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

database

package
v0.0.0-...-b550a2e Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectDB

func ConnectDB(connString string) (*pgxpool.Pool, error)

func ConnectDBWithMaxConns

func ConnectDBWithMaxConns(connString string, maxConns int32) (*pgxpool.Pool, error)

ConnectDBWithMaxConns creates a pool with a custom maximum connection count. Use when the caller needs higher concurrency than the default (e.g. the seeder).

func DBVersion

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

DBVersion returns the current schema version recorded in goose_db_version, or 0 if that table doesn't exist yet (a database that has never been migrated).

func DownTo

func DownTo(ctx context.Context, connString string, version int64) error

DownTo migrates the database down to the given version, session-locked like RunMigrations. This is destructive (it runs migrations' Down scripts, which commonly drop data/columns/tables) - callers are expected to gate it behind an explicit operator opt-in (see cmd/admin-tools's `migrate down-to`), not call it unconditionally.

func ExpectedVersion

func ExpectedVersion() (int64, error)

ExpectedVersion returns the highest migration version embedded in this binary, derived from the numeric prefix of migrations/*.sql filenames (goose's own versioning scheme). This is what the binary expects the schema to be at once fully migrated.

func IsSchemaCurrent

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

IsSchemaCurrent reports whether the database schema is at least as new as what this binary expects. This intentionally checks >=, not ==: during a rolling upgrade the DB can be ahead of an older binary instance still finishing its rollout, and that instance must stay Ready rather than start failing readiness against a schema version it merely doesn't know about.

func MigrationStatus

func MigrationStatus(ctx context.Context, connString string) ([]*goose.MigrationStatus, error)

MigrationStatus returns the applied/pending state of every migration known to this binary.

func RegisterTypeLoader

func RegisterTypeLoader(loader func(context.Context, *pgx.Conn) error)

RegisterTypeLoader registers a function to load custom PostgreSQL types on each new connection. This function is safe to call from init() functions across different packages.

func RunMigrations

func RunMigrations(connString string) error

RunMigrations applies all pending migrations to the database at connString.

Types

This section is empty.

Directories

Path Synopsis
Package pgtime converts between time.Time and the pgtype timestamp types sqlc generates field types as.
Package pgtime converts between time.Time and the pgtype timestamp types sqlc generates field types as.

Jump to

Keyboard shortcuts

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