小结
-
以 json 格式存储
-
强制要求表只有单一主键, 不允许有复合主键
设计
以 数据库设计 - 数据删除 为蓝本
采用 一张表存储删除的记录 的方案, 以 json 的格式存储到关系型数据库中
表结构
属性 | 说明 |
---|---|
表名 | |
主键 | |
数据 | json 格式 |
drop table if exists deleted_record;
create table if not exists deleted_record
(
id varchar(19) not null comment '主键id',
table_name varchar(100) not null comment '表名',
pk varchar(19) not null comment '记录主键',
record varchar(16240) not null comment '删除的记录; json 格式',
create_time datetime(3) not null comment '',
update_time datetime(3) not null comment '',
constraint pk_id primary key (id)
)comment='已删除的记录表' engine=InnoDB;
注意: 这里的主键属性, 只能有一个值, 故要求数据库设计中, 强制要求不允许有复合主键
使用
删除的时候, 将删除的数据先存储到该表中, 再进行物理删除原数据, 操作涉及到数据库的具体操作, 不宜在 domainServie 层使用, 应该在 dao 层使用
包结构
-domainService
–internal
—deleteRecord
----IDeleteRecordHelper
----impl
-----deleteRecordPO
-----deleteRecordDao
-----deleteRecordHelper