Files
archie/internal/infrastructure/postgres/pgstore/pgstore.go
T
sam ae552db7e0 refactor(store)!: remove the SQLite task store, the PocketBase event store and the SQLite session store
The State Store, event capture and Gateway conversations already serve from
PostgreSQL. This deletes internal/store and internal/infrastructure/edastore,
the SQLite gateway session store and openProductionTaskStore, and the -db
recovery path on a legacy task file; backup, restore, validate and rollback
work on the database database_url names.

- The binding-secret cipher moves to internal/infrastructure/bindingcipher and
  ToolCall to internal/infrastructure/postgres.
- NewSessionStoreMemory is now a pure in-memory store that passes the shared
  SessionStore conformance suite.
- Tests run against PostgreSQL through internal/infrastructure/postgres/pgstore;
  legacyimport/legacyfixture writes the legacy files the import and the boot
  gate read.
- The cron dialect is owned in internal/domain/scheduling, so
  github.com/pocketbase/pocketbase and pocketbase/dbx leave go.mod.
  modernc.org/sqlite stays for the one-time import (legacyread).
- The UI and Messaging architecture gates ban the Postgres and legacy readers
  in place of internal/store.
2026-09-24 14:43:50 +10:00

62 lines
1.9 KiB
Go

// Package pgstore opens migrated PostgreSQL stores on a throwaway pgtest
// database, for tests outside internal/infrastructure/postgres. A package
// using it calls pgtest.Main from TestMain.
package pgstore
import (
"testing"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/samcharles93/archie-core/internal/infrastructure/bindingcipher"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest"
)
// TaskDB is the State Store's task database: the task, event, status and
// identity surface plus the control-plane resources, over one pool.
type TaskDB struct {
*postgres.Store
*postgres.Resources
Pool *pgxpool.Pool
}
// Pool opens a pool on a fresh migrated database, closed when t ends.
func Pool(t testing.TB) *pgxpool.Pool {
t.Helper()
return PoolAt(t, pgtest.URL(t))
}
// PoolAt opens a pool on url and migrates it, closed when t ends. Opening a
// second pool on the same url is how a test models a restart.
func PoolAt(t testing.TB, url string) *pgxpool.Pool {
t.Helper()
pool, err := postgres.Open(t.Context(), url)
if err != nil {
t.Fatalf("pgstore: open: %v", err)
}
t.Cleanup(pool.Close)
if err := postgres.Migrate(t.Context(), pool, postgres.Migrations()); err != nil {
t.Fatalf("pgstore: migrate: %v", err)
}
return pool
}
// On returns the task database over pool.
func On(pool *pgxpool.Pool) *TaskDB {
return &TaskDB{Store: postgres.New(pool), Resources: postgres.NewResources(pool), Pool: pool}
}
// Open returns the task database on a fresh migrated database.
func Open(t testing.TB) *TaskDB {
t.Helper()
return On(Pool(t))
}
// EDA returns the event-capture store on a fresh migrated database. A nil
// cipher keeps binding secrets in plaintext.
func EDA(t testing.TB, cipher bindingcipher.BindingCipher) *postgres.EDA {
t.Helper()
return postgres.NewEDA(Pool(t), cipher)
}