Skip to content

Commit f5ba0ac

Browse files
author
James Cor
committed
fix gms foreign key chain
1 parent 54bd6d6 commit f5ba0ac

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

enginetest/queries/update_queries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,9 @@ var UpdateIgnoreScripts = []ScriptTest{
707707
Name: "UPDATE IGNORE with foreign keys",
708708
SetUpScript: []string{
709709
"CREATE TABLE colors ( id INT NOT NULL, color VARCHAR(32) NOT NULL, PRIMARY KEY (id), INDEX color_index(color));",
710-
"CREATE TABLE objects (id INT NOT NULL, name VARCHAR(64) NOT NULL,color VARCHAR(32), PRIMARY KEY(id),FOREIGN KEY (color) REFERENCES colors(color))",
711-
"INSERT INTO colors (id,color) VALUES (1,'red'),(2,'green'),(3,'blue'),(4,'purple')",
712-
"INSERT INTO objects (id,name,color) VALUES (1,'truck','red'),(2,'ball','green'),(3,'shoe','blue')",
710+
"CREATE TABLE objects (id INT NOT NULL, name VARCHAR(64) NOT NULL,color VARCHAR(32), PRIMARY KEY(id),FOREIGN KEY (color) REFERENCES colors(color));",
711+
"INSERT INTO colors (id,color) VALUES (1,'red'),(2,'green'),(3,'blue'),(4,'purple');",
712+
"INSERT INTO objects (id,name,color) VALUES (1,'truck','red'),(2,'ball','green'),(3,'shoe','blue');",
713713
},
714714
Assertions: []ScriptTestAssertion{
715715
{

sql/analyzer/apply_foreign_keys.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ func getForeignKeyEditor(ctx *sql.Context, a *Analyzer, tbl sql.ForeignKeyTable,
209209
if err != nil {
210210
return nil, err
211211
}
212-
return getForeignKeyRefActions(ctx, a, tbl, cache, fkChain, fkEditor, checkRows)
212+
fkEditor, err = getForeignKeyRefActions(ctx, a, tbl, cache, fkChain, fkEditor, checkRows)
213+
if err != nil {
214+
return nil, err
215+
}
216+
return fkEditor, err
213217
}
214218

215219
// getForeignKeyReferences returns an editor containing only the references for the given table.
@@ -238,7 +242,7 @@ func getForeignKeyReferences(ctx *sql.Context, a *Analyzer, tbl sql.ForeignKeyTa
238242
if err != nil {
239243
return nil, err
240244
}
241-
fkChain = fkChain.AddTable(fks[0].ParentDatabase, fks[0].ParentTable).AddTableUpdater(fks[0].ParentDatabase, fks[0].ParentTable, updater)
245+
fkChain = fkChain.AddTableUpdater(fks[0].Database, fks[0].Table, updater)
242246

243247
tblSch := tbl.Schema()
244248
fkEditor := &plan.ForeignKeyEditor{
@@ -383,7 +387,8 @@ func getForeignKeyRefActions(ctx *sql.Context, a *Analyzer, tbl sql.ForeignKeyTa
383387
return nil, err
384388
}
385389

386-
childEditor, err := getForeignKeyEditor(ctx, a, childTbl, cache, fkChain.AddForeignKey(fk.Name), checkRows)
390+
fkChain = fkChain.AddForeignKey(fk.Name)
391+
childEditor, err := getForeignKeyEditor(ctx, a, childTbl, cache, fkChain, checkRows)
387392
if err != nil {
388393
return nil, err
389394
}
@@ -541,7 +546,7 @@ func (cache *foreignKeyCache) GetEditor(fkEditor *plan.ForeignKeyEditor, dbName
541546
type foreignKeyChain struct {
542547
fkNames map[string]struct{}
543548
fkTables map[foreignKeyTableName]struct{}
544-
fkUpdate map[foreignKeyTableName]sql.ForeignKeyEditor
549+
fkUpdate map[foreignKeyTableName]sql.ForeignKeyEditor // TODO: why is this even a map?
545550
}
546551

547552
// AddTable returns a new chain with the added table.

0 commit comments

Comments
 (0)