Skip to content

Commit 7630365

Browse files
MrChaos1993Aleksandr Tuliakov
and
Aleksandr Tuliakov
authored
fix: change DefaultValueValue to the same as other drivers (#222)
Co-authored-by: Aleksandr Tuliakov <[email protected]>
1 parent 89bd876 commit 7630365

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Diff for: migrator.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -786,5 +786,6 @@ func (m Migrator) RenameColumn(dst interface{}, oldName, field string) error {
786786
}
787787

788788
func parseDefaultValueValue(defaultValue string) string {
789-
return regexp.MustCompile(`^(.*?)(?:::.*)?$`).ReplaceAllString(defaultValue, "$1")
789+
value := regexp.MustCompile(`^(.*?)(?:::.*)?$`).ReplaceAllString(defaultValue, "$1")
790+
return strings.Trim(value, "'")
790791
}

Diff for: migrator_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@ func Test_parseDefaultValueValue(t *testing.T) {
2929
{
3030
name: "it should works with empty string without colons",
3131
args: args{defaultValue: "''"},
32-
want: "''",
32+
want: "",
3333
},
3434
{
3535
name: "it should works with empty string with two colons",
3636
args: args{defaultValue: "''::character varying"},
37-
want: "''",
37+
want: "",
3838
},
3939
{
4040
name: "it should works with empty string with three colons",
4141
args: args{defaultValue: "'':::character varying"},
42-
want: "''",
42+
want: "",
4343
},
4444
{
4545
name: "it should works with string without colons",
4646
args: args{defaultValue: "'field'"},
47-
want: "'field'",
47+
want: "field",
4848
},
4949
{
5050
name: "it should works with string with two colons",
5151
args: args{defaultValue: "'field'::character varying"},
52-
want: "'field'",
52+
want: "field",
5353
},
5454
{
5555
name: "it should works with string with three colons",
5656
args: args{defaultValue: "'field':::character varying"},
57-
want: "'field'",
57+
want: "field",
5858
},
5959
{
6060
name: "it should works with value with two colons",

0 commit comments

Comments
 (0)