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.
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb"
|
|
)
|
|
|
|
// Service owner names: every Archie process that serves this database holds
|
|
// one of these claims for its whole life, so an offline rewrite checks them
|
|
// all.
|
|
const (
|
|
OwnerStateStore = "state-store"
|
|
OwnerGateway = "gateway"
|
|
)
|
|
|
|
// 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
|
|
}
|