'use strict'; /** * 协议(agreements) * * 一行 = 一种协议(用户协议 / 隐私政策……),版本正文在 `agreement_versions`, * `current_version_id` 指向当前生效版本(不设外键,避免与版本表互相依赖)。 */ module.exports = (app) => { const { BIGINT, STRING, TINYINT, INTEGER, DATE } = app.Sequelize; const Agreement = app.model.define('agreement', { id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' }, code: { type: STRING(64), allowNull: false, unique: true, comment: '协议标识(user_agreement 等)' }, name: { type: STRING(128), allowNull: false, comment: '协议名称(展示用)' }, description: { type: STRING(255), allowNull: true, comment: '简介' }, required: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '登录是否必须同意:1是 0否' }, status: { type: TINYINT.UNSIGNED, allowNull: false, defaultValue: 1, comment: '状态:1启用 0停用' }, sortNo: { type: INTEGER.UNSIGNED, allowNull: false, defaultValue: 0, comment: '展示排序(小的在前)' }, currentVersionId: { type: BIGINT.UNSIGNED, allowNull: true, comment: '当前生效版本 agreement_versions.id' }, }, { tableName: 'agreements', paranoid: true, comment: '协议定义表', }); Agreement.associate = function() { app.model.Agreement.hasMany(app.model.AgreementVersion, { foreignKey: 'agreement_id', as: 'versions' }); app.model.Agreement.belongsTo(app.model.AgreementVersion, { foreignKey: 'current_version_id', as: 'currentVersion', constraints: false, }); }; return Agreement; };