<?php

use yii\db\Migration;
use yii\db\Schema;

class m181104_132424_create_category extends Migration
{
    public $tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
    public function safeUp()
    {
        /**
         * 商品分类
         */
//        $this->createTable('{{%category}}', [
//            'id' => Schema::TYPE_PK,
//            'name' => Schema::TYPE_STRING . "(20) NOT NULL  COMMENT '名称'",
////            'contacts' => Schema::TYPE_STRING . "(20) NOT NULL  COMMENT '联系人'",
////            'tel' => Schema::TYPE_STRING . "(11) NOT NULL  COMMENT '联系电话'",
////            'address' => Schema::TYPE_STRING . "(200) NOT NULL  COMMENT '地址'",
////            'desc' => Schema::TYPE_STRING . "(200) NOT NULL  COMMENT '简介'",
//            'created_at' => Schema::TYPE_INTEGER . "(11) NOT NULL",
//            'updated_at' => Schema::TYPE_INTEGER . "(11) NOT NULL",
//            'status' => Schema::TYPE_SMALLINT . "(1) NOT NULL DEFAULT '1' COMMENT '状态'",
//        ], $this->tableOptions);
        /**
         *  'article' => '文章数', //冗余字段,方便查询
        'sort' => '排序',
        'module' => '支持的文档类型',
        'allow_publish' => '是否允许发布内容',
         */
        $this->dropColumn('{{%category}}', 'article');
        $this->dropColumn('{{%category}}', 'module');
        $this->dropColumn('{{%category}}', 'allow_publish');

        $moduleColumn = new \yii\db\ColumnSchemaBuilder('integer');
        $moduleColumn->notNull();
        $moduleColumn->comment('状态');
        $moduleColumn->defaultValue(1);//
        $this->addColumn('{{%category}}', 'status', $moduleColumn);



    }

    public function safeDown()
    {
//        $this->dropTable('{{%category}}');
        return false;
    }
    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m181104_132424_create_category cannot be reverted.\n";

        return false;
    }
    */
}
