feat(sync): implement lww conflict and tombstone handling

This commit is contained in:
2026-04-06 01:33:57 +08:00
parent c48e16a977
commit c98adb3051
9 changed files with 530 additions and 19 deletions
+20
View File
@@ -17,6 +17,7 @@ export type LocalTaskRecord = {
priority: LocalTaskPriority;
status: LocalTaskStatus;
ddlAt: number | null;
version: number;
createdAt: number;
updatedAt: number;
deletedAt: number | null;
@@ -97,6 +98,25 @@ class TodoLocalDb extends Dexie {
sync_inbox: "&opId,userId,entityId,serverTs,appliedAt"
});
this.version(4)
.stores({
tasks: "&id,userId,status,priority,ddlAt,updatedAt,deletedAt",
op_logs: "&opId,entityId,entityType,action,clientTs,syncedAt",
task_drafts: "&taskId,userId,updatedAt",
sync_states: "&userId,updatedAt,lastSyncedAt",
sync_inbox: "&opId,userId,entityId,serverTs,appliedAt"
})
.upgrade(async (tx) => {
await tx
.table("tasks")
.toCollection()
.modify((task: Partial<LocalTaskRecord>) => {
if (typeof task.version !== "number") {
task.version = 1;
}
});
});
this.tasks = this.table("tasks");
this.opLogs = this.table("op_logs");
this.taskDrafts = this.table("task_drafts");