Doctrine 1
  1. Doctrine 1
  2. DC-558

CLONE -generate-migrations-diff is producing bogus migrations (drops the whole database)

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.0, 1.2.1
    • Fix Version/s: 1.2.3
    • Component/s: Migrations
    • Labels:
      None
    • Environment:
      Vanilla sandbox on version 1.2.1 and 1.2.0
      both sqlite and mysql, so its not driver dependant

      Description

      Replicating the bug:
      1. unzip vanilla sandbox.
      2. create schema file with entity
      3. run ./doctrine build-all
      4. modify schema, add column to entity.
      5. run ./doctrine generate-migrations-diff

      Expected behaviour:
      generates migration wich adds column to entity.

      Real behaviour:
      Drops entity from database

      Similar issue:
      http://groups.google.com/group/doctrine-user/browse_thread/thread/8b4a0fc0778a388a/79446784623b8497?lnk=gst&q=1.2.1+migration

        Activity

        Hide
        Kyle Spraggs added a comment -

        This issue is NOT fixed for certain configurations of Doctrine (namely PEAR).

        See http://www.doctrine-project.org/jira/browse/DC-475

        Show
        Kyle Spraggs added a comment - This issue is NOT fixed for certain configurations of Doctrine (namely PEAR). See http://www.doctrine-project.org/jira/browse/DC-475
        Hide
        Martin Shopland added a comment - - edited

        I agree, this is an issue still in 1.2.2.

        The problem seems to be to do with the model class name prefix, it manifests itself in Doctrine_Migration_Diff on line 190. The keys of two arrays are compared to see what needs to be changed:

        Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
        $from = array (
            'Model_CaseStudy' => array(...),
            'Model_Event' => array(...),
            'Model_Group' => array(...)
        );
        
        $to = array(
            'CaseStudy' => array(...),
            'Event' => array(...),
            'Group' => array(...)
        );
        

        Because none of the array keys match it assumes that the $to array are all new models and so generates the migration to drop all of $from and create all of $to; as the models have the same table names, if you run the down you end up with no tables at all.

        So I think we need to inject the prefix into the $to models creation process somehow, as yet I haven't figured out an effective place to do this.

        Show
        Martin Shopland added a comment - - edited I agree, this is an issue still in 1.2.2. The problem seems to be to do with the model class name prefix, it manifests itself in Doctrine_Migration_Diff on line 190. The keys of two arrays are compared to see what needs to be changed: Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml $from = array ( 'Model_CaseStudy' => array(...), 'Model_Event' => array(...), 'Model_Group' => array(...) ); $to = array( 'CaseStudy' => array(...), 'Event' => array(...), 'Group' => array(...) ); Because none of the array keys match it assumes that the $to array are all new models and so generates the migration to drop all of $from and create all of $to; as the models have the same table names, if you run the down you end up with no tables at all. So I think we need to inject the prefix into the $to models creation process somehow, as yet I haven't figured out an effective place to do this.
        Hide
        Martin Shopland added a comment - - edited

        I've got it working. Not sure how robust or appropriate this fix is:

        Unable to find source-code formatter for language: diff. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
         
        diff --git a/lib/Doctrine/Core.php b/lib/Doctrine/Core.php
        index ef10b6e..2fa7a73 100644
        --- a/lib/Doctrine/Core.php
        +++ b/lib/Doctrine/Core.php
        @@ -664,7 +664,7 @@ class Doctrine_Core
                                     $className = $e[0];
                                 }
        
        -                        if ($classPrefix) {
        +                        if ($classPrefix && $classPrefix != substr($className, 0, strlen($classPrefix))) {
                                     $className = $classPrefix . $className;
                                 }
        diff --git a/lib/Doctrine/Migration/Diff.php b/lib/Doctrine/Migration/Diff.php
        index 7f00b38..4260f27 100644
        --- a/lib/Doctrine/Migration/Diff.php
        +++ b/lib/Doctrine/Migration/Diff.php
        @@ -112,7 +112,13 @@ class Doctrine_Migration_Diff
                 $this->_cleanup();
        
                 $from = $this->_generateModels(self::$_fromPrefix, $this->_from);
        -        $to = $this->_generateModels(self::$_toPrefix, $this->_to);
        +        $to = $this->_generateModels(
        +
        +            Doctrine_Manager::getInstance()->getAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX) .
        +            self::$_toPrefix,
        +
        +            $this->_to
        +        );
        
                 return $this->_diff($from, $to);
             }
        
        Show
        Martin Shopland added a comment - - edited I've got it working. Not sure how robust or appropriate this fix is: Unable to find source-code formatter for language: diff. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml diff --git a/lib/Doctrine/Core.php b/lib/Doctrine/Core.php index ef10b6e..2fa7a73 100644 --- a/lib/Doctrine/Core.php +++ b/lib/Doctrine/Core.php @@ -664,7 +664,7 @@ class Doctrine_Core $className = $e[0]; } - if ($classPrefix) { + if ($classPrefix && $classPrefix != substr($className, 0, strlen($classPrefix))) { $className = $classPrefix . $className; } diff --git a/lib/Doctrine/Migration/Diff.php b/lib/Doctrine/Migration/Diff.php index 7f00b38..4260f27 100644 --- a/lib/Doctrine/Migration/Diff.php +++ b/lib/Doctrine/Migration/Diff.php @@ -112,7 +112,13 @@ class Doctrine_Migration_Diff $ this ->_cleanup(); $from = $ this ->_generateModels(self::$_fromPrefix, $ this ->_from); - $to = $ this ->_generateModels(self::$_toPrefix, $ this ->_to); + $to = $ this ->_generateModels( + + Doctrine_Manager::getInstance()->getAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX) . + self::$_toPrefix, + + $ this ->_to + ); return $ this ->_diff($from, $to); }

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Kyle Spraggs
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: