Skip to content

Commit

Permalink
Merge pull request #184 from wenki96/main
Browse files Browse the repository at this point in the history
fix foreign key bugs
  • Loading branch information
ZSYTY authored Nov 8, 2023
2 parents d20495b + 80a7b19 commit 547cd18
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,16 @@ protected void rewriteOriginSqlWithForeignKey(BaseDdlOperation logicalDdlPlan, E
// rewrite origin sql for different naming behaviours in 5.7 & 8.0
boolean createTableWithFk = logicalDdlPlan.getDdlType() == DdlType.CREATE_TABLE
&& !((LogicalCreateTable) logicalDdlPlan).getSqlCreateTable().getAddedForeignKeys().isEmpty();
boolean alterTableAddFk = logicalDdlPlan.getDdlType() == DdlType.ALTER_TABLE
&& ((LogicalAlterTable) logicalDdlPlan).getSqlAlterTable().getAlters().get(0).getKind()
== SqlKind.ADD_FOREIGN_KEY;
boolean alterTableDropFk = logicalDdlPlan.getDdlType() == DdlType.ALTER_TABLE
&& ((LogicalAlterTable) logicalDdlPlan).getSqlAlterTable().getAlters().get(0).getKind()
== SqlKind.DROP_FOREIGN_KEY;
boolean alterTableAddFk =
logicalDdlPlan.getDdlType() == DdlType.ALTER_TABLE && logicalDdlPlan instanceof LogicalAlterTable
&& ((LogicalAlterTable) logicalDdlPlan).getSqlAlterTable().getAlters().size() == 1
&& ((LogicalAlterTable) logicalDdlPlan).getSqlAlterTable().getAlters().get(0).getKind()
== SqlKind.ADD_FOREIGN_KEY;
boolean alterTableDropFk =
logicalDdlPlan.getDdlType() == DdlType.ALTER_TABLE && logicalDdlPlan instanceof LogicalAlterTable
&& ((LogicalAlterTable) logicalDdlPlan).getSqlAlterTable().getAlters().size() == 1
&& ((LogicalAlterTable) logicalDdlPlan).getSqlAlterTable().getAlters().get(0).getKind()
== SqlKind.DROP_FOREIGN_KEY;
if (createTableWithFk) {
ec.getDdlContext().setForeignKeyOriginalSql(
((LogicalCreateTable) logicalDdlPlan).getSqlCreateTable().toString());
Expand Down

0 comments on commit 547cd18

Please sign in to comment.