fixed bug 30016: upgrading from 2.50 to pi some FKs are missing 3.0PR15Q3 3.0PR15Q3.1 3.0PR15Q3.2 3.0PR15Q3.3 3.0PR15Q3.4 3.0PR15Q3.5
authorAsier Lostalé <asier.lostale@openbravo.com>
Wed, 27 May 2015 14:58:33 +0200
changeset 602 d5d21a543e48
parent 601 386d20e998ca
child 603 579b82cafcd8
child 612 2bf9eb701bee
fixed bug 30016: upgrading from 2.50 to pi some FKs are missing

There were 2 scenarios where this occurred:
* FKs from recreated to non recreated tables in case none of them are in AD
* both tables participating in the FK are recreated and the referenced one
is loaded before the referencing one in the model
src/org/apache/ddlutils/platform/PlatformImplBase.java
src/org/apache/ddlutils/platform/SqlBuilder.java
--- a/src/org/apache/ddlutils/platform/PlatformImplBase.java	Wed May 27 14:51:56 2015 +0200
+++ b/src/org/apache/ddlutils/platform/PlatformImplBase.java	Wed May 27 14:58:33 2015 +0200
@@ -2383,13 +2383,12 @@
       for (int i = 0; i < model.getTableCount(); i++) {
         Table table = model.getTable(i);
         if (dataset.getTable(table.getName()) != null) {
-          if (!recreatedTables.contains(table.getName())) {
-            getSqlBuilder().createExternalForeignKeys(model, table, true);
-          }
+          getSqlBuilder().createExternalForeignKeys(model, table, true);
         } else {
           for (int j = 0; j < table.getForeignKeyCount(); j++) {
             ForeignKey fk = table.getForeignKey(j);
-            if (dataset.getTable(fk.getForeignTableName()) != null
+            if ((recreatedTables.contains(table.getName()) || dataset.getTable(fk
+                .getForeignTableName()) != null)
                 && !recreatedTables.contains(fk.getForeignTableName())) {
               getSqlBuilder().writeExternalForeignKeyCreateStmt(model, table, fk);
             }
--- a/src/org/apache/ddlutils/platform/SqlBuilder.java	Wed May 27 14:51:56 2015 +0200
+++ b/src/org/apache/ddlutils/platform/SqlBuilder.java	Wed May 27 14:58:33 2015 +0200
@@ -1592,17 +1592,20 @@
     int numTablesInOldModel = currentModel.getTableCount();
     for (int i = 0; i < numTablesInOldModel; i++) {
       Table oldTable = currentModel.getTable(i);
-      if (recreatedTables.contains(oldTable.getName())) {
-        // no need to drop FKs in already recreated tables
-        continue;
-      }
+
       for (int fkIdx = 0; fkIdx < oldTable.getForeignKeyCount(); fkIdx++) {
         ForeignKey oldFk = oldTable.getForeignKey(fkIdx);
         if (!tableName.equals(oldFk.getForeignTableName())) {
           // we only care at this point about FKs to current table
           continue;
         }
-        writeExternalForeignKeyDropStmt(oldTable, oldFk);
+
+        if (!recreatedTables.contains(oldTable.getName())) {
+          // no need to drop FKs in already recreated tables, but we need to remember it as dropped
+          // to be recreated later
+          writeExternalForeignKeyDropStmt(oldTable, oldFk);
+        }
+
         droppedFKs.add(oldFk.getName());
       }
     }