Skip to content

Commit

Permalink
avoid unnecessary default changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aj0strow committed Jan 14, 2017
1 parent 448c55f commit 4c0e695
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cli/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package cli

const Version = "0.0.4"
const Version = "0.0.5"
8 changes: 6 additions & 2 deletions plan/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import (
)

func setDefault(a, b *db.Column) bool {
return a.Default != b.Default && a.Default != ""
return !defaultEqual(a, b) && a.Default != ""
}

func dropDefault(a, b *db.Column) bool {
return a.Default != b.Default && b.Default != ""
return !defaultEqual(a, b) && b.Default != ""
}

func defaultEqual(a, b *db.Column) bool {
return a.Default == b.Default || a.Default+"::"+a.DataType == b.Default
}
24 changes: 24 additions & 0 deletions plan/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ func TestSetDefault(t *testing.T) {
&db.Column{},
true,
},
Test{
`ignore type casting`,
&db.Column{
DataType: "text",
Default: `''`,
},
&db.Column{
DataType: "text",
Default: `''::text`,
},
false,
},
}
for _, test := range tests {
if setDefault(test.A, test.B) != test.SetDefault {
Expand Down Expand Up @@ -94,6 +106,18 @@ func TestDropDefault(t *testing.T) {
&db.Column{},
false,
},
Test{
`ignore type casting`,
&db.Column{
DataType: "text",
Default: `''`,
},
&db.Column{
DataType: "text",
Default: `''::text`,
},
false,
},
}
for _, test := range tests {
if dropDefault(test.A, test.B) != test.DropDefault {
Expand Down

0 comments on commit 4c0e695

Please sign in to comment.