Skip to content

Commit

Permalink
Add more fallback cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanslade committed Dec 13, 2024
1 parent edfed1c commit 7abd366
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/sql2pgroll/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,19 @@ func convertAlterTableAddForeignKeyConstraint(stmt *pgq.AlterTableStmt, constrai
func canConvertAlterTableAddForeignKeyConstraint(constraint *pgq.Constraint) bool {
switch constraint.GetFkUpdAction() {
case "r", "c", "n", "d":
// We ignore "a" above since this is NO ACTION, the default
// RESTRICT, CASCADE, SET NULL, SET DEFAULT
return false
case "a":
// NO ACTION, the default
break
}
switch constraint.GetFkMatchtype() {
case "f":
// FULL
return false
case "s":
// SIMPLE, the default
break
}
return true
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql2pgroll/alter_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ func TestUnconvertableAlterTableStatements(t *testing.T) {
"ALTER TABLE foo ADD CONSTRAINT fk_bar_cd FOREIGN KEY (a, b) REFERENCES bar (c, d) ON UPDATE CASCADE;",
"ALTER TABLE foo ADD CONSTRAINT fk_bar_cd FOREIGN KEY (a, b) REFERENCES bar (c, d) ON UPDATE SET NULL;",
"ALTER TABLE foo ADD CONSTRAINT fk_bar_cd FOREIGN KEY (a, b) REFERENCES bar (c, d) ON UPDATE SET DEFAULT;",
"ALTER TABLE foo ADD CONSTRAINT fk_bar_cd FOREIGN KEY (a, b) REFERENCES bar (c, d) MATCH FULL;",
// MATCH PARTIAL is not implemented in the actual parser yet
//"ALTER TABLE foo ADD CONSTRAINT fk_bar_cd FOREIGN KEY (a, b) REFERENCES bar (c, d) MATCH PARTIAL;",
}

for _, sql := range tests {
Expand Down

0 comments on commit 7abd366

Please sign in to comment.