123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- // models/News.js
- module.exports = (sequelize, DataTypes) => {
- const News = sequelize.define('News', {
- id: {
- type: DataTypes.INTEGER.UNSIGNED,
- primaryKey: true,
- autoIncrement: true
- },
- title: {
- type: DataTypes.STRING,
- allowNull: false,
- comment: '新闻标题'
- },
- content: {
- type: DataTypes.TEXT,
- allowNull: false,
- comment: '新闻内容'
- },
- summary: {
- type: DataTypes.TEXT,
- allowNull: true,
- comment: '新闻摘要'
- },
- author: {
- type: DataTypes.STRING,
- allowNull: true,
- comment: '作者'
- },
- source: {
- type: DataTypes.STRING,
- allowNull: true,
- comment: '新闻来源'
- },
- coverImage: {
- type: DataTypes.STRING,
- allowNull: true,
- comment: '封面图片URL'
- },
- category: {
- type: DataTypes.STRING,
- allowNull: true,
- comment: '新闻分类'
- },
- tags: {
- type: DataTypes.STRING,
- allowNull: true,
- comment: '标签,用逗号分隔'
- },
- viewCount: {
- type: DataTypes.INTEGER.UNSIGNED,
- defaultValue: 0,
- comment: '浏览次数'
- },
- isPublished: {
- type: DataTypes.BOOLEAN,
- defaultValue: true,
- comment: '是否发布'
- },
- publishedAt: {
- type: DataTypes.DATE,
- allowNull: true,
- comment: '发布时间'
- }
- }, {
- tableName: 'news',
- timestamps: true,
- indexes: [
- {
- fields: ['title']
- },
- {
- fields: ['category']
- },
- {
- fields: ['isPublished']
- },
- {
- fields: ['publishedAt']
- }
- ]
- });
- return News;
- };
|