Skip to content

Commit

Permalink
fix: change DefaultValueValue to the same as other drivers (go-gorm#222)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandr Tuliakov <[email protected]>
  • Loading branch information
2 people authored and PuneetPunamiya committed Jan 17, 2024
1 parent 9656209 commit 99f6ec2
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 99f6ec2

Please sign in to comment.