MySQL Migration bug #475

Closed
marcj opened this Issue Nov 4, 2013 · 1 comment

1 participant

@marcj
Propel member

Something wrong in TableComparator::compareIndices or IndexComparator::computeDiff.

1) Propel\Tests\Issues\M2MRelationTest::testRelationThree2
Propel\Generator\Exception\BuildException: Can not execute SQL: 
CREATE INDEX `relation1_user_group_FI_3` ON `relation1_user_group` (`relation_id`)
From database: 
migration:
  relation1_user_group (relation1_user_group):
      user_id INTEGER  PK NOT NULL 'null' ()
      group_id INTEGER  PK NOT NULL 'null' ()
      group_id2 INTEGER  PK NOT NULL 'null' ()
      relation_id INTEGER  PK NOT NULL 'null' ()
    FKs:
      relation1_user_group_FK_1 (user_id => id)
      relation1_user_group_FK_2 (group_id, group_id2 => id, id2)
      relation1_user_group_FK_3 (relation_id => id)
    indices:
      relation1_user_group_FI_2 (group_id, group_id2)
      relation1_user_group_FI_3 (relation_id)
  relation1_user (relation1_user):
      id INTEGER  PK NOT NULL 'null' (AUTO_INCREMENT)
      name VARCHAR 255   'null' ()
  relation1_group (relation1_group):
      id INTEGER  PK NOT NULL 'null' (AUTO_INCREMENT)
      id2 INTEGER  PK NOT NULL 'null' ()
      name VARCHAR 255   'null' ()
  relation1_relation (relation1_relation):
      id INTEGER  PK NOT NULL 'null' (AUTO_INCREMENT)
      name VARCHAR 255   'null' ()

To database (Current): 
migration:
  relation1_group (relation1_group):
      id INTEGER  PK NOT NULL 'null' (AUTO_INCREMENT)
      id2 INTEGER  PK NOT NULL 'null' ()
      name VARCHAR 255   'null' ()
  relation1_relation (relation1_relation):
      id INTEGER  PK NOT NULL 'null' (AUTO_INCREMENT)
      name VARCHAR 255   'null' ()
  relation1_user (relation1_user):
      id INTEGER  PK NOT NULL 'null' (AUTO_INCREMENT)
      name VARCHAR 255   'null' ()
  relation1_user_group (relation1_user_group):
      user_id INTEGER  PK NOT NULL 'null' ()
      group_id INTEGER  PK NOT NULL 'null' ()
      group_id2 INTEGER  PK NOT NULL 'null' ()
      relation_id INTEGER  PK NOT NULL 'null' ()
    indices:
      relation1_user_group_FI_3 (group_id, group_id2)
      relation1_user_group_FI_2 (group_id, group_id2)


Diff:
relation1_user_group:
    addedIndices:
      - relation1_user_group_FI_3
    addedFks:
      - relation1_user_group_FK_1
      - relation1_user_group_FK_2
      - relation1_user_group_FK_3
@marcj
Propel member
--- src/Propel/Generator/Model/Diff/TableComparator.php (revision 4d5e963078cc8919aa1eba05a41655843844afb0)
+++ src/Propel/Generator/Model/Diff/TableComparator.php (revision )
@@ -243,8 +243,8 @@
         $fromTableIndices = array_merge($this->getFromTable()->getIndices(), $this->getFromTable()->getUnices());
         $toTableIndices = array_merge($this->getToTable()->getIndices(), $this->getToTable()->getUnices());

-        foreach ($toTableIndices as $toTableIndexPos => $toTableIndex) {
-            foreach ($fromTableIndices as $fromTableIndexPos => $fromTableIndex) {
+        foreach ($fromTableIndices as $fromTableIndexPos => $fromTableIndex) {
+            foreach ($toTableIndices as $toTableIndexPos => $toTableIndex) {
                 if (false === IndexComparator::computeDiff($fromTableIndex, $toTableIndex, $caseInsensitive)) {
                     unset($fromTableIndices[$fromTableIndexPos]);
                     unset($toTableIndices[$toTableIndexPos]);

Looks like this fixed it. Can someone fix that, make a unit test, run against all dbs and commit? I'm pretty busy atm.

@marcj marcj modified the milestone: alpha-3 Mar 13, 2014
@marcj marcj closed this in ca6b77e Apr 9, 2014
@mpscholten mpscholten added a commit to mpscholten/Propel2 that referenced this issue Aug 24, 2014
@marcj marcj Fixed #475 - MySQL Migration bug with indices 10f039e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment