pgmigrate

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 9 Imported by: 5

Documentation

Overview

Package pgmigrate provides a PostgreSQL-specific migration executor for the Grove migration system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor implements migrate.Executor for PostgreSQL.

When the underlying driver supports driver.ConnAcquirer, the executor acquires a dedicated connection in [AcquireLock] and routes ALL subsequent operations through it until [ReleaseLock]. This guarantees that the session-level pg_try_advisory_lock is acquired and released on the same connection, preventing advisory-lock leaks in pooled environments.

func New

func New(drv driver.Driver) *Executor

New creates a new PostgreSQL migration executor.

func (*Executor) AcquireLock

func (e *Executor) AcquireLock(ctx context.Context, lockedBy string) error

AcquireLock attempts to acquire the distributed migration lock using PostgreSQL advisory locks for immediate feedback.

If the driver implements driver.ConnAcquirer, a dedicated connection is acquired first so that the advisory lock and all subsequent migration operations share the same session. This prevents lock leaks when using connection pools.

func (*Executor) EnsureLockTable

func (e *Executor) EnsureLockTable(ctx context.Context) error

EnsureLockTable creates the grove_migration_locks table if it doesn't exist.

func (*Executor) EnsureMigrationTable

func (e *Executor) EnsureMigrationTable(ctx context.Context) error

EnsureMigrationTable creates the grove_migrations table if it doesn't exist.

func (*Executor) Exec

func (e *Executor) Exec(ctx context.Context, query string, args ...any) (driver.Result, error)

Exec executes a SQL statement that does not return rows.

func (*Executor) ListApplied

func (e *Executor) ListApplied(ctx context.Context) ([]*migrate.AppliedMigration, error)

ListApplied returns all migrations that have been applied, ordered by migrated_at ascending.

func (*Executor) LockInfo

func (e *Executor) LockInfo(ctx context.Context) (*migrate.LockInfo, error)

LockInfo reports the current migration lock holder recorded in the lock table. It satisfies migrate.LockInspector, letting the orchestrator produce a diagnosable error when the lock-wait budget is exhausted.

func (*Executor) Query

func (e *Executor) Query(ctx context.Context, query string, args ...any) (driver.Rows, error)

Query executes a SQL statement that returns rows.

func (*Executor) RecordApplied

func (e *Executor) RecordApplied(ctx context.Context, m *migrate.Migration) error

RecordApplied records that a migration was successfully applied.

func (*Executor) ReleaseLock

func (e *Executor) ReleaseLock(ctx context.Context) error

ReleaseLock releases the distributed migration lock. If a dedicated connection was acquired in [AcquireLock], the advisory lock is released on that same connection before the connection is returned to the pool.

func (*Executor) RemoveApplied

func (e *Executor) RemoveApplied(ctx context.Context, m *migrate.Migration) error

RemoveApplied removes the record of an applied migration (for rollback).

Jump to

Keyboard shortcuts

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