Documentation
¶
Overview ¶
Package postgres opens the PostgreSQL pool of a site, runs its migrations and hands its database to a plain role.
Index ¶
- Variables
- func CheckAddress(address string) error
- func Classify(err error) error
- func HandOver(ctx context.Context, db *sql.DB, owner Owner) ([]string, error)
- func Migrate(ctx context.Context, db *sql.DB, m Migrations) error
- func OwnerSteps(ctx context.Context, db *sql.DB, role string) ([]string, error)
- func ReachesServer(ctx context.Context, db *sql.DB) (bool, error)
- type Handle
- type Migrations
- type Options
- type Owner
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotSuperuser refuses a hand-over on a connection that is no superuser. ErrNotSuperuser = errors.New("dbkit: handing over a database takes a superuser connection") // ErrNotPlainRole refuses a hand-over to a role that is a superuser or can reach the database server. ErrNotPlainRole = errors.New("dbkit: a database goes to a plain role, and this role can reach the database server") // ErrRoleName refuses a role name that is empty or longer than the server keeps. ErrRoleName = errors.New("dbkit: the role name is empty or longer than the server keeps") )
Functions ¶
func CheckAddress ¶
CheckAddress returns the error for an empty PostgreSQL address or one pgx 5.10 and 5.11 read apart with no PG* set.
func Classify ¶
Classify returns err wrapped in its dbkit error class, or err unchanged when it has none or already carries it.
func HandOver ¶ added in v0.4.0
HandOver gives owner the database of db and what it holds, in one transaction, and returns the steps it ran.
func Migrate ¶
Migrate applies every pending migration of m to db under goose's advisory lock, creating an absent schema of Table.
func OwnerSteps ¶ added in v0.4.0
OwnerSteps returns the statements HandOver would run for role on the database of db, and changes nothing.
Types ¶
type Handle ¶
type Handle struct {
// Pool owns every connection of the handle.
Pool *pgxpool.Pool
// DB is the database/sql view of Pool, with no idle connection of its own.
DB *sql.DB
}
Handle is the one PostgreSQL pool of a site and a database/sql view that draws from it.
type Migrations ¶
type Migrations struct {
// Table is the version table, table or schema.table, lowercase parts of up to 63 bytes, none reserved, no pg_ schema.
Table string
// FS holds the owner's SQL migration files at its root, and nil means none.
FS fs.FS
// Go are the owner's Go migrations, each built with goose.NewGoMigration.
Go []*goose.Migration
}
Migrations are the migrations of one owner.