news.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // models/News.js
  2. module.exports = (sequelize, DataTypes) => {
  3. const News = sequelize.define('News', {
  4. id: {
  5. type: DataTypes.INTEGER.UNSIGNED,
  6. primaryKey: true,
  7. autoIncrement: true
  8. },
  9. title: {
  10. type: DataTypes.STRING,
  11. allowNull: false,
  12. comment: '新闻标题'
  13. },
  14. content: {
  15. type: DataTypes.TEXT,
  16. allowNull: false,
  17. comment: '新闻内容'
  18. },
  19. summary: {
  20. type: DataTypes.TEXT,
  21. allowNull: true,
  22. comment: '新闻摘要'
  23. },
  24. author: {
  25. type: DataTypes.STRING,
  26. allowNull: true,
  27. comment: '作者'
  28. },
  29. source: {
  30. type: DataTypes.STRING,
  31. allowNull: true,
  32. comment: '新闻来源'
  33. },
  34. coverImage: {
  35. type: DataTypes.STRING,
  36. allowNull: true,
  37. comment: '封面图片URL'
  38. },
  39. category: {
  40. type: DataTypes.STRING,
  41. allowNull: true,
  42. comment: '新闻分类'
  43. },
  44. tags: {
  45. type: DataTypes.STRING,
  46. allowNull: true,
  47. comment: '标签,用逗号分隔'
  48. },
  49. viewCount: {
  50. type: DataTypes.INTEGER.UNSIGNED,
  51. defaultValue: 0,
  52. comment: '浏览次数'
  53. },
  54. isPublished: {
  55. type: DataTypes.BOOLEAN,
  56. defaultValue: true,
  57. comment: '是否发布'
  58. },
  59. publishedAt: {
  60. type: DataTypes.DATE,
  61. allowNull: true,
  62. comment: '发布时间'
  63. }
  64. }, {
  65. tableName: 'news',
  66. timestamps: true,
  67. indexes: [
  68. {
  69. fields: ['title']
  70. },
  71. {
  72. fields: ['category']
  73. },
  74. {
  75. fields: ['isPublished']
  76. },
  77. {
  78. fields: ['publishedAt']
  79. }
  80. ]
  81. });
  82. return News;
  83. };