#1336 - Change DDL generation such that it does create index before alter table add foreign key

This commit is contained in:
Rob Bygrave
2018-03-07 02:19:10 +13:00
parent 3cb52917e3
commit 2019bc7bf1
5 changed files with 8 additions and 9 deletions
@@ -435,15 +435,15 @@ public class BaseTableDdl implements TableDdl {
protected void writeForeignKey(DdlWrite write, WriteForeignKey request) throws IOException {
String tableName = lowerTableName(request.table());
DdlBuffer fkeyBuffer = write.applyForeignKeys();
alterTableAddForeignKey(fkeyBuffer, request);
String tableName = lowerTableName(request.table());
if (request.indexName() != null) {
// no matching unique constraint so add the index
fkeyBuffer.append(platformDdl.createIndex(request.indexName(), tableName, request.cols())).endOfStatement();
}
alterTableAddForeignKey(fkeyBuffer, request);
fkeyBuffer.end();
write.dropAllForeignKeys()
@@ -455,7 +455,6 @@ public class BaseTableDdl implements TableDdl {
}
write.dropAllForeignKeys().end();
}
protected void alterTableAddForeignKey(DdlBuffer buffer, WriteForeignKey request) throws IOException {
@@ -1,3 +1,3 @@
alter table mytable add constraint fk_mytable_order_id foreign key (order_id) references orders (id) on delete restrict on update restrict;
create index ix_mytable_order_id on mytable (order_id);
alter table mytable add constraint fk_mytable_order_id foreign key (order_id) references orders (id) on delete restrict on update restrict;
@@ -21,9 +21,9 @@ create table ckey_parent (
constraint pk_ckey_parent primary key (one_key,two_key)
);
alter table ckey_detail add constraint fk_ckey_detail_parent foreign key (one_key,two_key) references ckey_parent (one_key,two_key) on delete restrict on update restrict;
create index ix_ckey_detail_parent on ckey_detail (one_key,two_key);
alter table ckey_detail add constraint fk_ckey_detail_parent foreign key (one_key,two_key) references ckey_parent (one_key,two_key) on delete restrict on update restrict;
alter table ckey_parent add constraint fk_ckey_parent_assoc_id foreign key (assoc_id) references ckey_assoc (id) on delete restrict on update restrict;
create index ix_ckey_parent_assoc_id on ckey_parent (assoc_id);
alter table ckey_parent add constraint fk_ckey_parent_assoc_id foreign key (assoc_id) references ckey_assoc (id) on delete restrict on update restrict;
@@ -13,6 +13,6 @@ create table phones (
constraint pk_phones primary key (id)
);
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict;
create index ix_phones_person_id on phones (person_id);
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict;
@@ -13,6 +13,6 @@ create table phones (
constraint pk_phones primary key (id)
);
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict;
create index ix_phones_person_id on phones (person_id);
alter table phones add constraint fk_phones_person_id foreign key (person_id) references persons (id) on delete restrict on update restrict;