feat: 实现小程序离线巡检与可靠同步

This commit is contained in:
weijuesen
2026-08-14 09:03:48 +08:00
parent 6b222abb7b
commit 69ef5a0704
19 changed files with 543 additions and 19 deletions
@@ -0,0 +1,16 @@
DROP INDEX IF EXISTS idx_inspection_records_user_idempotency;
-- 恢复全局唯一索引前,先处理跨用户重复,保留所有记录。
UPDATE inspection_records AS r
SET idempotency_key = r.idempotency_key || '#' || r.id
WHERE r.idempotency_key IS NOT NULL
AND EXISTS (
SELECT 1
FROM inspection_records AS x
WHERE x.idempotency_key = r.idempotency_key
AND x.id <> r.id
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_inspection_records_idempotency_key
ON inspection_records (idempotency_key)
WHERE idempotency_key IS NOT NULL;
@@ -0,0 +1,17 @@
-- 保留全部历史记录,只对同用户重复键追加记录 ID,避免迁移删除或丢失数据。
UPDATE inspection_records AS r
SET idempotency_key = r.idempotency_key || '#' || r.id
WHERE r.idempotency_key IS NOT NULL
AND EXISTS (
SELECT 1
FROM inspection_records AS x
WHERE x.user_id IS NOT DISTINCT FROM r.user_id
AND x.idempotency_key = r.idempotency_key
AND x.id <> r.id
);
DROP INDEX IF EXISTS idx_inspection_records_idempotency_key;
CREATE UNIQUE INDEX IF NOT EXISTS idx_inspection_records_user_idempotency
ON inspection_records (user_id, idempotency_key)
WHERE idempotency_key IS NOT NULL;