Development

Changeset 21782

You must first sign up to be able to contribute.

Changeset 21782

Show
Ignore:
Timestamp:
09/08/09 14:49:32 (4 years ago)
Author:
Kris.Wallsmith
Message:

[sfPropelMigrationsLightPlugin] made less mysql-specific (thanks Jérôme Texier)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelMigrationsLightPlugin/trunk/lib/sfMigrator.class.php

    r10225 r21782  
    44 * This file is part of the sfPropelMigrationsLightPlugin package. 
    55 * (c) 2006-2008 Martin Kreidenweis <sf@kreidenweis.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    1111/** 
    1212 * Manage all calls to the sfMigration class instances. 
    13  *  
     13 * 
    1414 * @package    symfony 
    1515 * @subpackage plugin 
     
    2121  /** 
    2222   * Migration filenames. 
    23    *  
     23   * 
    2424   * @var array $migrations 
    2525   */ 
     
    2828  /** 
    2929   * Perform an update on the database. 
    30    *  
     30   * 
    3131   * @param   string $sql 
    32    *  
     32   * 
    3333   * @return  integer 
    3434   */ 
     
    4242  /** 
    4343   * Perform a query on the database. 
    44    *  
     44   * 
    4545   * @param   string $sql 
    4646   * @param   string $fetchmode 
    47    *  
     47   * 
    4848   * @return  mixed 
    4949   */ 
     
    5151  { 
    5252    $con = Propel::getConnection(); 
    53      
     53 
    5454    if ($con instanceof PropelPDO) 
    5555    { 
     
    7575  /** 
    7676   * Execute migrations. 
    77    *  
    78    * @param   integer $destVersion  Version number to migrate to, defaults to  
     77   * 
     78   * @param   integer $destVersion  Version number to migrate to, defaults to 
    7979   *                                the max existing 
    80    *  
     80   * 
    8181   * @return  integer Number of executed migrations 
    8282   */ 
     
    119119  /** 
    120120   * Generate a new migration stub 
    121    *  
     121   * 
    122122   * @param   string $name Name of the new migration 
    123    *  
     123   * 
    124124   * @return  string Filename of the new migration file 
    125125   */ 
    126   public function generateMigration($name)  
     126  public function generateMigration($name) 
    127127  { 
    128128    // calculate version number for new migration 
     
    177177  /** 
    178178   * Get the list of migration filenames. 
    179    *  
     179   * 
    180180   * @return array 
    181181   */ 
     
    188188   * @return integer The lowest migration that exists 
    189189   */ 
    190   public function getMinVersion()  
     190  public function getMinVersion() 
    191191  { 
    192192    return $this->migrations ? $this->getMigrationNumberFromFile($this->migrations[0]) : 0; 
     
    205205  /** 
    206206   * Get the current schema version from the database. 
    207    *  
    208    * If no schema version is currently stored in the database, one is created  
     207   * 
     208   * If no schema version is currently stored in the database, one is created 
    209209   * and initialized with 0. 
    210210   * 
    211211   * @return integer 
    212212   */ 
    213   public function getCurrentVersion()  
    214   { 
    215     // check if schema_info table exists 
    216     $result = $this->executeQuery('SHOW TABLES LIKE "schema_info"'); 
    217  
    218     if ($result instanceof PDOStatement ? $result->rowCount() : $result->getRecordCount()) 
     213  public function getCurrentVersion() 
     214  { 
     215    try 
    219216    { 
    220217      $result = $this->executeQuery('SELECT version FROM schema_info'); 
    221  
    222218      if ($result instanceof PDOStatement) 
    223219      { 
     
    228224        if ($result->next()) 
    229225        { 
    230           $currentVersion = $result->getInt("version"); 
     226          $currentVersion = $result->getInt('version'); 
    231227        } 
    232228        else 
     
    236232      } 
    237233    } 
    238     else 
    239     { 
    240       // no schema_info table exists yet so we create it 
    241       $this->executeUpdate('CREATE TABLE schema_info (version INTEGER UNSIGNED)'); 
     234    catch (Exception $e) 
     235    { 
     236      // assume no schema_info table exists yet so we create it 
     237      $this->executeUpdate('CREATE TABLE schema_info (version INTEGER)'); 
    242238 
    243239      // and insert the version record as 0 
    244       $this->executeUpdate('INSERT INTO schema_info SET version = 0'); 
     240      $this->executeUpdate('INSERT INTO schema_info (version) VALUES (0)'); 
    245241      $currentVersion = 0; 
    246242    } 
     
    248244    return $currentVersion; 
    249245  } 
    250    
     246 
    251247  /** 
    252248   * Get the number encoded in the given migration file name. 
    253    *  
     249   * 
    254250   * @param   string $file The filename to look at 
    255    *  
     251   * 
    256252   * @return  integer 
    257253   */ 
    258   public function getMigrationNumberFromFile($file)  
     254  public function getMigrationNumberFromFile($file) 
    259255  { 
    260256    $number = substr(basename($file), 0, 3); 
     
    270266  /** 
    271267   * Get the directory where migration classes are saved. 
    272    *  
     268   * 
    273269   * @return  string 
    274270   */ 
    275   public function getMigrationsDir()  
     271  public function getMigrationsDir() 
    276272  { 
    277273    return sfConfig::get('sf_data_dir').DIRECTORY_SEPARATOR.'migrations'; 
     
    280276  /** 
    281277   * Get the directory where migration fixtures are saved. 
    282    *  
     278   * 
    283279   * @return  string 
    284280   */ 
     
    290286  /** 
    291287   * Write the given version as current version to the database. 
    292    *  
     288   * 
    293289   * @param integer $version New current version 
    294290   */ 
     
    302298  /** 
    303299   * Migrate down, from version $from to version $to. 
    304    *  
     300   * 
    305301   * @param   integer $from 
    306302   * @param   integer $to 
    307    *  
     303   * 
    308304   * @return  integer Number of executed migrations 
    309305   */ 
     
    341337  /** 
    342338   * Migrate up, from version $from to version $to. 
    343    *  
     339   * 
    344340   * @param   integer $from 
    345341   * @param   integer $to 
     
    379375  /** 
    380376   * Get the migration object for the given version. 
    381    *  
     377   * 
    382378   * @param   integer $version 
    383    *  
     379   * 
    384380   * @return  sfMigration 
    385381   */ 
     
    399395   * 
    400396   * @param   integer $version 
    401    *  
     397   * 
    402398   * @return  string Filename 
    403399   */ 
     
    421417      $maxVersion = $this->getMaxVersion(); 
    422418 
    423       if (1 != $minVersion)  
     419      if (1 != $minVersion) 
    424420      { 
    425421        throw new sfInitializationException('First migration is not migration 1. Some migration files may be missing.'); 
     
    432428    } 
    433429  } 
    434    
     430 
    435431  /** 
    436432   * Auto generate logic for the first migration. 
    437    *  
     433   * 
    438434   * @param   string $name 
    439435   * @param   string $newVersion