pgmigrate

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MPL-2.0-no-copyleft-exception Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pgmigrate implements sqlmigrate.Migrator for PostgreSQL via pgx/v5.

Multi-tenant schemas

Pass a Schema to target a specific PostgreSQL schema:

runner := pgmigrate.New(conn)
runner.Schema = "authz"

Each schema gets its own _migrations table, so tenants are migrated independently. The sql-migrate CLI supports this via TENANT_SCHEMA; see the CLI help for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Migrator

type Migrator struct {
	Conn   *pgx.Conn
	Schema string // optional; qualifies the _migrations table (e.g. "authz")
}

Migrator implements sqlmigrate.Migrator using a single pgx.Conn.

func New

func New(conn *pgx.Conn) *Migrator

New creates a Migrator from the given connection.

func (*Migrator) Applied

func (r *Migrator) Applied(ctx context.Context) ([]sqlmigrate.Migration, error)

Applied returns all applied migrations from the _migrations table. Returns an empty slice if the table does not exist (PG error 42P01).

Note: pgx.Conn.Query is lazy — when the table is missing, the 42P01 error may surface at rows.Err() rather than at Query(). Both sites must check for it.

func (*Migrator) ExecDown

func (r *Migrator) ExecDown(ctx context.Context, m sqlmigrate.Migration, sql string) error

ExecDown runs the down migration SQL inside a PostgreSQL transaction.

func (*Migrator) ExecUp

func (r *Migrator) ExecUp(ctx context.Context, m sqlmigrate.Migration, sql string) error

ExecUp runs the up migration SQL inside a PostgreSQL transaction.

Jump to

Keyboard shortcuts

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