<?php

use Phinx\Db\Adapter\MysqlAdapter;
use think\migration\Migrator;

class CreateProductCategory extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('product_category', ['engine' => 'InnoDB', 'comment' => '商品分类表']);
        $table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID'])
            ->addColumn('unique_id', 'string', ['limit' => 64, 'null' => false, 'comment' => '唯一ID'])
            ->addColumn('pid', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'comment' => '父级ID'])
            ->addColumn('path', 'string', ['limit' => 128, 'null' => true, 'default' => null, 'comment' => '层级路径'])
            ->addColumn('name', 'string', ['limit' => 64, 'null' => false, 'comment' => '分类名称'])
            ->addColumn('icon', 'string', ['limit' => 125, 'default' => null, 'comment' => '图标'])
            ->addColumn('desc', 'string', ['limit' => 255, 'default' => null, 'comment' => '描述信息'])
            ->addColumn('related_tco_category', 'string', ['limit' => 64, 'default' => null, 'comment' => '关联 tco(产品目录) 商品分类ID,多个用英文逗号分隔'])
            ->addColumn('sort', 'integer', ['null' => false, 'default' => 0, 'comment' => '排序'])
            ->addColumn('level', 'integer', ['limit' => MysqlAdapter::INT_TINY,'null' => false, 'default' => 1, 'comment' => '层级'])
            ->addColumn('is_show', 'boolean', ['null' => false, 'default' => 1, 'comment' => '是否显示:1是,0否'])
            ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '新增时间'])
            ->addColumn('updated_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间'])
            ->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间'])
            ->create();
    }
}
