<?php

use think\migration\Migrator;
use think\migration\db\Column;

class Users 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('users', array('engine' => 'Innodb', 'comment' => '用户表', 'signed' => false));
        $table->addColumn('username', 'string', array('null' => true, 'limit'  =>  20, 'default' => '', 'comment' => '用户名'))
            ->addColumn('password', 'string', array('null' => true, 'limit'  =>  255, 'comment' => '用户密码'))
            ->addColumn('sex', 'integer', ['null' => true, 'default' => 0, 'comment' => '性别'])
            ->addColumn('email', 'string', array('null' => true, 'limit'  =>  100, 'comment' => '邮箱 登录'))
            ->addColumn('idcard', 'string', array('null' => true, 'limit'  =>  20, 'comment' => '身份证'))
            ->addColumn('user_no', 'string', array('null' => true, 'limit'  =>  20, 'comment' => '用户编号'))
            ->addColumn('department_id', 'integer', ['null' => true, 'default' => 0, 'comment' => '部门ID'])
            ->addColumn('status', 'boolean', array('null' => true, 'limit'  =>  1, 'default' => 1, 'comment' => '用户状态 1 正常 2 禁用'))
            ->addColumn('last_login_ip', 'string', array('null' => true, 'limit' => 50, 'default' => 0, 'comment' => '最后登录IP'))
            ->addColumn('last_login_time', 'integer', array('null' => true, 'default' => 0, 'comment' => '最后登录时间', 'signed' => false))
            ->addColumn('wxmp_open_id', 'string', ['limit' => '30', 'null' => true, 'signed' => true, 'comment' => '微信小程序openid',])
            ->addColumn('wx_open_id', 'string', ['limit' => '30', 'null' => true, 'signed' => true, 'comment' => '微信公众号openid',])
            ->addColumn('wx_union_id', 'string', ['limit' => '50', 'null' => true, 'signed' => true, 'comment' => '微信unionid',])
            ->addColumn('phone', 'string', ['null' => true, 'limit' => '20', 'null' => true, 'signed' => true, 'comment' => '手机号',])
            ->addColumn('remember_token', 'string', ['limit' => 512, 'default' => '', 'null' => true, 'comment' => '用户token'])
            ->addColumn('realname', 'string', ['null' => true, 'default' => '', 'comment' => '姓名', 'limit' => 20])
            ->addColumn('equ_password', 'string', array('null' => true, 'limit'  =>  255, 'comment' => '设备密码'))
            ->addColumn('avatar', 'string', ['limit' => 255, 'null' => true, 'default' => '', 'comment' => '用户头像', 'after' => 'email'])
            ->addColumn('creator_id', 'integer', ['null' => true, 'default' => 0, 'comment' => '创建人ID'])
            ->addColumn('created_at', 'integer', array('null' => true, 'default' => 0, 'comment' => '创建时间', 'signed' => false))
            ->addColumn('updated_at', 'integer', array('null' => true, 'default' => 0, 'comment' => '更新时间', 'signed' => false))
            ->addColumn('deleted_at', 'integer', array('null' => true, 'default' => 0, 'comment' => '删除状态,0未删除 >0 已删除', 'signed' => false))
            ->create();
    }
}