Documentation
¶
Overview ¶
Package appschema is what an application's release does to its application database schema (#2411): apply the pending migrations so that a release with a failing migration changes nothing, and revert to an earlier release's migration version when every migration between has a down migration. It drives the appdb kind through the toolkit's exported methods and records each step in the migration history manage_schema keeps.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoKit = errors.New("this deployment has no application database connection kind")
ErrNoKit is a release of an application with a schema on a deployment with no application database kind.
Functions ¶
This section is empty.
Types ¶
type Applied ¶
type Applied struct {
// Versions is the migrations applied, in order.
Versions []int
// Head is the highest applied version after the release.
Head int
}
Applied is what a release did to the schema.
type FailedError ¶
FailedError is a release whose migrations did not all apply. Undone is the versions applied before the failure and reverted again; Left is any that could not be reverted and stay applied.
func (*FailedError) Error ¶
func (e *FailedError) Error() string
func (*FailedError) Unwrap ¶
func (e *FailedError) Unwrap() error
type Kit ¶
type Kit interface {
Status(ctx context.Context, connection, schema string, migrations []postgreskit.Migration) (*postgreskit.LedgerStatus, error)
PlanMigrations(ctx context.Context, connection, schema string, pending []postgreskit.Migration) (*postgreskit.Plan, error)
Apply(ctx context.Context, o postgreskit.ApplyOptions, migrations []postgreskit.Migration) ([]postgreskit.Migration, error)
Revert(ctx context.Context, o postgreskit.ApplyOptions, migrations []postgreskit.Migration, toVersion int) ([]postgreskit.Migration, error)
}
Kit is the part of the appdb toolkit a release uses.
type Reverted ¶
type Reverted struct {
Versions []int
// Head is the highest applied version after the rollback.
Head int
// Kept says why migrations stayed applied, empty when none did.
Kept string
}
Reverted is what a rollback did to the schema.
type Schema ¶
type Schema struct {
// Kit is the live toolkit, nil when none is registered.
Kit func() Kit
Store Store
}
Schema applies and reverts an application's migrations.
func (*Schema) Release ¶
Release applies every pending migration. The pending migrations that run in a transaction are first run together in one transaction that is rolled back, so one that fails is found before anything changes. Should a migration still fail during the apply, the ones this release applied are reverted with their down migrations.
type State ¶
type State struct {
// Applied is the highest applied version, 0 for none.
Applied int `json:"applied"`
// Pending is the versions a release would apply.
Pending []int `json:"pending"`
}
State is where a schema's migrations stand.
type Store ¶
type Store interface {
List(ctx context.Context, connection, schema string) ([]postgreskit.Migration, error)
Record(ctx context.Context, e postgreskit.MigrationEvent) error
}
Store is the platform's record of the migrations and their history.