Skip to content

Commit 869dd96

Browse files
yx179971glebarez
authored andcommitted
fix ddl from exists table (go-gorm#172)
1 parent fb2dfbf commit 869dd96

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ddlmod.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
var (
1515
sqliteSeparator = "`|\"|'|\t"
16-
indexRegexp = regexp.MustCompile(fmt.Sprintf(`(?is)CREATE(?: UNIQUE)? INDEX [%v]?[\w\d-]+[%v]? ON (.*)$`, sqliteSeparator, sqliteSeparator))
16+
indexRegexp = regexp.MustCompile(fmt.Sprintf(`(?is)CREATE(?: UNIQUE)? INDEX [%v]?[\w\d-]+[%v]?(?s:.*?)ON (.*)$`, sqliteSeparator, sqliteSeparator))
1717
tableRegexp = regexp.MustCompile(fmt.Sprintf(`(?is)(CREATE TABLE [%v]?[\w\d-]+[%v]?)(?:\s*\((.*)\))?`, sqliteSeparator, sqliteSeparator))
1818
separatorRegexp = regexp.MustCompile(fmt.Sprintf("[%v]", sqliteSeparator))
1919
columnsRegexp = regexp.MustCompile(fmt.Sprintf(`[(,][%v]?(\w+)[%v]?`, sqliteSeparator, sqliteSeparator))

ddlmod_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,24 @@ func TestParseDDL(t *testing.T) {
9797
},
9898
},
9999
},
100+
{
101+
"index with \n from .schema sqlite",
102+
[]string{
103+
"CREATE TABLE `test-d` (`field` integer NOT NULL)",
104+
"CREATE INDEX `idx_uq`\n ON `test-b`(`field`) WHERE field = 0",
105+
},
106+
1,
107+
[]migrator.ColumnType{
108+
{
109+
NameValue: sql.NullString{String: "field", Valid: true},
110+
DataTypeValue: sql.NullString{String: "integer", Valid: true},
111+
ColumnTypeValue: sql.NullString{String: "integer", Valid: true},
112+
PrimaryKeyValue: sql.NullBool{Bool: false, Valid: true},
113+
UniqueValue: sql.NullBool{Bool: false, Valid: true},
114+
NullableValue: sql.NullBool{Bool: false, Valid: true},
115+
},
116+
},
117+
},
100118
}
101119

102120
for _, p := range params {

0 commit comments

Comments
 (0)