roll

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMigrationFiles   = fmt.Errorf("no migration files found")
	ErrNoMigrationApplied = fmt.Errorf("no migrations applied")
	ErrNoVersionSchema    = fmt.Errorf("no version schemas found")
)
View Source
var (
	ErrMismatchedMigration          = fmt.Errorf("remote migration does not match local migration")
	ErrExistingSchemaWithoutHistory = fmt.Errorf("schema has existing tables but no migration history - baseline required")
)

Functions

func LatestMigrationNameLocal added in v0.14.0

func LatestMigrationNameLocal(ctx context.Context, dir fs.FS) (string, error)

LatestMigrationNameLocal returns the name of the last migration in `dir`, where the migration files are lexicographically ordered by filename.

func LatestVersionLocal added in v0.11.0

func LatestVersionLocal(ctx context.Context, dir fs.FS) (string, error)

LatestVersionLocal returns the version schema name of the last migration in `dir`, where the migration files are lexicographically ordered by filename.

func VersionedSchemaName

func VersionedSchemaName(schema string, version string) string

Types

type MigrationHooks added in v0.6.0

type MigrationHooks struct {
	// BeforeStartDDL is called before the DDL phase of migration start
	BeforeStartDDL func(*Roll) error
	// AfterStartDDL is called after the DDL phase of migration start is complete
	AfterStartDDL func(*Roll) error
	// BeforeCompleteDDL is called before the DDL phase of migration complete
	BeforeCompleteDDL func(*Roll) error
	// AfterCompleteDDL is called after the DDL phase of migration complete is complete
	AfterCompleteDDL func(*Roll) error
}

MigrationHooks defines hooks that can be set to be called at various points during the migration process

type MigrationStatus added in v0.14.0

type MigrationStatus string
const (
	NoneMigrationStatus       MigrationStatus = "No migrations"
	InProgressMigrationStatus MigrationStatus = "In progress"
	CompleteMigrationStatus   MigrationStatus = "Complete"
)

type Option added in v0.5.0

type Option func(*options)

func WithLockTimeoutMs added in v0.5.0

func WithLockTimeoutMs(lockTimeoutMs int) Option

WithLockTimeoutMs sets the lock timeout in milliseconds for pgroll DDL operations

func WithLogging added in v0.12.0

func WithLogging(enabled bool) Option

WithLogging enables verbose logging for the Roll instance

func WithMigrationHooks added in v0.6.0

func WithMigrationHooks(hooks MigrationHooks) Option

WithMigrationHooks sets the migration hooks for the Roll instance Migration hooks are called at various points during the migration process to allow for custom behavior to be injected

func WithRole added in v0.5.0

func WithRole(role string) Option

WithRole sets the role to set before executing migrations

func WithSearchPath added in v0.7.0

func WithSearchPath(schemas ...string) Option

WithSearchPath sets the search_path to use during migration execution. The schema in which the migration is run is always included in the search path, regardless of this setting.

func WithSkipValidation added in v0.8.0

func WithSkipValidation(skip bool) Option

WithSkipValidation controls whether or not to perform validation on migrations. If set to true, validation will be skipped.

func WithVersionSchema added in v0.14.0

func WithVersionSchema(enabled bool) Option

WithVersionSchema enables or disables the creation of version schema for migrations.

type PGVersion added in v0.4.0

type PGVersion int
const (
	PGVersion15 PGVersion = 15
)

type Roll

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

func New

func New(ctx context.Context, pgURL, schema string, state *state.State, opts ...Option) (*Roll, error)

New creates a new Roll instance

func (*Roll) Close

func (m *Roll) Close() error

func (*Roll) Complete

func (m *Roll) Complete(ctx context.Context) error

Complete will update the database schema to match the current version

func (*Roll) CreateBaseline added in v0.13.0

func (m *Roll) CreateBaseline(ctx context.Context, baselineVersion string) error

CreateBaseline creates a baseline migration for an existing database schema. This is used when starting pgroll with an existing database - it captures the current schema state as a baseline version without applying any changes. Future migrations will build upon this baseline version.

func (*Roll) Init

func (m *Roll) Init(ctx context.Context) error

Init initializes the Roll instance

func (*Roll) LatestMigrationNameRemote added in v0.14.0

func (m *Roll) LatestMigrationNameRemote(ctx context.Context) (string, error)

LatestMigrationNameRemote returns the name of the last migration to have been applied to the target schema.

func (*Roll) LatestVersionRemote added in v0.8.0

func (m *Roll) LatestVersionRemote(ctx context.Context) (string, error)

LatestVersionRemote returns the version schema name of the last migration to have been applied to the target schema.

func (*Roll) MissingMigrations added in v0.12.0

func (m *Roll) MissingMigrations(ctx context.Context, dir fs.FS) ([]*migrations.RawMigration, error)

MissingMigrations returns the slice of migrations that have been applied to the target database but are missing from the local migrations directory `dir`.

func (*Roll) PGVersion added in v0.4.0

func (m *Roll) PGVersion() PGVersion

PGVersion returns the postgres version

func (*Roll) PgConn added in v0.6.0

func (m *Roll) PgConn() db.DB

PgConn returns the underlying database connection

func (*Roll) Rollback

func (m *Roll) Rollback(ctx context.Context) error

Rollback will revert the changes made by the migration

func (*Roll) Schema added in v0.6.0

func (m *Roll) Schema() string

Schema returns the schema the Roll instance is acting on

func (*Roll) Start

func (m *Roll) Start(ctx context.Context, migration *migrations.Migration, cfg *backfill.Config) error

Start will apply the required changes to enable supporting the new schema version

func (*Roll) StartDDLOperations added in v0.6.0

func (m *Roll) StartDDLOperations(ctx context.Context, migration *migrations.Migration) (*backfill.Job, error)

StartDDLOperations performs the DDL operations for the migration. This does not include running backfills for any modified tables.

func (*Roll) State added in v0.8.0

func (m *Roll) State() *state.State

State returns the state instance the Roll instance is acting on

func (*Roll) Status added in v0.4.1

func (m *Roll) Status(ctx context.Context, schema string) (*Status, error)

Status returns the current migration status of the specified schema

func (*Roll) UnappliedMigrations added in v0.8.0

func (m *Roll) UnappliedMigrations(ctx context.Context, dir fs.FS) ([]*migrations.RawMigration, error)

UnappliedMigrations returns the slice of unapplied migrations from `dir` that have not yet been applied to the database. Applying each of the returned migrations in order will bring the database up to date with `dir`.

If the local order of migrations does not match the order of migrations in the schema history, an `ErrMismatchedMigration` error is returned.

func (*Roll) UseVersionSchema added in v0.14.0

func (m *Roll) UseVersionSchema() bool

func (*Roll) Validate added in v0.14.0

func (m *Roll) Validate(ctx context.Context, migration *migrations.Migration) error

type Status added in v0.14.0

type Status struct {
	// The schema name.
	Schema string `json:"schema"`

	// The name of the latest version schema.
	Version string `json:"version"`

	// The status of the most recent migration.
	Status MigrationStatus `json:"status"`
}

Status describes the current migration status of a database schema.

Jump to

Keyboard shortcuts

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