Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrColumnOrderingChanged is returned when the ordering of columns changes and column ordering is not ignored. // It is recommended to ignore column ordering changes to column order ErrColumnOrderingChanged = fmt.Errorf("column ordering changed: %w", ErrNotImplemented) )
var ErrNotImplemented = fmt.Errorf("not implemented")
Functions ¶
This section is empty.
Types ¶
type MigrationHazard ¶
type MigrationHazard struct {
Type MigrationHazardType
Message string
}
MigrationHazard represents a hazard that a statement poses to a database
func (MigrationHazard) String ¶
func (p MigrationHazard) String() string
type MigrationHazardType ¶
type MigrationHazardType = string
const ( MigrationHazardTypeAcquiresAccessExclusiveLock MigrationHazardType = "ACQUIRES_ACCESS_EXCLUSIVE_LOCK" MigrationHazardTypeCorrectness MigrationHazardType = "CORRECTNESS" MigrationHazardTypeDeletesData MigrationHazardType = "DELETES_DATA" MigrationHazardTypeHasUntrackableDependencies MigrationHazardType = "HAS_UNTRACKABLE_DEPENDENCIES" MigrationHazardTypeIndexBuild MigrationHazardType = "INDEX_BUILD" MigrationHazardTypeIndexDropped MigrationHazardType = "INDEX_DROPPED" MigrationHazardTypeImpactsDatabasePerformance MigrationHazardType = "IMPACTS_DATABASE_PERFORMANCE" MigrationHazardTypeIsUserGenerated MigrationHazardType = "IS_USER_GENERATED" MigrationHazardTypeExtensionVersionUpgrade MigrationHazardType = "UPGRADING_EXTENSION_VERSION" )
type Plan ¶
type Plan struct {
// Statements is the set of statements to be executed in order to migrate a database from schema A to schema B
Statements []Statement
// CurrentSchemaHash is the hash of the current schema, schema A. If you serialize this plans somewhere and
// plan on running them later, you should verify that the current schema hash matches the current schema hash.
// To get the current schema hash, you can use schema.GetPublicSchemaHash(ctx, conn)
CurrentSchemaHash string
}
Plan represents a set of statements to be executed in order to migrate a database from schema A to schema B
func GeneratePlan ¶
func GeneratePlan(ctx context.Context, conn *sql.Conn, tempDbFactory tempdb.Factory, newDDL []string, opts ...PlanOpt) (Plan, error)
GeneratePlan generates a migration plan to migrate the database to the target schema.
Parameters: conn: connection to the target database you wish to migrate. tempDbFactory: used to create a temporary database instance to extract the schema from the new DDL and validate the migration plan. It is recommended to use tempdb.NewOnInstanceFactory, or you can provide your own. newDDL: DDL encoding the new schema opts: Additional options to configure the plan generation
func (Plan) ApplyLockTimeoutModifier ¶ added in v0.4.0
ApplyLockTimeoutModifier applies the given timeout to all statements that match the given regex
func (Plan) ApplyStatementTimeoutModifier ¶
ApplyStatementTimeoutModifier applies the given timeout to all statements that match the given regex
type PlanOpt ¶
type PlanOpt func(opts *planOptions)
func WithDataPackNewTables ¶
func WithDataPackNewTables() PlanOpt
WithDataPackNewTables configures the plan generation such that it packs the columns in the new tables to minimize padding. It will help minimize the storage used by the tables
func WithDoNotValidatePlan ¶
func WithDoNotValidatePlan() PlanOpt
WithDoNotValidatePlan disables plan validation, where the migration plan is tested against a temporary database instance
func WithLogger ¶
WithLogger configures plan generation to use the provided logger instead of the default
func WithRespectColumnOrder ¶ added in v0.2.0
func WithRespectColumnOrder() PlanOpt
WithRespectColumnOrder configures the plan generation to respect any changes to the ordering of columns in existing tables. You will most likely want this disabled, since column ordering changes are common
type Statement ¶
type Statement struct {
DDL string
// Timeout is the statement_timeout to apply to this statement. If implementing your own plan executor, be sure to set
// the session-level statement_timeout to this value before executing the statement. A transaction-level statement_timeout
// will not work since building indexes concurrently cannot be done in a transaction
Timeout time.Duration
// LockTimeout is the lock_timeout to apply to this statement. If implementing your own plan executor, be sure to set
// the session-level lock_timeout to this value before executing the statement. A transaction-level lock_timeout
// will not work since building indexes concurrently cannot be done in a transaction
LockTimeout time.Duration
// The hazards this statement poses
Hazards []MigrationHazard
}