Created
December 8, 2010 20:02
-
-
Save bartimaeus/733811 to your computer and use it in GitHub Desktop.
Example of a CakePHP Migration that changes the database schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Eric Shelley <[email protected]> | |
*/ | |
class M20101208130030 extends CakeMigration | |
{ | |
/** | |
* Migration description | |
* | |
* @var string | |
* @access public | |
*/ | |
public $description = 'Rename inventories added_on and added_by fields to created standard'; | |
/** | |
* Before migration callback | |
* | |
* @param string $direction, up or down direction of migration process | |
* @return boolean Should process continue | |
* @access public | |
*/ | |
public function before($direction) | |
{ | |
switch ($direction) { | |
case 'up': | |
echo "Going up...\n"; | |
$Inventory = $this->generateModel('Inventory'); | |
$Inventory->query(<<<PGSQL | |
ALTER TABLE inventories RENAME COLUMN added_by TO created_by; | |
ALTER TABLE inventories RENAME COLUMN added_on TO created; | |
PGSQL | |
); | |
echo "\nCompleted successfully\n\n"; | |
break; | |
case 'down': | |
// No down b/c I'm correcting data | |
break; | |
} | |
return true; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment