refactor(schema): Add support for migration editions
This refactors the schema package and subpackages to support editions.
An Edition is a collection of sql migrations. A given boundary binary
can have multiple migration editions. The `schema.Manager` is updated to
apply the necessary migrations in the correct order, leveraging an
Edition's priority to determine the order in which the separate Editions
are applied.
The sql migration files are now nested under a directory for the
edition.
This also switches from the generated code to using embed, which
eliminates the need for the `make migrations` target and the generated
code. As such this commit removes the target and generated code.
See:
https://pkg.go.dev/embed
This commit is contained in:
144 files changed
+3469
-11098
No files matched your search
@@ -425,24 +425,22 @@ func (c *Command) Run(args []string) int {
|
||||
c.UI.Error(fmt.Errorf("Error checking schema state: %w", err).Error())
|
||||
return base.CommandCliError
|
||||
}
|
||||
if !ckState.InitializationStarted {
|
||||
if !ckState.Initialized {
|
||||
c.UI.Error(base.WrapAtLength("The database has not been initialized. Please run 'boundary database init'."))
|
||||
return base.CommandCliError
|
||||
}
|
||||
if ckState.Dirty {
|
||||
c.UI.Error(base.WrapAtLength("Database is in a bad state. Please revert the database into the last known good state."))
|
||||
return base.CommandCliError
|
||||
}
|
||||
if ckState.BinarySchemaVersion > ckState.DatabaseSchemaVersion {
|
||||
if !ckState.MigrationsApplied() {
|
||||
for _, e := range ckState.Editions {
|
||||
if e.DatabaseSchemaState == schema.Ahead {
|
||||
c.UI.Error(base.WrapAtLength(fmt.Sprintf("Newer schema version (%s %d) "+
|
||||
"than this binary expects. Please use a newer version of the boundary "+
|
||||
"binary.", e.Name, e.DatabaseSchemaVersion)))
|
||||
return base.CommandCliError
|
||||
}
|
||||
}
|
||||
c.UI.Error(base.WrapAtLength("Database schema must be updated to use this version. Run 'boundary database migrate' to update the database. NOTE: Boundary does not currently support live migration; ensure all controllers are shut down before running the migration command."))
|
||||
return base.CommandCliError
|
||||
}
|
||||
if ckState.BinarySchemaVersion < ckState.DatabaseSchemaVersion {
|
||||
c.UI.Error(base.WrapAtLength(fmt.Sprintf("Newer schema version (%d) "+
|
||||
"than this binary expects. Please use a newer version of the boundary "+
|
||||
"binary.", ckState.DatabaseSchemaVersion)))
|
||||
return base.CommandCliError
|
||||
}
|
||||
if err := c.verifyKmsSetup(); err != nil {
|
||||
c.UI.Error(base.WrapAtLength("Database is in a bad state. Please revert the database into the last known good state."))
|
||||
return base.CommandCliError
|
||||
|
||||
Reference in new issue
Block a user