table('nginx_access_log', ['id' => false, 'primary_key' => ['id']]) ->setComment('nginx 访问日志明细(解析入库)') ->addColumn('id', 'biginteger', ['null' => false, 'signed' => false, 'identity' => true, 'comment' => '主键ID']) ->addColumn('file_path', 'string', ['limit' => 500, 'null' => false, 'comment' => '来源日志文件路径']) ->addColumn('remote_addr', 'string', ['limit' => 45, 'null' => false, 'comment' => '客户端 IP(含 IPv6)']) ->addColumn('remote_user', 'string', ['limit' => 100, 'null' => true, 'comment' => 'HTTP 认证用户名']) ->addColumn('time_local', 'integer', ['limit' => 11, 'null' => false, 'comment' => '请求时间戳(业务时区)', 'signed' => false]) ->addColumn('method', 'string', ['limit' => 10, 'null' => true, 'comment' => 'HTTP 方法']) ->addColumn('uri', 'string', ['limit' => 255, 'null' => false, 'comment' => '请求 URI(超 255 截断)']) ->addColumn('query_string', 'string', ['limit' => 500, 'null' => false, 'default' => '', 'comment' => '查询字符串']) ->addColumn('http_version', 'string', ['limit' => 10, 'null' => true, 'comment' => 'HTTP 协议版本']) ->addColumn('status', 'integer', ['limit' => 11, 'default' => 0, 'comment' => 'HTTP 状态码']) ->addColumn('body_bytes_sent', 'biginteger', ['default' => 0, 'comment' => '响应体字节数']) ->addColumn('http_referer', 'string', ['limit' => 500, 'null' => false, 'default' => '', 'comment' => 'Referer']) ->addColumn('http_user_agent', 'string', ['limit' => 500, 'null' => false, 'default' => '', 'comment' => 'User-Agent(超 500 截断)']) ->addColumn('request_time', 'decimal', ['precision' => 10, 'scale' => 3, 'default' => 0, 'comment' => 'nginx 请求总耗时(秒)']) ->addColumn('upstream_response_time', 'decimal', ['precision' => 10, 'scale' => 3, 'default' => 0, 'comment' => 'upstream 响应时间(秒)']) ->addColumn('bytes_sent', 'biginteger', ['default' => 0, 'comment' => '总发送字节数(含 header)']) ->addColumn('country', 'string', ['limit' => 50, 'null' => true, 'comment' => '国家(GeoIP 预留)']) ->addColumn('province', 'string', ['limit' => 50, 'null' => true, 'comment' => '省份(GeoIP 预留)']) ->addColumn('city', 'string', ['limit' => 50, 'null' => true, 'comment' => '城市(GeoIP 预留)']) ->addColumn('create_time', 'integer', ['limit' => 11, 'comment' => '入库时间戳', 'signed' => false]) ->addIndex(['time_local'], ['name' => 'idx_time_local']) ->addIndex(['remote_addr'], ['name' => 'idx_remote_addr']) ->addIndex(['status'], ['name' => 'idx_status']) ->addIndex(['uri'], ['name' => 'idx_uri']) ->addIndex(['file_path'], ['name' => 'idx_file_path']) ->create(); } }