'use strict'; /** * 创建仓库开放 API 请求日志表。 * 记录 /warehouse 入口的每次请求:app_key、method、warehouse_id、 * 请求体、响应体、HTTP 状态码、耗时等。 */ module.exports = { up: async (queryInterface, Sequelize) => { const { STRING, INTEGER, BIGINT, TEXT, DATE } = Sequelize; await queryInterface.createTable('wms_warehouse_log', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, comment: '自增主键', }, log_id: { type: STRING(32), allowNull: false, unique: true, comment: '日志唯一ID(WL-{timestamp}-{random})', }, app_key: { type: STRING(64), allowNull: true, comment: 'API 应用 AppKey', }, method: { type: STRING(100), allowNull: true, comment: '请求方法名(如 inbox.push)', }, warehouse_id: { type: INTEGER(10), allowNull: true, comment: '仓库 ID', }, url: { type: TEXT, allowNull: true, comment: '请求 URL', }, http_status: { type: INTEGER(5), allowNull: true, comment: 'HTTP 状态码', }, body: { type: TEXT('long'), allowNull: true, comment: '请求体(最大 65535 字符)', }, result: { type: TEXT('long'), allowNull: true, comment: '响应体(最大 65535 字符)', }, use_time: { type: INTEGER(12), allowNull: true, comment: '耗时(毫秒)', }, created_at: { type: DATE, allowNull: true, comment: '创建时间', }, updated_at: { type: DATE, allowNull: true, comment: '更新时间', }, }); // 索引 await queryInterface.addIndex('wms_warehouse_log', { name: 'uk_log_id', unique: true, fields: [ 'log_id' ], }); await queryInterface.addIndex('wms_warehouse_log', { name: 'idx_app_key', fields: [ 'app_key' ], }); await queryInterface.addIndex('wms_warehouse_log', { name: 'idx_method', fields: [ 'method' ], }); await queryInterface.addIndex('wms_warehouse_log', { name: 'idx_warehouse_id', fields: [ 'warehouse_id' ], }); await queryInterface.addIndex('wms_warehouse_log', { name: 'idx_created_at', fields: [ 'created_at' ], }); }, down: async queryInterface => { await queryInterface.dropTable('wms_warehouse_log'); }, };