Skip to content

Commit

Permalink
Add index
Browse files Browse the repository at this point in the history
$connectionプロパティも追加された
  • Loading branch information
kteraguchi committed Jul 28, 2016
1 parent cf5f479 commit a2bc492
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
69 changes: 69 additions & 0 deletions Config/Migration/1469689386_add_index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* AddIndex
*/

/**
* Class AddIndex
*/
class AddIndex extends CakeMigration {

/**
* Migration description
*
* @var string
*/
public $description = 'add_index';

/**
* Actions to be performed
*
* @var array $migration
*/
public $migration = array(
'up' => 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;
}
}
12 changes: 10 additions & 2 deletions Config/Schema/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
*/
class TagsSchema extends CakeSchema {

/**
* Database connection
*
* @var string
*/
public $connection = 'master';

/**
* before
*
Expand Down Expand Up @@ -52,15 +59,16 @@ 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 | '),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null, 'comment' => 'created datetime | 作成日時 | | '),
'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')
);
Expand Down

0 comments on commit a2bc492

Please sign in to comment.