Permalink
Browse files

pull, push, diff: Permit .skeema to override flavor

push/diff: If flavor is set in .skeema, use the value here instead of auto-
detecting from the target instance. This permits operators to manually configure
the flavor when needed, for example if running a custom fork/patch-set of the
mysql-server.

pull: Previously, if a flavor was specified in .skeema but could not be auto-
detected from the running instance, Skeema would remove the flavor from .skeema.
Now it leaves it alone, allowing operators to manually configure the flavor
without risk of `skeema pull` removing it.
  • Loading branch information...
evanelias committed Aug 24, 2018
1 parent 94b0b50 commit 796de4cee2ec34f0853eb6a235da6c575dee1287
Showing with 19 additions and 11 deletions.
  1. +12 −8 cmd_pull.go
  2. +5 −1 cmd_push.go
  3. +2 −2 doc/options.md
View
@@ -94,7 +94,6 @@ func PullHandler(cfg *mybase.Config) error {
// execute the generated statement! We just examine its type.
mods := tengo.StatementModifiers{
AllowUnsafe: true,
Flavor: t.Instance.Flavor(),
}
// pull command updates next auto-increment value for existing table always
// if requested, or only if previously present in file otherwise
@@ -107,6 +106,11 @@ func PullHandler(cfg *mybase.Config) error {
if err != nil {
return err
}
if configFlavor := tengo.NewFlavor(t.Dir.Config.Get("flavor")); configFlavor != tengo.FlavorUnknown {
mods.Flavor = configFlavor
} else {
mods.Flavor = t.Instance.Flavor()
}
// Track which table names have already been seen, to handle cases where the
// same table shows up in two different TableDiffs. This can happen because
@@ -244,16 +248,16 @@ func findNewSchemas(dir *Dir) error {
}
// Update the instance dir's .skeema option file if the instance's current
// flavor does not match what's in the file
if instFlavor := instance.Flavor(); instFlavor.String() != dir.Config.Get("flavor") {
// flavor does not match what's in the file. However, leave the value in the
// file alone if it's specified and we're unable to detect the instance's
// vendor, as this gives operators the ability to manually override an
// undetectable flavor.
instFlavor := instance.Flavor()
if instFlavor.Vendor != tengo.VendorUnknown && instFlavor.String() != dir.Config.Get("flavor") {
if optionFile, err := dir.OptionFile(); err != nil {
log.Warnf("Unable to update flavor in %s/.skeema: %s", dir, err)
} else {
if instFlavor == tengo.FlavorUnknown {
optionFile.UnsetOptionValue(dir.section, "flavor")
} else {
optionFile.SetOptionValue(dir.section, "flavor", instFlavor.String())
}
optionFile.SetOptionValue(dir.section, "flavor", instFlavor.String())
if err := optionFile.Write(true); err != nil {
log.Warnf("Unable to update flavor in %s: %s", optionFile.Path(), err)
} else {
View
@@ -198,7 +198,11 @@ func pushWorker(sps *sharedPushState) {
sps.setFatalError(NewExitValue(CodeBadConfig, err.Error()))
return
}
mods.Flavor = t.Instance.Flavor()
if configFlavor := tengo.NewFlavor(t.Dir.Config.Get("flavor")); configFlavor != tengo.FlavorUnknown {
mods.Flavor = configFlavor
} else {
mods.Flavor = t.Instance.Flavor()
}
// Build DDLStatements for each TableDiff, handling pre-execution errors
// accordingly
View
@@ -348,9 +348,9 @@ Commands | *all*
This option indicates the database server vendor and version corresponding to the first [host](#host) defined in this directory. The value is formatted as "vendor:major.minor", for example "mysql:5.6", "percona:5.7", or "mariadb:10.1".
This option is automatically populated in host-level .skeema files by `skeema init`, `skeema pull`, and `skeema add-environment` beginning in Skeema v1.0.3.
This option is automatically populated in host-level .skeema files by `skeema init`, `skeema pull`, and `skeema add-environment` beginning in Skeema v1.0.3.
Currently, this option just controls use of certain session-level variables that are specific to particular vendors and versions. For example, if `flavor: mysql:8.0` is set, Skeema automatically disables the information_schema stat cache (at the session level, i.e. just for Skeema's own connections) to ensure it always sees up-to-date values in information_schema.
This option controls use of vendor-and-version-specific DDL formatting, as well as session variables. For example, if `flavor: mysql:8.0` is set, Skeema automatically disables the information_schema stat cache (at the session level, i.e. just for Skeema's own connections) to ensure it always sees up-to-date values in information_schema.
In future releases, it may also be used for purposes such as optionally offloading the [temporary schema operations](faq.md#temporary-schema-usage) to a local Docker container; the [flavor](#flavor) value will then be used to ensure the correct Docker image is used.

0 comments on commit 796de4c

Please sign in to comment.