Documentation
¶
Index ¶
- Variables
- func LatestMigrationNameLocal(ctx context.Context, dir fs.FS) (string, error)
- func LatestVersionLocal(ctx context.Context, dir fs.FS) (string, error)
- func VersionedSchemaName(schema string, version string) string
- type MigrationHooks
- type MigrationStatus
- type Option
- func WithLockTimeoutMs(lockTimeoutMs int) Option
- func WithLogging(enabled bool) Option
- func WithMigrationHooks(hooks MigrationHooks) Option
- func WithRole(role string) Option
- func WithSearchPath(schemas ...string) Option
- func WithSkipValidation(skip bool) Option
- func WithVersionSchema(enabled bool) Option
- type PGVersion
- type Roll
- func (m *Roll) Close() error
- func (m *Roll) Complete(ctx context.Context) error
- func (m *Roll) CreateBaseline(ctx context.Context, baselineVersion string) error
- func (m *Roll) Init(ctx context.Context) error
- func (m *Roll) LatestMigrationNameRemote(ctx context.Context) (string, error)
- func (m *Roll) LatestVersionRemote(ctx context.Context) (string, error)
- func (m *Roll) MissingMigrations(ctx context.Context, dir fs.FS) ([]*migrations.RawMigration, 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) (*backfill.Job, error)
- func (m *Roll) State() *state.State
- func (m *Roll) Status(ctx context.Context, schema string) (*Status, error)
- func (m *Roll) UnappliedMigrations(ctx context.Context, dir fs.FS) ([]*migrations.RawMigration, error)
- func (m *Roll) UseVersionSchema() bool
- func (m *Roll) Validate(ctx context.Context, migration *migrations.Migration) error
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoMigrationFiles = fmt.Errorf("no migration files found") ErrNoMigrationApplied = fmt.Errorf("no migrations applied") ErrNoVersionSchema = fmt.Errorf("no version schemas found") )
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
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
LatestVersionLocal returns the version schema 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 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
WithLockTimeoutMs sets the lock timeout in milliseconds for pgroll DDL operations
func WithLogging ¶ added in v0.12.0
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 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.
func WithVersionSchema ¶ added in v0.14.0
WithVersionSchema enables or disables the creation of version schema for migrations.
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) CreateBaseline ¶ added in v0.13.0
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) LatestMigrationNameRemote ¶ added in v0.14.0
LatestMigrationNameRemote returns the name of the last migration to have been applied to the target schema.
func (*Roll) LatestVersionRemote ¶ added in v0.8.0
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) 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
State returns the state instance the Roll instance is acting on
func (*Roll) Status ¶ added in v0.4.1
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
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.