<?php

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

class UserData 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', ['engine' => 'InnoDB', 'collation' => 'utf8_general_ci', 'comment' => '用户表' ,'id' => 'uid','signed' => true ,'primary_key' => ['uid']]);
        $table->addColumn('username', 'string', ['limit' => 15,'null' => false,'default' => '','signed' => true,'comment' => '用户名',])
			->addColumn('nickname', 'string', ['limit' => 255,'null' => false,'default' => null,'signed' => true,'comment' => '姓名',])
			->addColumn('password', 'string', ['limit' => 255,'null' => false,'default' => null,'signed' => true,'comment' => '用户密码',])
			->addColumn('email', 'string', ['limit' => 100,'null' => true,'signed' => true,'comment' => '邮箱 登录',])
			->addColumn('avatar', 'string', ['limit' => 255,'null' => true,'signed' => true,'comment' => '用户头像',])
			->addColumn('remember_token', 'string', ['limit' => 512,'null' => true,'signed' => true,'comment' => '用户token',])
			->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建人ID',])
			->addColumn('department_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '部门ID',])
			->addColumn('user_type', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '用户类型',])
			->addColumn('status', 'integer', ['default' => 1,'signed' => true,'comment' => '用户状态 1 正常 2 禁用',])
			->addColumn('last_login_ip', 'string', ['limit' => 50,'null' => false,'default' => 0,'signed' => true,'comment' => '最后登录IP',])
			->addColumn('last_login_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '最后登录时间',])
			->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
			->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
			->addColumn('delete_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '删除状态，0未删除 >0 已删除',])
            ->create();
        $table = $this->table('departments', ['engine' => 'InnoDB', 'collation' => 'utf8_general_ci', 'comment' => '部门表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('title', 'string', ['limit' => 15,'null' => false,'default' => '','signed' => true,'comment' => '部门名称',])
            ->addColumn('parent_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '父级ID',])
            ->addColumn('principal', 'string', ['limit' => 20,'null' => false,'default' => '','signed' => true,'comment' => '负责人',])
            ->addColumn('mobile', 'string', ['limit' => 20,'null' => false,'default' => '','signed' => true,'comment' => '联系电话',])
            ->addColumn('email', 'string', ['limit' => 100,'null' => false,'default' => '','signed' => true,'comment' => '联系又想',])
            ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建人ID',])
            ->addColumn('status', 'integer', ['default' => 1,'signed' => true,'comment' => '1 正常 2 停用',])
            ->addColumn('sort', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '排序字段',])
            ->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
            ->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
            ->addColumn('delete_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '删除状态，null 未删除 timestamp 已删除',])
            ->create();
        $table = $this->table('users_log', ['engine' => 'InnoDB', 'collation' => 'utf8_general_ci', 'comment' => '用户表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('uid', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => null,'signed' => false,'comment' => '用户ID',])
            ->addColumn('title', 'string', ['limit' => 100,'null' => false,'default' => '','signed' => true,'comment' => '操作名称',])
            ->addColumn('method', 'string', ['limit' => 20,'null' => false,'default' => 'POST','signed' => true,'comment' => '操作类型',])
            ->addColumn('route', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '操作路由',])
            ->addColumn('params', 'text', ['null' => false,'signed' => true,'comment' => '操作参数',])
            ->addColumn('client_ip', 'string', ['limit' => 100,'null' => false,'default' => '','signed' => true,'comment' => '客户端IP',])
            ->addColumn('browser', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '浏览器',])
            ->addColumn('code', 'string', ['limit' => 20,'null' => false,'default' => null,'signed' => true,'comment' => '状态码',])
            ->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
            ->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
            ->addColumn('delete_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '删除状态，0未删除 >0 已删除',])
            ->create();
        $table = $this->table('jobs', ['engine' => 'InnoDB', 'collation' => 'utf8_general_ci', 'comment' => '岗位表' ,'id' => 'id','signed' => true ,'primary_key' => ['id']]);
        $table->addColumn('job_name', 'string', ['limit' => 15,'null' => false,'default' => '','signed' => true,'comment' => '岗位名称',])
            ->addColumn('coding', 'string', ['limit' => 50,'null' => false,'default' => '','signed' => true,'comment' => '编码',])
            ->addColumn('creator_id', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '创建人ID',])
            ->addColumn('status', 'integer', ['default' => 1,'signed' => true,'comment' => '1 正常 2 停用',])
            ->addColumn('sort', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '排序字段',])
            ->addColumn('description', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '描述',])
            ->addColumn('create_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '创建时间',])
            ->addColumn('update_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '更新时间',])
            ->addColumn('delete_time', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => false,'comment' => '删除状态，null 未删除 timestamp 已删除',])
            ->create();

    }
}
