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.
38 lines
891 B
Go
38 lines
891 B
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: import.sql
|
|
|
|
package postgresdb
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const importCompleted = `-- name: ImportCompleted :one
|
|
SELECT EXISTS (SELECT 1 FROM import_completion)
|
|
`
|
|
|
|
func (q *Queries) ImportCompleted(ctx context.Context) (bool, error) {
|
|
row := q.db.QueryRow(ctx, importCompleted)
|
|
var exists bool
|
|
err := row.Scan(&exists)
|
|
return exists, err
|
|
}
|
|
|
|
const insertImportCompletion = `-- name: InsertImportCompletion :exec
|
|
|
|
INSERT INTO import_completion (id, sources, report) VALUES (1, $1, $2)
|
|
`
|
|
|
|
type InsertImportCompletionParams struct {
|
|
Sources string
|
|
Report string
|
|
}
|
|
|
|
// The one-time legacy import's completion record.
|
|
func (q *Queries) InsertImportCompletion(ctx context.Context, arg InsertImportCompletionParams) error {
|
|
_, err := q.db.Exec(ctx, insertImportCompletion, arg.Sources, arg.Report)
|
|
return err
|
|
}
|