Documentation
¶
Index ¶
- Variables
- func LatestVersionLocal(ctx context.Context, dir fs.FS) (string, error)
- func VersionedSchemaName(schema string, version string) string
- type MigrationHooks
- type Option
- func WithDisableViewsManagement() Option
- func WithLockTimeoutMs(lockTimeoutMs int) Option
- func WithMigrationHooks(hooks MigrationHooks) Option
- func WithNoVersionSchemaForRawSQL() Option
- func WithRole(role string) Option
- func WithSearchPath(schemas ...string) Option
- func WithSkipValidation(skip bool) Option
- type PGVersion
- type Roll
- func (m *Roll) Close() error
- func (m *Roll) Complete(ctx context.Context) error
- func (m *Roll) Init(ctx context.Context) error
- func (m *Roll) LatestVersionRemote(ctx context.Context) (string, error)
- func (m *Roll) PGVersion() PGVersion
- func (m *Roll) PgConn() db.DB
- func (m *Roll) Rollback(ctx context.Context) error
- func (m *Roll) Schema() string
- func (m *Roll) Start(ctx context.Context, migration *migrations.Migration, cfg *backfill.Config) error
- func (m *Roll) StartDDLOperations(ctx context.Context, migration *migrations.Migration) ([]*schema.Table, error)
- func (m *Roll) State() *state.State
- func (m *Roll) Status(ctx context.Context, schema string) (*state.Status, error)
- func (m *Roll) UnappliedMigrations(ctx context.Context, dir fs.FS) ([]*migrations.Migration, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoMigrationFiles = fmt.Errorf("no migration files found") ErrNoMigrationApplied = fmt.Errorf("no migrations applied") )
var ErrMismatchedMigration = fmt.Errorf("remote migration does not match local migration")
Functions ¶
func LatestVersionLocal ¶ added in v0.11.0
LatestVersionLocal returns the name of the last migration in `dir`, where the migration files are lexicographically ordered by filename.
func VersionedSchemaName ¶
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 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
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 WithSearchPath ¶ added in v0.7.0
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
WithSkipValidation controls whether or not to perform validation on migrations. If set to true, validation will be skipped.
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) LatestVersionRemote ¶ added in v0.8.0
LatestVersionRemote returns the name of the last migration to have been applied to the target schema.
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) ([]*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
State returns the state instance the Roll instance is acting on
func (*Roll) UnappliedMigrations ¶ added in v0.8.0
UnappliedMigrations returns a slice of unapplied migrations from `dir`, lexicographically ordered by filename without extension. 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.