'use strict'; /** * 新闻模型 - News * * 存储新闻通知信息,支持置顶、微信公众号链接和按组别过滤显示。 * 表名:news */ module.exports = app => { const { STRING, TEXT, BOOLEAN, DATE, INTEGER } = app.Sequelize; const News = app.model.define('news', { // 主键 ID,自增 id: { type: INTEGER, primaryKey: true, autoIncrement: true, comment: '新闻唯一标识', }, // 新闻标题 title: { type: STRING(200), allowNull: false, comment: '新闻标题', }, // 新闻正文内容(支持 HTML) content: { type: TEXT, allowNull: true, defaultValue: null, comment: '新闻正文(微信链接型新闻可为空)', }, // 微信公众号文章链接 wx_link: { type: STRING(500), allowNull: true, defaultValue: null, comment: '微信公众号文章链接', }, // 新闻类型:content(内容型)/ wx_link(微信链接型) news_type: { type: STRING(20), allowNull: false, defaultValue: 'content', comment: '新闻类型:content=内容型, wx_link=微信链接型', }, // 发布时间 publish_time: { type: DATE, allowNull: false, comment: '发布时间', }, // 是否置顶 pinned: { type: BOOLEAN, allowNull: false, defaultValue: false, comment: '是否置顶', }, // 排序序号 sort_order: { type: INTEGER, allowNull: false, defaultValue: 0, comment: '排序序号,越小越靠前', }, // 目标可见组别 group: { type: STRING(20), allowNull: false, defaultValue: 'all', comment: '目标可见组别', }, // 标签(逗号分隔) tags: { type: STRING(500), allowNull: true, defaultValue: null, comment: '标签,多个标签用逗号分隔', }, // 记录创建时间 created_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '创建时间', }, // 记录更新时间 updated_at: { type: DATE, allowNull: false, defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'), comment: '更新时间', }, }, { tableName: 'news', timestamps: false, underscored: true, indexes: [ { fields: ['publish_time'], }, { fields: ['pinned', 'publish_time'], }, { fields: ['group'], }, { fields: ['sort_order'], }, ], }); return News; };