feat(archied): serve the State Store, event store and Gateway conversations from Postgres

The State Store's task and event-capture stores and the conversation store
read by archied and served by archie-gateway now open on database_url.
Every serving process refuses to start when legacy SQLite data exists and no
import completion is recorded, naming archie-state-store import; a fresh
install records completion itself. The Gateway holds its Postgres serve
claim for its lifetime and releases it before the pool closes.
This commit is contained in:
sam committed 2026-09-24 10:01:54 +10:00
1 parent 9298c8f2c3
commit cea88060b1
18 files changed
+381 -177

No files matched your search

@@ -27,3 +27,13 @@ func ImportComplete(ctx context.Context, pool *pgxpool.Pool) (bool, error) {
}
return done, nil
}
// RecordFreshInstall writes the completion record for a database that starts
// with no legacy data to import, so a legacy file that appears later cannot
// block it from serving. It leaves an existing record untouched.
func RecordFreshInstall(ctx context.Context, pool *pgxpool.Pool) error {
if err := postgresdb.New(pool).InsertFreshInstallCompletion(ctx); err != nil {
return fmt.Errorf("postgres: fresh install completion: %w", err)
}
return nil
}
@@ -20,6 +20,16 @@ func (q *Queries) ImportCompleted(ctx context.Context) (bool, error) {
return exists, err
}
const insertFreshInstallCompletion = `-- name: InsertFreshInstallCompletion :exec
INSERT INTO import_completion (id, sources, report) VALUES (1, '', 'fresh install: no legacy data')
ON CONFLICT (id) DO NOTHING
`
func (q *Queries) InsertFreshInstallCompletion(ctx context.Context) error {
_, err := q.db.Exec(ctx, insertFreshInstallCompletion)
return err
}
const insertImportCompletion = `-- name: InsertImportCompletion :exec
INSERT INTO import_completion (id, sources, report) VALUES (1, $1, $2)
@@ -5,3 +5,7 @@ INSERT INTO import_completion (id, sources, report) VALUES (1, $1, $2);
-- name: ImportCompleted :one
SELECT EXISTS (SELECT 1 FROM import_completion);
-- name: InsertFreshInstallCompletion :exec
INSERT INTO import_completion (id, sources, report) VALUES (1, '', 'fresh install: no legacy data')
ON CONFLICT (id) DO NOTHING;