Permalink
Browse files

pull: New option --new-schemas to control new schema handling

Previously, `skeema pull` would always look for schemas (databases) that exist
on the instance, but have no filesystem representation yet. It will then create
and populate new directories for these schemas.

This commit adds a new option to control this behavior. It is enabled by
default, preserving the previous behavior.

However, when using a workflow that involves running `skeema pull development`
regularly, it may be useful to disable this option. For example, if the
development environment tends to contain various extra schemas for testing
purposes, set `skip-new-schemas` in a global or top-level .skeema file's
`[development]` section to avoid storing these testing schemas in the
filesystem.

Resolves #38.
  • Loading branch information...
evanelias committed Oct 31, 2018
1 parent fef797d commit 5aa616821f77ea4649eb958a1a0367a15487c922
Showing with 28 additions and 0 deletions.
  1. +4 −0 cmd_pull.go
  2. +13 −0 doc/options.md
  3. +11 −0 skeema_cmd_test.go
@@ -32,6 +32,7 @@ top of the file. If no environment name is supplied, the default is
cmd := mybase.NewCommand("pull", summary, desc, PullHandler)
cmd.AddOption(mybase.BoolOption("include-auto-inc", 0, false, "Include starting auto-inc values in new table files, and update in existing files"))
cmd.AddOption(mybase.BoolOption("normalize", 0, true, "Reformat *.sql files to match SHOW CREATE TABLE"))
cmd.AddOption(mybase.BoolOption("new-schemas", 0, true, "Detect any new schemas and populate new dirs for them"))
cmd.AddArg("environment", "production", false)
CommandSuite.AddSubCommand(cmd)
}
@@ -323,6 +324,9 @@ func updateFlavor(dir *fs.Dir, instance *tengo.Instance) {
}
func findNewSchemas(dir *fs.Dir, instance *tengo.Instance, seenNames []string) error {
if !dir.Config.GetBool("new-schemas") {
return nil
}
subdirHasSchema := make(map[string]bool)
for _, name := range seenNames {
subdirHasSchema[name] = true
@@ -25,6 +25,7 @@
* [ignore-schema](#ignore-schema)
* [ignore-table](#ignore-table)
* [include-auto-inc](#include-auto-inc)
* [new-schemas](#new-schemas)
* [normalize](#normalize)
* [password](#password)
* [port](#port)
@@ -465,6 +466,18 @@ In `skeema pull`, a false value omits AUTO_INCREMENT=X clauses in any *newly-wri
Only set this to true if you intentionally need to track auto_increment values in all tables. If only a few tables require nonstandard auto_increment, simply include the value manually in the CREATE TABLE statement in the *.sql file. Subsequent calls to `skeema pull` won't strip it, even if `include-auto-inc` is false.
### new-schemas
Commands | pull
--- | :---
**Default** | true
**Type** | boolean
**Restrictions** | none
If true, `skeema pull` will look for schemas (databases) that exist on the instance, but have no filesystem representation yet. It will then create and populate new directories for these schemas. If false, this step is skipped, and new schemas will not be pulled into the filesystem.
When using a workflow that involves running `skeema pull development` regularly, it may be useful to disable this option. For example, if the development environment tends to contain various extra schemas for testing purposes, set `skip-new-schemas` in a global or top-level .skeema file's `[development]` section to avoid storing these testing schemas in the filesystem.
### normalize
Commands | pull
@@ -219,6 +219,17 @@ func (s SkeemaIntegrationSuite) TestPullHandler(t *testing.T) {
if !strings.Contains(contents, "# random comment") {
t.Error("Expected mydb/product/posts.sql to retain its extraneous comment, but it was removed")
}
// Test behavior with --skip-new-schemas: new schema should not have a dir in
// fs, but changes to existing schemas should still be made
s.sourceSQL(t, "pull1.sql")
s.handleCommand(t, CodeSuccess, ".", "skeema pull --skip-new-schemas")
if _, err := os.Stat("mydb/archives"); !os.IsNotExist(err) {
t.Errorf("Expected os.Stat to return IsNotExist error for mydb/archives; instead err=%v", err)
}
if _, err := os.Stat("mydb/analytics/widget_counts.sql"); err != nil {
t.Errorf("Expected os.Stat to return nil error for mydb/analytics/widget_counts.sql; instead err=%v", err)
}
}
func (s SkeemaIntegrationSuite) TestLintHandler(t *testing.T) {

0 comments on commit 5aa6168

Please sign in to comment.