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 {