Doctrine 1
  1. Doctrine 1
  2. DC-84

Migration automation methods break with tables and fks on the same migration class

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.0-ALPHA2
    • Fix Version/s: 1.2.0-ALPHA3
    • Component/s: Migrations
    • Labels:
      None

      Description

      Hello,

      Currently if within a single migration class one uses the automation methods $this->table() and $this->foreignKey() the process will fail when moving down because the system will execute the down direction in the same order as the up direction. For example:

      public function migrate($direction) {
      $this->table($direction, 'mytable', ...);
      $this->table($direction, 'myrelatedtable', ... );
      $this->foreignKey($direction, 'mytable', 'myfkname', ...);
      }

      Going up, everything is fine. The tables are created and the FK is applied. Going down, however will error out since by the time the FK is going to be removed the table it belons to is gone.

        Activity

        Hide
        Jonathan H. Wage added a comment -

        Hmm. Would this fix the problem? I am unsure if this would cause any other problems.

        Index: lib/Doctrine/Migration.php
        ===================================================================
        --- lib/Doctrine/Migration.php	(revision 6437)
        +++ lib/Doctrine/Migration.php	(working copy)
        @@ -499,6 +499,9 @@
         
                     if ($migration->getNumChanges() > 0) {
                         $changes = $migration->getChanges();
        +                if ($direction == 'down') {
        +                    $changes = array_reverse($changes);
        +                }
                         foreach ($changes as $value) {
                             list($type, $change) = $value;
                             $funcName = 'process' . Doctrine_Inflector::classify($type);
        
        Show
        Jonathan H. Wage added a comment - Hmm. Would this fix the problem? I am unsure if this would cause any other problems. Index: lib/Doctrine/Migration.php =================================================================== --- lib/Doctrine/Migration.php (revision 6437) +++ lib/Doctrine/Migration.php (working copy) @@ -499,6 +499,9 @@ if ($migration->getNumChanges() > 0) { $changes = $migration->getChanges(); + if ($direction == 'down') { + $changes = array_reverse($changes); + } foreach ($changes as $value) { list($type, $change) = $value; $funcName = 'process' . Doctrine_Inflector::classify($type);
        Hide
        Ariel Arjona added a comment - - edited

        That would work but it would have to check if there's a migrate() method otherwise it would reverse regular down() methods:

        if ($direction == 'down' && method_exists($migration, 'migrate'))

        Show
        Ariel Arjona added a comment - - edited That would work but it would have to check if there's a migrate() method otherwise it would reverse regular down() methods: if ($direction == 'down' && method_exists($migration, 'migrate'))

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Ariel Arjona
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: