Documentation
¶
Index ¶
- Variables
- func Migrate(ctx context.Context, sqlDB *sql.DB) error
- func MigrateAll(ctx context.Context, sqlDB *sql.DB) error
- func MigrateAllPool(ctx context.Context, pool *pgxpool.Pool) error
- func MigrateDown(ctx context.Context, db *sql.DB) error
- func MigrateReset(ctx context.Context, db *sql.DB) error
- func MigrateStatus(ctx context.Context, db *sql.DB) error
Constants ¶
This section is empty.
Variables ¶
var Migrations embed.FS
Functions ¶
func Migrate ¶
Migrate applies all pending migrations UP through goose, serialized across concurrent callers by the session advisory lock. MigrateAll/MigrateAllPool are the callable entrypoints; this is the shared implementation.
func MigrateAll ¶
MigrateAll runs the app migrations UP, safe for CONCURRENT callers.
Every DB-touching pod (control AND broker) runs this on startup before it reads any schema-dependent table, so no pod races ahead of the migration on a fresh database (there is no boot ordering between the control and broker Deployments). Concurrency is made safe by a Postgres SESSION advisory lock (goose WithSessionLocker): of N pods starting at once, exactly ONE acquires the lock and applies the pending migrations; the rest BLOCK on the lock and, when it releases, observe the schema already current and return nil — no "relation already exists" error, no boot crashloop. Idempotent: a no-op (returns nil) when the schema is already up to date.
func MigrateAllPool ¶
MigrateAllPool is the pgxpool-shaped entrypoint the pod boot uses: it opens a throwaway database/sql handle over the SAME DSN as the running pgxpool (goose needs a *sql.DB; the rest of the app uses pgx), runs MigrateAll under the advisory lock, and closes the handle. cmd/converge calls this ONCE as the first DB operation in run() — before any schema-reading step (the config-plane cache, the spec-validator rebuild, the sweepers) — so on a fresh DB every such read sees a migrated schema.
Types ¶
This section is empty.