Created
March 24, 2015 16:37
-
-
Save fleeting/a286ef72ecc1c5e1fba0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class InitialFaqsMigration extends CakeMigration { | |
/** | |
* Migration description | |
* | |
* @var string | |
*/ | |
public $description = 'initial_migration'; | |
/** | |
* Actions to be performed | |
* | |
* @var array $migration | |
*/ | |
public $migration = array( | |
'up' => array( | |
'create_table' => array( | |
'faqs' => array( | |
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => true, 'key' => 'primary'), | |
'group_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => true, 'key' => 'index'), | |
'question' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | |
'answer' => array('type' => 'text', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | |
'sort_order' => array('type' => 'integer', 'null' => false, 'default' => '0', 'length' => 11, 'unsigned' => true), | |
'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | |
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), | |
'indexes' => array( | |
'PRIMARY' => array('column' => 'id', 'unique' => 1), | |
'faqs_faq_groups' => array('column' => 'group_id', 'unique' => 0), | |
), | |
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), | |
), | |
'faq_groups' => array( | |
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => true, 'key' => 'primary'), | |
'name' => array('type' => 'string', 'null' => false, 'default' => null, 'length' => 128, 'key' => 'unique', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), | |
'created' => array('type' => 'datetime', 'null' => true, 'default' => null), | |
'modified' => array('type' => 'datetime', 'null' => true, 'default' => null), | |
'indexes' => array( | |
'PRIMARY' => array('column' => 'id', 'unique' => 1), | |
), | |
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB'), | |
), | |
), | |
), | |
'down' => array( | |
'drop_table' => array( | |
'faqs', 'faq_groups' | |
), | |
), | |
); | |
/** | |
* Before migration callback | |
* | |
* @param string $direction Direction of migration process (up or down) | |
* @return bool Should process continue | |
*/ | |
public function before($direction) { | |
return true; | |
} | |
/** | |
* After migration callback | |
* | |
* @param string $direction Direction of migration process (up or down) | |
* @return bool Should process continue | |
*/ | |
public function after($direction) { | |
if ($direction === "up") { | |
$this->db->execute("alter table faqs add constraint faqs_faq_groups foreign key (group_id) references faq_groups (id) on delete cascade on update restrict"); | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment