Help us shape the future of Go! Take the 2026 Go Developer Survey

db

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Migrations embed.FS

Functions

func Migrate

func Migrate(ctx context.Context, sqlDB *sql.DB) error

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

func MigrateAll(ctx context.Context, sqlDB *sql.DB) error

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

func MigrateAllPool(ctx context.Context, pool *pgxpool.Pool) error

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.

func MigrateDown

func MigrateDown(ctx context.Context, db *sql.DB) error

func MigrateReset

func MigrateReset(ctx context.Context, db *sql.DB) error

func MigrateStatus

func MigrateStatus(ctx context.Context, db *sql.DB) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL