roll

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PGVersion15              PGVersion     = 15
	DefaultBackfillBatchSize int           = 1000
	DefaultBackfillDelay     time.Duration = 0
)

Variables

View Source
var (
	ErrNoMigrationFiles   = fmt.Errorf("no migration files found")
	ErrNoMigrationApplied = fmt.Errorf("no migrations applied")
)
View Source
var ErrMismatchedMigration = fmt.Errorf("remote migration does not match local migration")

Functions

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 Option added in v0.5.0

type Option func(*options)

func WithBackfillBatchDelay added in v0.7.0

func WithBackfillBatchDelay(delay time.Duration) Option

WithBackfillBatchDelay sets the delay after each batch is run.

func WithBackfillBatchSize added in v0.7.0

func WithBackfillBatchSize(batchSize int) Option

WithBackfillBatchSize sets the number of rows backfilled in each batch.

func WithDisableViewsManagement added in v0.5.0

func WithDisableViewsManagement() Option

WithDisableViewsManagement disables pgroll version schemas management when passed, pgroll will not create or drop version schemas

func WithLockTimeoutMs added in v0.5.0

func WithLockTimeoutMs(lockTimeoutMs int) Option

WithLockTimeoutMs sets the lock timeout in milliseconds for pgroll DDL operations

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 WithNoVersionSchemaForRawSQL added in v0.7.0

func WithNoVersionSchemaForRawSQL() Option

WithNoVersionSchemaForRawSQL disables the creation of version schema for raw SQL migrations

func WithRole added in v0.5.0

func WithRole(role string) Option

WithRole sets the role to set before executing migrations

func WithSQLTransformer added in v0.6.0

func WithSQLTransformer(transformer migrations.SQLTransformer) Option

WithSQLTransformer sets the SQL transformer to apply to all user-defined SQL statements before they are executed. This is useful to sanitize or modify user defined SQL statements before they are executed.

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.

type PGVersion added in v0.4.0

type PGVersion int

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) Init

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

Init initializes the Roll instance

func (*Roll) LatestVersionLocal added in v0.8.0

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

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

func (*Roll) LatestVersionRemote added in v0.8.0

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

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

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, cbs ...migrations.CallbackFn) 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, cbs ...migrations.CallbackFn) ([]*schema.Table, 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) (*state.Status, error)

Status returns the current migration status

func (*Roll) UnappliedMigrations added in v0.8.0

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

UnappliedMigrations returns a slice of unapplied migrations from `dir`, lexicographically ordered by filename. 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.

Jump to

Keyboard shortcuts

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