<?php

use yii\db\Migration;

class m170523_070338_product_category extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%product_category}}', [
            'id' => 'int(10) unsigned NOT NULL AUTO_INCREMENT',
            '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('{{%product_category}}',['id'=>'1','name'=>'产品分类1','ordid'=>'0','display'=>'1']);
        $this->insert('{{%product_category}}',['id'=>'2','name'=>'产品分类2','ordid'=>'0','display'=>'1']);
        $this->insert('{{%product_category}}',['id'=>'3','name'=>'产品分类3','ordid'=>'0','display'=>'1']);
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

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

