db->driverName === 'mysql') { $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_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}}'); } }