-- 任务操作记录表(协议 v2:先持久化意图,再产生外部副作用) -- -- 这是显式迁移脚本,不会被应用自动执行,也不对生产库运行。 -- 执行前请备份:sqlite3 LionWebsite.db ".backup LionWebsite.db.before-task-operation" -- -- 幂等:可重复执行。 create table if not exists task_operation ( gid integer not null constraint task_operation_pk primary key, operationId varchar(64), deleteOperationId varchar(64), state varchar(20) not null, lastRevision integer not null default 0, lastReportId varchar(64), updateTime long not null default 0 ); -- 节点上报消费只按 gid 命中主键,这里额外为「按状态找待处理意图」提供查询入口。 create index if not exists idx_task_operation_state on task_operation (state); -- gallery.gid 目前只有 table 级主键约束(部分历史库甚至是自增主键的衍生约束), -- 这里显式建立唯一索引,保证同一 gid 不会出现两条任务行: -- 「同一 gid 只有一个有效意图」是 v2 生命周期成立的前提。 -- 若该语句因历史重复数据失败,请先人工确认重复行来源再处理,不要直接删除。 create unique index if not exists idx_gallery_gid_unique on gallery (gid); -- 旧任务行没有操作记录:启动/查询时按 gid 惰性补建为 SUBMITTED(已在上游提交过), -- 不需要在迁移里批量写入,避免把正在进行的任务判成 UNKNOWN。