Changeset 3923

Show
Ignore:
Timestamp:
03/02/08 05:59:03 (16 months ago)
Author:
jwage
Message:

Enhancing migrations and schema files chapters.

Location:
branches/0.10/manual/docs/en
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/0.10/manual/docs/en/migration.txt

    r3921 r3923  
    6262public function dropTable($tableName) 
    6363public function renameTable($oldTableName, $newTableName) 
     64public function createConstraint($tableName, $constraintName, array $definition) 
     65public function dropConstraint($tableName, $constraintName, $primary = false) 
     66public function createForeignKey($tableName, array $definition) 
     67public function dropForeignKey($tableName, $fkName) 
    6468public function addColumn($tableName, $columnName, $type, array $options = array()) 
    6569public function renameColumn($tableName, $oldColumnName, $newColumnName) 
     
    7276+++ Altering Data 
    7377 
    74 You can alter table directly in your up() and down() methods like you normally would by creating new model instances and calling save() or creating queries and deleting data. 
     78Sometimes you may need to alter the data in the database with your models. Since you may create a table  
     79or make a change, you have to do the data altering after the up() or down() method is processed. We have  
     80hooks in place for this named preUp(), postUp(), preDown(), and postDown(). Define these methods and  
     81they will be triggered after the migration version is executed. 
    7582 
    7683<code type="php"> 
     
    8087    public function up() 
    8188    { 
    82         // Add new user 
    83         $user = new User(); 
    84         $user->loginname = 'jwage'; 
    85         $user->save(); 
     89        $this->createTable('migration_test', array('field1' => array('type' => 'string'))); 
    8690    } 
    8791     
     92    public function postUp() 
     93    { 
     94      $migrationTest = new MigrationTest(); 
     95      $migrationTest->field1 = 'test'; 
     96      $migrationTest->save(); 
     97    } 
     98 
    8899    public function down() 
    89100    { 
    90         // Delete the user we added in the up 
    91         $query = new Doctrine_Query(); 
    92         $query->delete('User')->from('User u')->where('u.loginname = ?', 'jwage')->execute(); 
    93          
     101        $this->dropTable('migration_test'); 
     102    } 
     103     
     104    public function postDown() 
     105    { 
     106        $migrationTest = Doctrine::getTable('MigrationTest')->findOneByField1('test'); 
     107        $migrationTest->delete(); 
    94108    } 
    95109} 
     
    107121echo $migration->getCurrentVersion(); // 0 
    108122</code> 
     123 
     124 
     125This functionality is allow allowed from the Doctrine command line interface. 
  • branches/0.10/manual/docs/en/schema-files.txt

    r3922 r3923  
    1414defaults. Below is an example of schema taking advantage of all the shorthand features. 
    1515 
    16 <code type="php"> 
     16<code type="yaml"> 
    1717--- 
    1818detect_relations: true 
     
    3737Here is the none short hand form of the above schema. 
    3838 
    39 <code type="php"> 
     39<code type="yaml"> 
    4040--- 
    4141detect_relations: true