Permalink
Browse files

diff/push: improve debug logging for unsupported table-diff edge case

With --debug enabled, when diff/push encounters a scenario in which Go La Tengo
cannot generate a diff for a table, Skeema ordinarily already displays a textual
diff of the actual vs expected CREATE TABLE statements. However, it did not
previously have a notion of unsupported *table-diffs* -- e.g., cases where Go La
Tengo can fully parse both tables and generate CREATE TABLE statements for them,
but cannot generate a corresponding ALTER TABLE for them. This situation is now
handled as well.

This is really just a safety/assertion improvement, as this scenario is not
expected to actually come up.
  • Loading branch information...
evanelias committed Jan 13, 2017
1 parent 5f60458 commit 611b1b9fec33098b21b5e62c1e948f95deffff9a
Showing with 29 additions and 17 deletions.
  1. +1 −1 Godeps/Godeps.json
  2. +19 −16 target.go
  3. +9 −0 vendor/github.com/skeema/tengo/table.go
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -304,27 +304,30 @@ func (t *Target) verifyDiff(diff *tengo.SchemaDiff) (err error) {
return nil
}
-// logUnsupportedTableDiff provides debug logging to identify why a table is
-// considered unsupported. It is "best effort" and simply returns early if it
-// encounters any errors.
+// logUnsupportedTableDiff provides debug logging to identify why a table (or
+// the diff operation between two versions of a table) is considered
+// unsupported. It is "best effort" and simply returns early if it encounters
+// any errors.
func (t *Target) logUnsupportedTableDiff(name string) {
- table, err := t.SchemaFromDir.Table(name)
- if err != nil {
+ var expectedCreate, actualCreate string
+
+ // Figure out which part is unsupported; this will determine what we're diffing
+ if dirTable, err := t.SchemaFromDir.Table(name); err == nil && dirTable != nil && dirTable.UnsupportedDDL {
+ expectedCreate = dirTable.GeneratedCreateStatement()
+ actualCreate = dirTable.CreateStatement()
+ } else if instTable, err := t.SchemaFromInstance.Table(name); err == nil && instTable != nil && instTable.UnsupportedDDL {
+ expectedCreate = instTable.GeneratedCreateStatement()
+ actualCreate = instTable.CreateStatement()
+ } else if dirTable != nil && instTable != nil && dirTable.CreateStatement() != instTable.CreateStatement() {
+ expectedCreate = dirTable.CreateStatement()
+ actualCreate = instTable.CreateStatement()
+ } else {
return
}
- // If the table from the dir is supported (or doesn't exist), obtain the
- // table from the instance instead.
- if table == nil || !table.UnsupportedDDL {
- table, err = t.SchemaFromInstance.Table(name)
- if table == nil || err != nil || !table.UnsupportedDDL {
- return
- }
- }
-
diff := difflib.UnifiedDiff{
- A: difflib.SplitLines(table.GeneratedCreateStatement()),
- B: difflib.SplitLines(table.CreateStatement()),
+ A: difflib.SplitLines(expectedCreate),
+ B: difflib.SplitLines(actualCreate),
FromFile: "Skeema-expected",
ToFile: "MySQL-actual",
Context: 0,

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 611b1b9

Please sign in to comment.