<?php

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

class CreateSysOperateLog 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_operate_log', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '操作日志表']);
        $table->addColumn('user_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '用户ID'])
            ->addColumn('title', 'string', ['limit' => 50, 'default' => '', 'comment' => '标题'])
            ->addColumn('version', 'string', ['limit' => 15, 'default' => '', 'comment' => '版本'])
            ->addColumn('method', 'string', ['limit' => 10, 'default' => '', 'comment' => '请求方式'])
            ->addColumn('controller', 'string', ['limit' => 50, 'default' => '', 'comment' => '控制器'])
            ->addColumn('action', 'string', ['limit' => 50, 'default' => '', 'comment' => '方法'])
            ->addColumn('url', 'string', ['limit' => 255, 'default' => '', 'comment' => 'URL'])
            ->addColumn('ip', 'string', ['limit' => 50, 'default' => '', 'comment' => 'IP'])
            ->addColumn('params', 'text', ['comment' => '请求参数'])
            ->addColumn('status', MysqlAdapter::PHINX_TYPE_SMALL_INTEGER, ['limit' => 5, 'default' => 200, 'comment' => '状态码'])
            ->addColumn('message', MysqlAdapter::PHINX_TYPE_TEXT, ['default' => null, 'comment' => '消息'])
            ->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
            ->addIndex(['user_id'], ['name' => 'idx_user_id'])
            ->create();
    }
}
