'use strict'; /** * 对外回调日志表(外部系统 → OMS 的 POST /openapi 请求与返回) * 与 api_outbound_logs(OMS → 外部)方向相反,覆盖回调链路的排查 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( 'callback_logs', { id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true, }, principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '所属主体ID(app_key 未定位到时为空)' }, warehouse_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '关联仓库ID(app_key 未定位到时为空)' }, warehouse_api_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: true, comment: '命中的仓库接口配置ID' }, method: { type: Sequelize.STRING(100), allowNull: false, defaultValue: '', comment: '回调方法名,如 index.ping / entryorder.confirm' }, app_key: { type: Sequelize.STRING(100), allowNull: true, comment: '请求携带的 app_key' }, ip: { type: Sequelize.STRING(64), allowNull: true, comment: '调用方 IP' }, http_status: { type: Sequelize.INTEGER, allowNull: true, comment: '响应 HTTP 状态码' }, flag: { type: Sequelize.STRING(20), allowNull: true, comment: '结果标记:success / failure' }, business_code: { type: Sequelize.STRING(32), allowNull: true, comment: '业务码(成功1,失败见 code)' }, message: { type: Sequelize.STRING(500), allowNull: true, comment: '提示信息 / 失败原因' }, request_query: { type: Sequelize.TEXT, allowNull: true, comment: '请求 query JSON(sign 已脱敏)' }, request_body: { type: Sequelize.TEXT, allowNull: true, comment: '请求报文 JSON(敏感字段已脱敏,超长截断)' }, response_body: { type: Sequelize.TEXT, allowNull: true, comment: '返回报文 JSON(超长截断)' }, is_success: { type: Sequelize.TINYINT, defaultValue: 0, comment: '业务是否成功(1是 0否)' }, error: { type: Sequelize.TEXT, allowNull: true, comment: '失败信息(未注册方法 / 验签失败 / 单据处理失败等)' }, duration: { type: Sequelize.INTEGER, allowNull: true, comment: '耗时(毫秒)' }, created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), }, updated_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), }, }, { charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '对外回调日志表' } ); await queryInterface.addIndex('callback_logs', { fields: [ 'principal_id' ], name: 'idx_cb_log_principal' }); await queryInterface.addIndex('callback_logs', { fields: [ 'warehouse_id' ], name: 'idx_cb_log_warehouse' }); await queryInterface.addIndex('callback_logs', { fields: [ 'warehouse_api_id' ], name: 'idx_cb_log_api' }); await queryInterface.addIndex('callback_logs', { fields: [ 'method' ], name: 'idx_cb_log_method' }); await queryInterface.addIndex('callback_logs', { fields: [ 'created_at' ], name: 'idx_cb_log_created' }); }, async down(queryInterface) { await queryInterface.dropTable('callback_logs'); }, };