'use strict'; /** * 协议版本(agreement_versions) * * 正文存 `content`(默认纯文本,`content_type='text'`;后续要富文本可改 'html'), * `status`:0 草稿 / 1 已发布 / 2 已归档。只有「已发布」且被 `agreements.current_version_id` * 指向的版本才会下发给客户端。 */ module.exports = (app) => { const { BIGINT, STRING, TINYINT, TEXT, DATE } = app.Sequelize; const AgreementVersion = app.model.define('agreement_version', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, agreementId: { type: BIGINT.UNSIGNED, allowNull: false, comment: 'agreements.id' }, version: { type: STRING(32), allowNull: false, comment: '版本号(1.0.0)' }, title: { type: STRING(128), allowNull: false, comment: '版本标题' }, summary: { type: STRING(255), allowNull: true, comment: '变更摘要' }, content: { type: TEXT('long'), allowNull: false, comment: '协议正文' }, contentType: { type: STRING(16), allowNull: false, defaultValue: 'text', comment: '正文类型:text / html' }, status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:0草稿 1已发布 2已归档' }, publishedAt: { type: DATE, allowNull: true, comment: '发布时间' }, effectiveAt: { type: DATE, allowNull: true, comment: '生效时间' }, }, { tableName: 'agreement_versions', paranoid: true, comment: '协议版本表', }); AgreementVersion.associate = function() { app.model.AgreementVersion.belongsTo(app.model.Agreement, { foreignKey: 'agreement_id', as: 'agreement' }); app.model.AgreementVersion.hasMany(app.model.UserAgreement, { foreignKey: 'version_id', as: 'userAgreements' }); }; return AgreementVersion; };