Show
Ignore:
Timestamp:
10/19/07 23:11:45 (15 months ago)
Author:
jwage
Message:

Additions to migrations to support generating migrations from models or existing databases.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine.php

    r2939 r2941  
    827827     * Migrate database to specified $to version. Migrates from current to latest if you do not specify. 
    828828     * 
    829      * @param string $directory Directory which contains your migration classes 
     829     * @param string $migrationsPath Path to migrations directory which contains your migration classes 
    830830     * @param string $to Version you wish to migrate to. 
    831831     * @return void 
    832832     */ 
    833     public static function migrate($directory, $to = null) 
    834     { 
    835         $migration = new Doctrine_Migration($directory); 
     833    public static function migrate($migrationsPath, $to = null) 
     834    { 
     835        $migration = new Doctrine_Migration($migrationsPath); 
    836836         
    837837        return $migration->migrate($to); 
     
    844844     * 
    845845     * @param string $className Name of the Migration class to generate 
    846      * @param string $directory Directory which contains your migration classes 
     846     * @param string $migrationsPath Path to directory which contains your migration classes 
    847847     * @package default 
    848848     */ 
    849     public static function generateMigrationClass($className, $directory) 
    850     { 
    851         $migration = new Doctrine_Migration($directory); 
    852         $next = (string) $migration->getNextVersion(); 
    853          
    854         $fileName = str_repeat('0', (3 - strlen($next))) . $next . '_' . self::tableize($className) . '.class.php'; 
    855         $path = $directory . DIRECTORY_SEPARATOR . $fileName; 
    856          
    857         $code  = '<?php' . PHP_EOL; 
    858         $code .= "// Automatically generated by the Doctrine ORM Framework\n"; 
    859         $code .= "class " . self::classify($className) . " extends Doctrine_Migration\n"; 
    860         $code .= "{\n"; 
    861         $code .= "\tpublic function up()\n\t{ }\n\n"; 
    862         $code .= "\tpublic function down()\n\t{ }\n"; 
    863         $code .= "}"; 
    864          
    865         file_put_contents($path, $code); 
     849    public static function generateMigrationClass($className, $migrationsPath) 
     850    { 
     851        $builder = new Doctrine_Migration_Builder($migrationsPath); 
     852         
     853        return $builder->generateMigrationClass($className); 
     854    } 
     855     
     856    /** 
     857     * generateMigrationsFromDb 
     858     * 
     859     * @param string $migrationsPath  
     860     * @return void 
     861     */ 
     862    public function generateMigrationsFromDb($migrationsPath) 
     863    { 
     864        $builder = new Doctrine_Migration_Builder($migrationsPath); 
     865         
     866        return $builder->generateMigrationsFromDb(); 
     867    } 
     868     
     869    /** 
     870     * generateMigrationsFromModels 
     871     * 
     872     * @param string $migrationsPath  
     873     * @param string $modelsPath  
     874     * @return void 
     875     */ 
     876    public function generateMigrationsFromModels($migrationsPath, $modelsPath = null) 
     877    { 
     878        $builder = new Doctrine_Migration_Builder($migrationsPath); 
     879         
     880        return $builder->generateMigrationsFromModels($modelsPath); 
     881    } 
     882     
     883    /** 
     884     * getTable 
     885     * 
     886     * @param string $tableName  
     887     * @return void 
     888     */ 
     889    public function getTable($tableName) 
     890    { 
     891        return Doctrine_Manager::table($tableName); 
     892    } 
     893     
     894    /** 
     895     * connection 
     896     * 
     897     * @param string $adapter  
     898     * @param string $name  
     899     * @return void 
     900     */ 
     901    public function connection($adapter, $name = null) 
     902    { 
     903        return Doctrine_Manager::connection($adapter, $name); 
    866904    } 
    867905