You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
1.9 KiB
97 lines
1.9 KiB
<?php |
|
|
|
return |
|
$code = <<<CODE |
|
<?php |
|
|
|
use yii\db\Migration; |
|
|
|
/** |
|
* Handles the creation of table `post_tag`. |
|
* Has foreign keys to the tables: |
|
* |
|
* - `post` |
|
* - `tag` |
|
*/ |
|
class {$class} extends Migration |
|
{ |
|
/** |
|
* @inheritdoc |
|
*/ |
|
public function up() |
|
{ |
|
\$this->createTable('post_tag', [ |
|
'post_id' => \$this->integer(), |
|
'tag_id' => \$this->integer(), |
|
'PRIMARY KEY(post_id, tag_id)', |
|
]); |
|
|
|
// creates index for column `post_id` |
|
\$this->createIndex( |
|
'idx-post_tag-post_id', |
|
'post_tag', |
|
'post_id' |
|
); |
|
|
|
// add foreign key for table `post` |
|
\$this->addForeignKey( |
|
'fk-post_tag-post_id', |
|
'post_tag', |
|
'post_id', |
|
'post', |
|
'id', |
|
'CASCADE' |
|
); |
|
|
|
// creates index for column `tag_id` |
|
\$this->createIndex( |
|
'idx-post_tag-tag_id', |
|
'post_tag', |
|
'tag_id' |
|
); |
|
|
|
// add foreign key for table `tag` |
|
\$this->addForeignKey( |
|
'fk-post_tag-tag_id', |
|
'post_tag', |
|
'tag_id', |
|
'tag', |
|
'id', |
|
'CASCADE' |
|
); |
|
} |
|
|
|
/** |
|
* @inheritdoc |
|
*/ |
|
public function down() |
|
{ |
|
// drops foreign key for table `post` |
|
\$this->dropForeignKey( |
|
'fk-post_tag-post_id', |
|
'post_tag' |
|
); |
|
|
|
// drops index for column `post_id` |
|
\$this->dropIndex( |
|
'idx-post_tag-post_id', |
|
'post_tag' |
|
); |
|
|
|
// drops foreign key for table `tag` |
|
\$this->dropForeignKey( |
|
'fk-post_tag-tag_id', |
|
'post_tag' |
|
); |
|
|
|
// drops index for column `tag_id` |
|
\$this->dropIndex( |
|
'idx-post_tag-tag_id', |
|
'post_tag' |
|
); |
|
|
|
\$this->dropTable('post_tag'); |
|
} |
|
} |
|
|
|
CODE;
|
|
|