Documentation
¶
Overview ¶
Package pgmigrate provides a PostgreSQL-specific migration executor for the Grove migration system.
Index ¶
- type Executor
- func (e *Executor) AcquireLock(ctx context.Context, lockedBy string) error
- func (e *Executor) EnsureLockTable(ctx context.Context) error
- func (e *Executor) EnsureMigrationTable(ctx context.Context) error
- func (e *Executor) Exec(ctx context.Context, query string, args ...any) (driver.Result, error)
- func (e *Executor) ListApplied(ctx context.Context) ([]*migrate.AppliedMigration, error)
- func (e *Executor) LockInfo(ctx context.Context) (*migrate.LockInfo, error)
- func (e *Executor) Query(ctx context.Context, query string, args ...any) (driver.Rows, error)
- func (e *Executor) RecordApplied(ctx context.Context, m *migrate.Migration) error
- func (e *Executor) ReleaseLock(ctx context.Context) error
- func (e *Executor) RemoveApplied(ctx context.Context, m *migrate.Migration) error
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 (*Executor) AcquireLock ¶
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 ¶
EnsureLockTable creates the grove_migration_locks table if it doesn't exist.
func (*Executor) EnsureMigrationTable ¶
EnsureMigrationTable creates the grove_migrations table if it doesn't exist.
func (*Executor) ListApplied ¶
ListApplied returns all migrations that have been applied, ordered by migrated_at ascending.
func (*Executor) LockInfo ¶
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) RecordApplied ¶
RecordApplied records that a migration was successfully applied.
func (*Executor) ReleaseLock ¶
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.