Generate postgres.gen.go using schema version directory structure (#808)

* Reorganize the db migration .sql scripts into individual schema version directories and generate the sql httpfs fakeFile accordingly.

* Created a /dev schema version directory to hold db schema updates that have not been finalized.

* Add an 'allow-development-migrations' flag to allow `boundary database init` to be executed even when there are schema updates in /dev.
This commit is contained in:
Todd Knight authored and GitHub committed 2020-12-04 21:32:27 -07:00
1 parent d8f8d60418
commit f6e50006fc
53 files changed
+116 -29

No files matched your search

+29 -7
View File
@@ -8,6 +8,7 @@ import (
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/config"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/migrations"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/sdk/wrapper"
@@ -37,6 +38,7 @@ type InitCommand struct {
flagLogLevel string
flagLogFormat string
flagMigrationUrl string
flagAllowDevMigrations bool
flagSkipInitialLoginRoleCreation bool
flagSkipAuthMethodCreation bool
flagSkipScopesCreation bool
@@ -116,6 +118,12 @@ func (c *InitCommand) Flags() *base.FlagSets {
f = set.NewFlagSet("Init Options")
f.BoolVar(&base.BoolVar{
Name: "allow-development-migrations",
Target: &c.flagAllowDevMigrations,
Usage: "If set the init will continue even if the schema includes database update steps that may not be supported in the next official release. Boundary does not provide a rollback mechanism so a backup should be taken independently if needed.",
})
f.BoolVar(&base.BoolVar{
Name: "skip-initial-login-role-creation",
Target: &c.flagSkipInitialLoginRoleCreation,
@@ -176,6 +184,20 @@ func (c *InitCommand) Run(args []string) (retCode int) {
}()
}
if migrations.DevMigration != c.flagAllowDevMigrations {
if migrations.DevMigration {
c.UI.Error(base.WrapAtLength("This version of the binary has " +
"dev database schema updates which may not be supported in the " +
"next official release. To proceed anyways please use the " +
"'-allow-development-migrations' flag."))
return 2
} else {
c.UI.Error(base.WrapAtLength("The '-allow-development-migrations' " +
"flag was set but this binary has no dev database schema updates."))
return 3
}
}
c.srv = base.NewServer(&base.Command{UI: c.UI})
if err := c.srv.SetupLogging(c.flagLogLevel, c.flagLogFormat, c.Config.LogLevel, c.Config.LogFormat); err != nil {
@@ -455,6 +477,13 @@ func (c *InitCommand) ParseFlagsAndConfig(args []string) int {
return 1
}
// Validation
switch {
case len(c.flagConfig) == 0:
c.UI.Error("Must specify a config file using -config")
return 1
}
wrapperPath := c.flagConfig
if c.flagConfigKms != "" {
wrapperPath = c.flagConfigKms
@@ -472,13 +501,6 @@ func (c *InitCommand) ParseFlagsAndConfig(args []string) int {
}
}
// Validation
switch {
case len(c.flagConfig) == 0:
c.UI.Error("Must specify a config file using -config")
return 1
}
c.Config, err = config.LoadFile(c.flagConfig, wrapper)
if err != nil {
c.UI.Error("Error parsing config: " + err.Error())