Documentation
¶
Overview ¶
Package pgdb gives an application its own schema in a PostgreSQL database: a pool whose connections use it, hopper's job tables in it, and goose migrations applied to it, so several applications can share one database without their tables meeting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HopperDriver ¶
HopperDriver returns hopper's driver for a pool from Open, with hopper's tables in the pool's schema. hopper's own default is a schema named hopper.
func Migrate ¶
Migrate creates the pool's schema, installs or upgrades hopper's tables in it and applies the application's migrations. It is safe to call from several replicas at once.
The lock is held on a dedicated connection outside the pool, so replicas waiting on it never starve the migration itself of pool connections.
func Open ¶
Open creates a connection pool whose connections use schema as their search_path, and verifies connectivity. TLS to the database is negotiated by crypto/tls, which uses the FIPS 140-3 module.
func ValidSchema ¶
ValidSchema reports whether name is usable as a schema: lowercase letters, digits and underscores, not starting with a digit, at most 63 bytes.
Types ¶
type Migrations ¶
type Migrations struct {
// FS holds the migration files at its root.
FS fs.FS
// LockKey is the pg_advisory_lock key held while migrating, so that one
// replica migrates at a time. Zero derives one from the schema.
LockKey int64
// Logger defaults to slog.Default().
Logger *slog.Logger
}
Migrations are an application's goose migrations.