From a2bc492aee6c10cbe123094aed033ac0f55dbb7b Mon Sep 17 00:00:00 2001 From: kteraguchi Date: Thu, 28 Jul 2016 16:23:26 +0900 Subject: [PATCH] Add index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $connectionプロパティも追加された --- Config/Migration/1469689386_add_index.php | 69 +++++++++++++++++++++++ Config/Schema/schema.php | 12 +++- 2 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 Config/Migration/1469689386_add_index.php diff --git a/Config/Migration/1469689386_add_index.php b/Config/Migration/1469689386_add_index.php new file mode 100644 index 0000000..694ffcb --- /dev/null +++ b/Config/Migration/1469689386_add_index.php @@ -0,0 +1,69 @@ + array( + 'alter_field' => array( + 'tags_contents' => array( + 'model' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + ), + ), + 'create_field' => array( + 'tags_contents' => array( + 'indexes' => array( + 'model' => array('column' => array('model', 'content_id'), 'unique' => 0), + ), + ), + ), + ), + 'down' => array( + 'alter_field' => array( + 'tags_contents' => array( + 'model' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + ), + ), + 'drop_field' => array( + 'tags_contents' => array('indexes' => array('model')), + ), + ), + ); + +/** + * 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) { + return true; + } +} diff --git a/Config/Schema/schema.php b/Config/Schema/schema.php index 320c60a..6f1c184 100644 --- a/Config/Schema/schema.php +++ b/Config/Schema/schema.php @@ -8,6 +8,13 @@ */ class TagsSchema extends CakeSchema { +/** + * Database connection + * + * @var string + */ + public $connection = 'master'; + /** * before * @@ -52,7 +59,7 @@ public function after($event = array()) { */ public $tags_contents = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'), - 'model' => array('type' => 'string', 'null' => false, 'default' => null, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), + 'model' => array('type' => 'string', 'null' => false, 'default' => null, 'key' => 'index', 'collate' => 'utf8_general_ci', 'charset' => 'utf8'), 'content_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 45, 'unsigned' => false), 'tag_id' => array('type' => 'integer', 'null' => false, 'default' => null, 'length' => 45, 'unsigned' => false), 'created_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => 'created user | 作成者 | users.id | '), @@ -60,7 +67,8 @@ public function after($event = array()) { 'modified_user' => array('type' => 'integer', 'null' => true, 'default' => null, 'unsigned' => false, 'comment' => 'modified user | 更新者 | users.id | '), 'modified' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'modified datetime | 更新日時 | | '), 'indexes' => array( - 'PRIMARY' => array('column' => 'id', 'unique' => 1) + 'PRIMARY' => array('column' => 'id', 'unique' => 1), + 'model' => array('column' => array('model', 'content_id'), 'unique' => 0) ), 'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'InnoDB') );