Skip to content

Commit

Permalink
fix: change DefaultValueValue to the same as other drivers (#222)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandr Tuliakov <[email protected]>
  • Loading branch information
MrChaos1993 and Aleksandr Tuliakov authored Oct 26, 2023
1 parent 89bd876 commit 7630365
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,5 +786,6 @@ func (m Migrator) RenameColumn(dst interface{}, oldName, field string) error {
}

func parseDefaultValueValue(defaultValue string) string {
return regexp.MustCompile(`^(.*?)(?:::.*)?$`).ReplaceAllString(defaultValue, "$1")
value := regexp.MustCompile(`^(.*?)(?:::.*)?$`).ReplaceAllString(defaultValue, "$1")
return strings.Trim(value, "'")
}
12 changes: 6 additions & 6 deletions migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ func Test_parseDefaultValueValue(t *testing.T) {
{
name: "it should works with empty string without colons",
args: args{defaultValue: "''"},
want: "''",
want: "",
},
{
name: "it should works with empty string with two colons",
args: args{defaultValue: "''::character varying"},
want: "''",
want: "",
},
{
name: "it should works with empty string with three colons",
args: args{defaultValue: "'':::character varying"},
want: "''",
want: "",
},
{
name: "it should works with string without colons",
args: args{defaultValue: "'field'"},
want: "'field'",
want: "field",
},
{
name: "it should works with string with two colons",
args: args{defaultValue: "'field'::character varying"},
want: "'field'",
want: "field",
},
{
name: "it should works with string with three colons",
args: args{defaultValue: "'field':::character varying"},
want: "'field'",
want: "field",
},
{
name: "it should works with value with two colons",
Expand Down

0 comments on commit 7630365

Please sign in to comment.