Documentation
¶
Overview ¶
Package store owns PostgreSQL access: the pgx pool, goose migrations, and sqlc-generated typed queries. All SQL lives here; no other package builds SQL strings.
Index ¶
- func Migrate(ctx context.Context, databaseURL string) error
- func MigrateExtension(ctx context.Context, databaseURL, name string, fsys fs.FS) error
- func MigrationStatus(ctx context.Context, databaseURL string) (int64, error)
- type Store
- func (s *Store) Close()
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) Pool() *pgxpool.Pool
- func (s *Store) Queries() *storegen.Queries
- func (s *Store) WithPgxTx(ctx context.Context, fn func(tx pgx.Tx, q *storegen.Queries) error) error
- func (s *Store) WithTx(ctx context.Context, fn func(q *storegen.Queries) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
Migrate runs all pending goose migrations from the embedded FS. Safe to run concurrently within a process (migrateMu) and across processes/instances (a Postgres session advisory lock held for the whole run): waiters block until the leader finishes, then observe an up-to-date schema and no-op. This matters at first boot — api, git and worker replicas all start with migrateOnStart — and for test binaries sharing one database. Locking lives here, not in goose, because goose's own lock does not cover the version-table bootstrap: on a fresh database two concurrent migrators raced through it and collided inside the first migrations.
func MigrateExtension ¶
MigrateExtension runs an extension's goose migrations (pkg/extension) under the extension's own version table (ent_<name>_goose_version), so the core's numbering and an extension's never collide; the SQL owns its schema (CREATE SCHEMA IF NOT EXISTS ent_<name>). Same in-process mutex as Migrate and a per-extension advisory lock, for the same reasons.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps the connection pool. Domain packages depend on Store, never on pgx directly, so the tenancy helpers have one place to live.