Skip to content

Commit

Permalink
Fix for tests and for migration generation
Browse files Browse the repository at this point in the history
Test Fix: Adds missing commas

Migration fix: Removes invalid field values before generating references
  • Loading branch information
dotvezz committed Jun 13, 2021
1 parent 76ba3be commit 8e238d4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions internal/dbms/mysql/adapter_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ func (a *adapter) AddReference(tName string, fTable schema.Table, r schema.Refer

for i, lColName := range lCols {
fCol, _ := fTable.GetColumn(fCols[i])

// Remove possibly invalid properties of fCol
fCol.AutoIncrement = false
fCol.PrimaryKey = false

// Set properties of fCol to be correct for the current operation
fCol.Nullable = !r.Required

sw.WriteString(a.AddColumn(tName, lColName, fCol)) // use fCol because the column's definition needs to match
sw.WriteRune('\n')
}
Expand Down
4 changes: 2 additions & 2 deletions internal/dbms/mysql/adapter_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func Test_adapter_CreateTable(t *testing.T) {
},
},
},
wantS: "CREATE TABLE `table` (\n `column` INT SIGNED NOT NULL\n);",
wantS: "CREATE TABLE `table` (\n `column` INT SIGNED NOT NULL,\n);",
},
"two column with primary key": {
tName: "table",
Expand All @@ -129,7 +129,7 @@ func Test_adapter_CreateTable(t *testing.T) {
},
wantS: "CREATE TABLE `table` (\n" +
" `column` INT SIGNED NOT NULL,\n" +
" `column2` INT SIGNED NOT NULL\n" +
" `column2` INT SIGNED NOT NULL,\n" +
" PRIMARY KEY (`column`)\n);",
},
}
Expand Down

0 comments on commit 8e238d4

Please sign in to comment.