diff --git a/migrator.go b/migrator.go index c64caf7..c085a70 100644 --- a/migrator.go +++ b/migrator.go @@ -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, "'") } diff --git a/migrator_test.go b/migrator_test.go index 00bf835..d4305ec 100644 --- a/migrator_test.go +++ b/migrator_test.go @@ -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",