10.04.2018 Views

Doctrine_manual-1-2-en

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 24: Migrations 330<br />

$migration = new <strong>Doctrine</strong>_Migration('migrations');<br />

$migration->migrate(0);<br />

Now run the migrate.php script:<br />

Listing<br />

24-13<br />

$ php migrate.php<br />

If you look in the database now, everything we did in the up() methods has be<strong>en</strong> reversed by<br />

the cont<strong>en</strong>ts of the down() method.<br />

Available Operations<br />

Here is a list of the available methods you can use to alter your database in your migration<br />

classes.<br />

Create Table<br />

Listing<br />

24-14<br />

// ...<br />

public function up()<br />

{<br />

$columns = array(<br />

'id' => array(<br />

'type' => 'integer',<br />

'unsigned' => 1<br />

'notnull' => 1<br />

'default' => 0<br />

),<br />

'name' => array(<br />

'type' => 'string',<br />

'l<strong>en</strong>gth' => 12<br />

),<br />

'password' => array(<br />

'type' => 'string',<br />

'l<strong>en</strong>gth' => 12<br />

)<br />

);<br />

$options = array(<br />

'type' => 'INNODB',<br />

'charset' => 'utf8'<br />

);<br />

}<br />

// ...<br />

$this->createTable('table_name', $columns, $options);<br />

You might notice already that the data structures used to manipulate the your schema are<br />

the same as the data structures used with the database abstraction layer. This is because<br />

internally the migration package uses the database abstraction layer to perform the<br />

operations specified in the migration classes.<br />

Drop Table<br />

Listing<br />

24-15<br />

// ...<br />

public function down()<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!