related to bug 29923: upgrading from 2.50 to pi shows errors in update.database
authorAsier Lostalé <asier.lostale@openbravo.com>
Tue, 26 May 2015 12:38:57 +0200
changeset 598 b5dc42ee72ef
parent 597 1e59779fa59f
child 599 94360b8e364e
related to bug 29923: upgrading from 2.50 to pi shows errors in update.database

added test case
src-test/model/recreation/FK4.xml
src-test/model/recreation/FK41.xml
src-test/src/org/openbravo/dbsm/test/model/recreation/OtherRecreations.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/model/recreation/FK4.xml	Tue May 26 12:38:57 2015 +0200
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+  <database name="TABLE TEST">
+    <table name="TEST" primaryKey="TEST_KEY">
+      <column name="TEST_ID" primaryKey="true" required="true" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="COL1" primaryKey="false" required="false" type="DECIMAL" size="10,0" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+    </table>
+
+    <table name="TEST2" primaryKey="TEST2_KEY">
+      <column name="TEST2_ID" primaryKey="true" required="true" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="TEST_ID" primaryKey="false" required="true" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="COL1" primaryKey="false" required="false" type="VARCHAR" size="10" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <foreign-key foreignTable="TEST" name="TEST2_TEST_FK">
+        <reference local="TEST_ID" foreign="TEST_ID"/>
+      </foreign-key>
+    </table>
+  </database>
+  
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/model/recreation/FK41.xml	Tue May 26 12:38:57 2015 +0200
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+  <database name="TABLE TEST">
+    <table name="TEST" primaryKey="TEST_KEY">
+      <column name="TEST_ID" primaryKey="true" required="true" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="COL1" primaryKey="false" required="false" type="DECIMAL" size="10,0" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+    </table>
+
+    <table name="TEST2" primaryKey="TEST2_KEY">
+      <column name="TEST2_ID" primaryKey="true" required="true" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="TEST_ID" primaryKey="false" required="true" type="VARCHAR" size="32" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <column name="COL1" primaryKey="false" required="false" type="VARCHAR" size="100" autoIncrement="false">
+        <default/>
+        <onCreateDefault/>
+      </column>
+      <foreign-key foreignTable="TEST" name="TEST2_TEST_FK">
+        <reference local="TEST_ID" foreign="TEST_ID"/>
+      </foreign-key>
+    </table>
+  </database>
+  
\ No newline at end of file
--- a/src-test/src/org/openbravo/dbsm/test/model/recreation/OtherRecreations.java	Tue May 26 12:36:41 2015 +0200
+++ b/src-test/src/org/openbravo/dbsm/test/model/recreation/OtherRecreations.java	Tue May 26 12:38:57 2015 +0200
@@ -172,6 +172,19 @@
     updateDatabase("recreation/FK3.xml", "data/createDefault", Arrays.asList("TEST", "TEST2"));
   }
 
+  /**
+   * When there is a FK from a non AD table to a recreated AD table it failed because it tried to
+   * drop FK twice. See issue #29923
+   */
+  @Test
+  public void fkToADRecreatedTable() throws SQLException {
+    resetDB();
+    updateDatabase("recreation/FK4.xml", "data/createDefault", Arrays.asList("TEST"));
+    System.out.println("\n\n*****************************************************************");
+    // checking real update
+    updateDatabase("recreation/FK41.xml", "data/createDefault", Arrays.asList("TEST"));
+  }
+
   @Test
   public void newTableWithDiffDefaultAndOCD() {
     resetDB();