'use strict'; /** * 创建客户端错误日志暂存表 wms_client_error_log。 * * 背景:Android/iOS/Web 等设备端将运行时错误日志上报到服务端暂存, * 供人工/后台查询分析跟踪 bug。接口入口 index.uploadClientErrorLog * (免登录、免权限、免鉴权,保留系统日志)。 * * 字段:客户端类型/版本、设备标识、系统版本/型号、错误类型、错误信息与堆栈、 * 附加上下文 extra、report_uuid(客户端生成,唯一索引幂等去重)、 * client_time(客户端发生时间,仅参考)、created_at(服务端写入时间)。 * * 索引:idx_created_at、idx_client_type_app_version、idx_device_id、uk_report_uuid(唯一)。 */ const TABLE_NAME = 'wms_client_error_log'; module.exports = { // eslint-disable-next-line no-unused-vars async up(queryInterface, Sequelize) { const { BIGINT, STRING, DATE, TEXT } = Sequelize; await queryInterface.createTable(TABLE_NAME, { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, allowNull: false, comment: '主键ID', }, client_type: { type: STRING(32), allowNull: false, defaultValue: '', comment: '客户端类型:android/ios/web 等', }, app_version: { type: STRING(64), allowNull: false, defaultValue: '', comment: '客户端版本号', }, device_id: { type: STRING(128), allowNull: false, defaultValue: '', comment: '设备唯一标识', }, os_version: { type: STRING(64), allowNull: false, defaultValue: '', comment: '操作系统版本', }, device_model: { type: STRING(128), allowNull: false, defaultValue: '', comment: '设备型号', }, error_type: { type: STRING(64), allowNull: false, defaultValue: '', comment: '错误类型/等级', }, error_message: { type: TEXT, allowNull: true, comment: '错误信息(服务端截断上限 5000 字符)', }, error_stack: { type: TEXT('medium'), allowNull: true, comment: '错误堆栈(服务端截断上限 65535 字符)', }, extra: { type: TEXT, allowNull: true, comment: '附加上下文(JSON 字符串,服务端截断上限 65535 字符)', }, report_uuid: { type: STRING(64), allowNull: false, defaultValue: '', comment: '客户端上报幂等ID(唯一索引,重复上报静默成功)', }, client_time: { type: DATE, allowNull: true, comment: '客户端错误发生时间(仅参考,不作为记录时间)', }, created_at: { type: DATE, allowNull: false, comment: '服务端写入时间(统一取服务器当前时间)', }, updated_at: { type: DATE, allowNull: false, comment: '更新时间', }, }); await queryInterface.addIndex(TABLE_NAME, [ 'created_at' ], { name: 'idx_created_at' }); await queryInterface.addIndex(TABLE_NAME, [ 'client_type', 'app_version' ], { name: 'idx_client_type_app_version' }); await queryInterface.addIndex(TABLE_NAME, [ 'device_id' ], { name: 'idx_device_id' }); await queryInterface.addIndex(TABLE_NAME, [ 'report_uuid' ], { name: 'uk_report_uuid', unique: true }); }, // eslint-disable-next-line no-unused-vars async down(queryInterface, Sequelize) { await queryInterface.dropTable(TABLE_NAME); }, };