<?php

use yii\db\Migration;

class m170523_070338_article_category extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%article_category}}', [
            'id' => 'int(10) unsigned NOT NULL AUTO_INCREMENT',
            'pid' => 'int(10) unsigned NOT NULL',
            'name' => 'varchar(30) NOT NULL',
            'ordid' => 'int(10) unsigned NOT NULL',
            'display' => 'tinyint(1) unsigned NOT NULL',
            'PRIMARY KEY (`id`)'
        ], "ENGINE=MyISAM  DEFAULT CHARSET=utf8");
        
        /* 索引设置 */
        
        
        /* 表数据 */
        $this->insert('{{%article_category}}',['id'=>'1','pid'=>'0','name'=>'深度报道','ordid'=>'0','display'=>'1']);
        $this->insert('{{%article_category}}',['id'=>'2','pid'=>'0','name'=>'公司新闻','ordid'=>'0','display'=>'1']);
        $this->insert('{{%article_category}}',['id'=>'3','pid'=>'0','name'=>'独家策划','ordid'=>'0','display'=>'1']);
        $this->insert('{{%article_category}}',['id'=>'4','pid'=>'0','name'=>'媒体关注','ordid'=>'0','display'=>'1']);
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

    public function down()
    {
        $this->execute('SET foreign_key_checks = 0');
        /* 删除表 */
        $this->dropTable('{{%article_category}}');
        $this->execute('SET foreign_key_checks = 1;');
    }
}

