feat: sync — migration 010 for sync_ops and sync_state tables

This commit is contained in:
mirivlad 2026-06-01 22:45:12 +08:00
parent edc708a106
commit 4145b4d74a
2 changed files with 30 additions and 0 deletions

View File

@ -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
);
`

View File

@ -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 {