From 4145b4d74ad681639c831b0c5c357ca6b03ac7d5 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Mon, 1 Jun 2026 22:45:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20sync=20=E2=80=94=20migration=20010=20fo?= =?UTF-8?q?r=20sync=5Fops=20and=20sync=5Fstate=20tables?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/core/storage/migrations_010.sql.go | 29 +++++++++++++++++++++ internal/core/storage/storage.go | 1 + 2 files changed, 30 insertions(+) create mode 100644 internal/core/storage/migrations_010.sql.go diff --git a/internal/core/storage/migrations_010.sql.go b/internal/core/storage/migrations_010.sql.go new file mode 100644 index 0000000..67a3232 --- /dev/null +++ b/internal/core/storage/migrations_010.sql.go @@ -0,0 +1,29 @@ +package storage + +// migration010 — sync_ops table for recording operations to push to sync server. +const migration010 = ` +CREATE TABLE IF NOT EXISTS sync_ops ( + id TEXT PRIMARY KEY, + op_id TEXT NOT NULL UNIQUE, + device_id TEXT NOT NULL, + entity_type TEXT NOT NULL, + entity_id TEXT NOT NULL, + op_type TEXT NOT NULL, + payload_json TEXT NOT NULL DEFAULT '{}', + created_at TEXT NOT NULL, + pushed_at TEXT, + applied_at TEXT +); + +CREATE INDEX IF NOT EXISTS idx_sync_ops_pushed ON sync_ops(pushed_at); +CREATE INDEX IF NOT EXISTS idx_sync_ops_entity ON sync_ops(entity_type, entity_id); + +CREATE TABLE IF NOT EXISTS sync_state ( + device_id TEXT PRIMARY KEY, + server_url TEXT NOT NULL DEFAULT '', + api_key TEXT NOT NULL DEFAULT '', + last_push_rev INTEGER NOT NULL DEFAULT 0, + last_pull_rev INTEGER NOT NULL DEFAULT 0, + last_sync_at TEXT +); +` diff --git a/internal/core/storage/storage.go b/internal/core/storage/storage.go index 78ad036..f817883 100644 --- a/internal/core/storage/storage.go +++ b/internal/core/storage/storage.go @@ -66,6 +66,7 @@ var migrationFiles = map[int]string{ // 7: migration007 (FTS5) — created lazily by search.Rebuild() 8: migration008, 9: migration009, + 10: migration010, } func (db *DB) runInitialSchema() error {