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.
55 lines
1.7 KiB
55 lines
1.7 KiB
<?php |
|
|
|
use yii\db\Migration; |
|
|
|
/** |
|
* Handles the creation of table `menu_items`. |
|
*/ |
|
class m180709_202659_create_menu_items_table extends Migration |
|
{ |
|
/** |
|
* {@inheritdoc} |
|
*/ |
|
public function safeUp() |
|
{ |
|
$tableOptions = null; |
|
if ($this->db->driverName === 'mysql') { |
|
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; |
|
} |
|
|
|
$this->createTable('{{%menu_items}}', [ |
|
'id' => $this->primaryKey(), |
|
'menu_id' => $this->integer()->notNull(), |
|
'parent_id' => $this->integer(), |
|
'name' => $this->string(255)->notNull(), |
|
'title_attr' => $this->string(255), |
|
'target' => $this->string(20), |
|
'css' => $this->string(255), |
|
'style' => $this->string(255), |
|
'module' => $this->string(255), |
|
'url' => $this->string(255), |
|
'url_params' => $this->text(), // json id=>1, ... |
|
'sort' => $this->integer()->notNull()->defaultValue(1), |
|
], $tableOptions); |
|
|
|
$this->createIndex('idx_menu_item_sort', '{{%menu_items}}', ['menu_id', 'sort']); |
|
$this->createIndex('idx_menu_items_menu_id', '{{%menu_items}}', 'menu_id'); |
|
$this->createIndex('idx_menu_items_parent_id', '{{%menu_items}}', 'parent_id'); |
|
|
|
$this->addForeignKey('frg_menu_items_menu_id', '{{%menu_items}}', 'menu_id', '{{%menu}}', 'id', 'CASCADE'); |
|
} |
|
|
|
/** |
|
* {@inheritdoc} |
|
*/ |
|
public function safeDown() |
|
{ |
|
$this->dropForeignKey('frg_menu_items_menu_id', '{{%menu_items}}'); |
|
|
|
$this->dropIndex('idx_menu_items_parent_id', '{{%menu_items}}'); |
|
$this->dropIndex('idx_menu_items_menu_id', '{{%menu_items}}'); |
|
$this->dropIndex('idx_menu_item_sort', '{{%menu_items}}'); |
|
|
|
$this->dropTable('{{%menu_items}}'); |
|
} |
|
}
|
|
|