Wave 1 of the Postgres migration (archie-core-7r0x.9). This is the shared shape every port lane builds on; nothing here switches a live path to Postgres yet. - config: add `database_url` beside `db_path` (config.go), mark it bootstrap-only in denied_keys, expose it in the webui StorageView/config schema, and add it to config.example.toml plus all deployments/*.toml. - docker-compose: add a postgres:18 service; `task dev` (dev:postgres) brings it up and waits for it before the State Store boots. - archied: `openStateStore` now opens and migrates the process-scoped Postgres pool via `openStateStorePool`. The State Store fails closed (D1.2) when database_url is absent or invalid rather than fall back to SQLite; serving against Postgres later requires an import-completion record (D1.3), which is a later lane's gate, not this one. - composition seam: task-store construction (state_store_task.go) and EDA-store construction (state_store_eda.go) are extracted from openStateStore, with the pool open in state_store_pool.go. This is a behaviour-preserving refactor only — no store, interface, error, ordering or logging change — so L1 and L2 build against separate files instead of sharing state_store.go. Tests: fail-closed pool behaviour is pinned (absent/invalid URL); the State Store boot/restart tests now run against a throwaway Postgres 18 container (pgtest TestMain). Scoped test command and module-wide build pass; see lane report.
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/samcharles93/archie-core/internal/store"
|
|
)
|
|
|
|
// openTaskStore claims ownership of the task database and opens the production
|
|
// task store. The ownership claim is what makes "the State Store is stopped" a
|
|
// fact an offline recovery command can check, and a second State Store on the
|
|
// same database fails here. It is a separate composition file from openEDAStore
|
|
// so L1 can replace openProductionTaskStore (and the ownership claim, per the
|
|
// serve-ownership decision) here without colliding with L2's edastore port.
|
|
func (b *boot) openTaskStore(ctx context.Context, path string) error {
|
|
ownership, err := store.AcquireOwnership(path)
|
|
if err != nil {
|
|
b.log.Error("claim state store ownership", "err", err)
|
|
return err
|
|
}
|
|
b.addCleanup(func() {
|
|
if err := ownership.Release(); err != nil {
|
|
b.log.Error("release state store ownership", "err", err)
|
|
}
|
|
})
|
|
|
|
st, err := openProductionTaskStore(ctx, path)
|
|
if err != nil {
|
|
b.log.Error("open state store", "err", err)
|
|
return err
|
|
}
|
|
b.st = st
|
|
b.addCleanup(func() {
|
|
if err := st.Close(); err != nil {
|
|
b.log.Error("close state store", "err", err)
|
|
}
|
|
})
|
|
return nil
|
|
}
|