archie-state-store import copies the State Store task database, the PocketBase event store and the Gateway conversation store, all named from db_path, into Postgres in one transaction. The bead asked for an archied command; offline maintenance of a store belongs to the binary that owns it, so it sits beside backup/restore/validate/rollback instead. It refuses rather than guesses: while the state-store or gateway ownership claim is held, when a domain it imports already holds rows (an allowlist of that domain's tables, checked after Migrate), on a completed prior import, on FK orphans, alias case collisions, duplicate bindings, events whose (at, id) order microsecond storage would change, schema gaps, and any value the target column cannot hold, naming table, row, value and rule. Historical ids are kept and every identity sequence is set from AUTOINCREMENT's high-water mark. After loading it compares key sets, event order, resource blobs and binding secrets byte for byte and the next id of every sequence, checks the source files were not written while read, and only then writes an import_completion row (migration 0005) in the same transaction. postgres.ImportComplete and legacyimport.HasLegacyData are the two halves of the boot gate: legacy data without a completed import must not serve.
20 lines
663 B
SQL
20 lines
663 B
SQL
-- import_completion records that the one-time import of an existing install's
|
|
-- SQLite stores committed and passed verification. It is written in the same
|
|
-- transaction as the imported rows, so a record exists exactly when the data
|
|
-- does. An empty database is not evidence that an import succeeded, only that
|
|
-- nothing has written to it yet, so serving over non-empty legacy files
|
|
-- requires this row.
|
|
|
|
-- +goose Up
|
|
|
|
CREATE TABLE import_completion (
|
|
id bigint PRIMARY KEY CHECK (id = 1),
|
|
completed_at timestamptz NOT NULL DEFAULT now(),
|
|
sources text NOT NULL,
|
|
report text NOT NULL
|
|
);
|
|
|
|
-- +goose Down
|
|
|
|
DROP TABLE import_completion;
|