chore(state-store): remove the one-time SQLite import and db_path

Every install serves from Postgres, so the legacyread/legacyimport packages,
the archie-state-store import command, the boot gate that refused to serve
over unimported SQLite files, and db_path (which only located those files)
go. Migration 0010 drops the import_completion table.
This commit is contained in:
sam committed 2026-09-25 00:40:48 +10:00
1 parent d61e49b2c9
commit 8c55b5d4e4
65 files changed
+138 -3350

No files matched your search

@@ -1,31 +0,0 @@
package postgres
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb"
)
// ImportComplete reports whether the one-time legacy import committed and
// verified against this migrated database. Serving over non-empty legacy
// files is refused without it.
func ImportComplete(ctx context.Context, pool *pgxpool.Pool) (bool, error) {
done, err := postgresdb.New(pool).ImportCompleted(ctx)
if err != nil {
return false, fmt.Errorf("postgres: import completion: %w", err)
}
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
}
@@ -1,39 +0,0 @@
package postgres
import (
"testing"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest"
)
func TestImportComplete(t *testing.T) {
tests := []struct {
name string
record bool
want bool
}{
{name: "migrated database without a record", want: false},
{name: "committed record", record: true, want: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pool := openPool(t, pgtest.URL(t))
if err := Migrate(t.Context(), pool, Migrations()); err != nil {
t.Fatalf("Migrate: %v", err)
}
if tt.record {
if _, err := pool.Exec(t.Context(),
"INSERT INTO import_completion (id, sources, report) VALUES (1, 's', 'r')"); err != nil {
t.Fatalf("seed record: %v", err)
}
}
got, err := ImportComplete(t.Context(), pool)
if err != nil {
t.Fatalf("ImportComplete: %v", err)
}
if got != tt.want {
t.Fatalf("ImportComplete = %v, want %v", got, tt.want)
}
})
}
}
@@ -0,0 +1,15 @@
-- The one-time SQLite import is removed, and with it the completion record
-- that gated serving over unimported legacy files.
-- +goose Up
DROP TABLE import_completion;
-- +goose Down
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
);
@@ -1,47 +0,0 @@
// 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 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)
`
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
}
@@ -134,13 +134,6 @@ type IdentitySubject struct {
BoundAt time.Time
}
type ImportCompletion struct {
ID int64
CompletedAt time.Time
Sources string
Report string
}
type Mapping struct {
ID string
Name string
@@ -1,11 +0,0 @@
-- The one-time legacy import's completion record.
-- name: InsertImportCompletion :exec
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;