| @@ 11-48 (lines=38) @@ | ||
| 8 | * @author Agiel K. Saputra <[email protected]> | |
| 9 | * @since 0.1.0 | |
| 10 | */ | |
| 11 | class m000000_000009_post_type_taxonomy extends \yii\db\Migration | |
| 12 | { | |
| 13 | /** | |
| 14 | * @inheritdoc | |
| 15 | */ | |
| 16 | public function up() | |
| 17 |     { | |
| 18 | $tableOptions = null; | |
| 19 | ||
| 20 |         if ($this->db->driverName === 'mysql') { | |
| 21 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; | |
| 22 | } | |
| 23 | ||
| 24 |         $this->createTable('{{%post_type_taxonomy}}', [ | |
| 25 | 'post_type_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', | |
| 26 | 'taxonomy_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', | |
| 27 | 'PRIMARY KEY ([[post_type_id]], [[taxonomy_id]])', | |
| 28 |             'FOREIGN KEY ([[post_type_id]]) REFERENCES {{%post_type}} ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE', | |
| 29 |             'FOREIGN KEY ([[taxonomy_id]]) REFERENCES {{%taxonomy}} ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE', | |
| 30 | ], $tableOptions); | |
| 31 | ||
| 32 | /** | |
| 33 | * The post type of "post" has category and tag | |
| 34 | */ | |
| 35 |         $this->batchInsert('{{%post_type_taxonomy}}', ['post_type_id', 'taxonomy_id'], [ | |
| 36 | [1, 1], | |
| 37 | [1, 2], | |
| 38 | ]); | |
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * @inheritdoc | |
| 43 | */ | |
| 44 | public function down() | |
| 45 |     { | |
| 46 |         $this->dropTable('{{%post_type_taxonomy}}'); | |
| 47 | } | |
| 48 | } | |
| 49 | ||
| @@ 11-48 (lines=38) @@ | ||
| 8 | * @author Agiel K. Saputra <[email protected]> | |
| 9 | * @since 0.1.0 | |
| 10 | */ | |
| 11 | class m000000_000012_term_relationship extends \yii\db\Migration | |
| 12 | { | |
| 13 | /** | |
| 14 | * @inheritdoc | |
| 15 | */ | |
| 16 | public function up() | |
| 17 |     { | |
| 18 | $tableOptions = null; | |
| 19 | ||
| 20 |         if ($this->db->driverName === 'mysql') { | |
| 21 | $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; | |
| 22 | } | |
| 23 | ||
| 24 |         $this->createTable('{{%term_relationship}}', [ | |
| 25 | 'post_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', | |
| 26 | 'term_id' => Schema::TYPE_INTEGER . '(11) NOT NULL', | |
| 27 | 'PRIMARY KEY ([[post_id]], [[term_id]])', | |
| 28 |             'FOREIGN KEY ([[post_id]]) REFERENCES {{%post}} ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE', | |
| 29 |             'FOREIGN KEY ([[term_id]]) REFERENCES {{%term}} ([[id]]) ON DELETE CASCADE ON UPDATE CASCADE', | |
| 30 | ], $tableOptions); | |
| 31 | ||
| 32 | /** | |
| 33 | * First post has post-category and post-tag | |
| 34 | */ | |
| 35 |         $this->batchInsert('{{%term_relationship}}', ['post_id', 'term_id'], [ | |
| 36 | [1, 1], | |
| 37 | [1, 2], | |
| 38 | ]); | |
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * @inheritdoc | |
| 43 | */ | |
| 44 | public function down() | |
| 45 |     { | |
| 46 |         $this->dropTable('{{%term_relationship}}'); | |
| 47 | } | |
| 48 | } | |
| 49 | ||