postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package postgres provides a PostgreSQL driver for Queen migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	base.Driver
	// contains filtered or unexported fields
}

Driver implements the queen.Driver interface for PostgreSQL.

func New

func New(db *sql.DB) *Driver

New creates a new PostgreSQL driver.

func NewFromPool

func NewFromPool(pool *pgxpool.Pool) *Driver

NewFromPool creates a PostgreSQL driver from a native pgx pool.

The returned driver uses database/sql through pgx's stdlib adapter. Closing the driver closes only the adapter handle; it does not close the pgx pool.

func NewFromPoolWithTableName

func NewFromPoolWithTableName(pool *pgxpool.Pool, tableName string) *Driver

NewFromPoolWithTableName creates a PostgreSQL driver from a native pgx pool with a custom migration table name.

func NewWithTableName

func NewWithTableName(db *sql.DB, tableName string) *Driver

NewWithTableName creates a new PostgreSQL driver with a custom table name.

func (*Driver) Exec

func (d *Driver) Exec(ctx context.Context, isolationLevel sql.IsolationLevel, fn func(*sql.Tx) error) error

Exec runs migrations on the connection holding the advisory lock. If that session is lost, the migration transaction is lost with it.

func (*Driver) ExecMigration

func (d *Driver) ExecMigration(ctx context.Context, m *queen.Migration, isolation sql.IsolationLevel, fn func(*sql.Tx) error) error

ExecMigration sets PostgreSQL timeouts for the duration of one transaction.

func (*Driver) ExecNonTransactional

func (d *Driver) ExecNonTransactional(ctx context.Context, m *queen.Migration, direction string) (retErr error)

ExecNonTransactional runs one SQL command on the lock-holding connection.

func (*Driver) GetApplied

func (d *Driver) GetApplied(ctx context.Context) ([]queen.Applied, error)

GetApplied reads through the lock connection when a migration holds it.

func (*Driver) Init

func (d *Driver) Init(ctx context.Context) error

Init creates or upgrades the migrations tracking table under the migration lock.

func (*Driver) Lock

func (d *Driver) Lock(ctx context.Context, timeout time.Duration) error

Lock acquires an advisory lock to prevent concurrent migrations.

func (*Driver) LockBeforeInit

func (*Driver) LockBeforeInit()

LockBeforeInit tells Queen that PostgreSQL can lock before table setup.

func (*Driver) Record

func (d *Driver) Record(ctx context.Context, m *queen.Migration, meta *queen.MigrationMetadata) error

Record writes through the lock connection when the migration is non-transactional.

func (*Driver) RecordTx

func (d *Driver) RecordTx(ctx context.Context, tx *sql.Tx, m *queen.Migration, meta *queen.MigrationMetadata) error

RecordTx records an applied migration in the migration transaction.

func (*Driver) Remove

func (d *Driver) Remove(ctx context.Context, version string) error

Remove writes through the lock connection when the migration is non-transactional.

func (*Driver) RemoveTx

func (d *Driver) RemoveTx(ctx context.Context, tx *sql.Tx, version string) error

RemoveTx removes a migration record in the rollback transaction.

func (*Driver) SetMigrationStatus

func (d *Driver) SetMigrationStatus(ctx context.Context, version, status string, durationMS int64) error

SetMigrationStatus persists the recovery marker around a non-transactional command.

func (*Driver) Unlock

func (d *Driver) Unlock(ctx context.Context) error

Unlock releases the advisory lock.

Jump to

Keyboard shortcuts

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