'use strict'; /** * 客户端错误日志暂存表模型(wms_client_error_log)。 * * Android/iOS/Web 等设备端通过 index.uploadClientErrorLog 上报的运行时错误日志暂存, * 仅做数据落库供人工/后台查询分析;report_uuid 唯一索引承担幂等去重(重复上报静默成功)。 * created_at/updated_at 由 Sequelize 时间戳统一取服务器当前时间,不采信客户端时间。 * * @param {import('egg').Application} app Egg 应用实例。 * @return {import('sequelize').ModelCtor} Sequelize 模型。 */ module.exports = app => { const { BIGINT, STRING, DATE, TEXT } = app.Sequelize; const ClientErrorLog = app.model.define('client_error_log', { id: { type: BIGINT(20).UNSIGNED, primaryKey: true, autoIncrement: true, 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: '更新时间', }, }, { tableName: 'wms_client_error_log', underscored: true, timestamps: true, createdAt: 'created_at', updatedAt: 'updated_at', paranoid: false, comment: '客户端错误日志暂存表(设备端运行时错误上报暂存)', indexes: [ { name: 'uk_report_uuid', unique: true, fields: [ 'report_uuid' ] }, { name: 'idx_created_at', fields: [ 'created_at' ] }, { name: 'idx_client_type_app_version', fields: [ 'client_type', 'app_version' ] }, { name: 'idx_device_id', fields: [ 'device_id' ] }, ], }); return ClientErrorLog; };