From 886c98865c89821a1006b0005a46729de6326b98 Mon Sep 17 00:00:00 2001 From: Aleksandr Tuliakov Date: Fri, 13 Oct 2023 12:41:02 +0400 Subject: [PATCH] fix: change DefaultValueValue to the same as other drivers --- migrator.go | 3 ++- migrator_test.go | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) 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",