<?php

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

class CreateSysUserLoginLog 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('sys_user_login_log', ['engine' => 'MyISAM', 'comment' => '系统用户登录日志表']);
        $table->addColumn('user_id', 'integer', ['null' => false, 'comment' => '用户ID'])
            ->addColumn('ip', 'integer', ['limit' => 11, 'signed' => false, 'null' => false, 'comment' => '登录IP'])
            ->addColumn('user_agent', 'string', ['limit' => 1024, 'null' => true, 'default' => null, 'comment' => '登录设备UA信息'])
            ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
            ->create();
    }
}
