Yii2 framework backup
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.
 
 
 
 
 

101 lines
2.2 KiB

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
return <<<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 safeUp()
{
\$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 safeDown()
{
// 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;