'use strict'; /** * 上传文件登记(file_records) * * 只登记「上传成功」的对象;引用关系不落库,由 `service/fileStorage` 实时判断 * (用户头像 / 文档正文),所以删除业务数据后不会留下脏引用。 */ module.exports = (app) => { const { BIGINT, STRING } = app.Sequelize; const FileRecord = app.model.define('file_record', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, // `key` 是 MySQL 保留字,落库列名用 object_key key: { type: STRING(512), allowNull: false, unique: true, field: 'object_key', comment: 'COS 对象键' }, url: { type: STRING(512), allowNull: false, comment: '对外访问地址' }, fileName: { type: STRING(255), allowNull: false, defaultValue: '', comment: '原始文件名' }, size: { type: BIGINT.UNSIGNED, allowNull: false, defaultValue: 0, comment: '字节数' }, mimeType: { type: STRING(100), allowNull: false, defaultValue: '', comment: 'MIME 类型' }, hash: { type: STRING(64), allowNull: false, defaultValue: '', comment: '内容 SHA256' }, category: { type: STRING(32), allowNull: false, defaultValue: '', comment: '业务分类:avatar / doc' }, uploaderId: { type: BIGINT.UNSIGNED, allowNull: true, comment: '上传者 users.id' }, uploaderName: { type: STRING(64), allowNull: false, defaultValue: '', comment: '上传者快照' }, }, { tableName: 'file_records', paranoid: true, comment: '上传文件登记表', }); return FileRecord; };