state

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireLock

func AcquireLock(ctx context.Context, conn *pgx.Conn) error

AcquireLock attempts to acquire a PostgreSQL advisory lock. This prevents concurrent migrations on the same database. Returns an error if the lock is already held.

func AppliedSteps

func AppliedSteps(ctx context.Context, conn *pgx.Conn, planName string) (map[int]bool, error)

AppliedSteps returns all applied step indexes for a given plan name.

func EnsureTable

func EnsureTable(ctx context.Context, conn *pgx.Conn) error

EnsureTable creates the _scheme_state table if it doesn't exist.

func InsertRecord

func InsertRecord(ctx context.Context, conn *pgx.Conn, rec *Record) error

InsertRecord inserts a migration step record into the state table.

func LatestHash

func LatestHash(ctx context.Context, conn *pgx.Conn) (string, error)

LatestHash returns the schema hash from the most recent successful migration. Returns empty string if no migrations have been applied.

func ReleaseLock

func ReleaseLock(ctx context.Context, conn *pgx.Conn) error

ReleaseLock releases the advisory lock.

Types

type Record

type Record struct {
	ID              int
	SchemaHash      string
	AppliedAt       time.Time
	PlanName        string
	StepIndex       int
	SQLStatement    string
	ExecutionTimeMs int
	Success         bool
}

Record represents a single applied migration step record.

Jump to

Keyboard shortcuts

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