123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 'use strict';
- /** @type {import('sequelize-cli').Migration} */
- module.exports = {
- async up (queryInterface, Sequelize) {
- await queryInterface.createTable('news', {
- id: {
- type: Sequelize.INTEGER,
- primaryKey: true,
- autoIncrement: true
- },
- title: {
- type: Sequelize.STRING,
- allowNull: false,
- comment: '新闻标题'
- },
- content: {
- type: Sequelize.TEXT,
- allowNull: false,
- comment: '新闻内容'
- },
- summary: {
- type: Sequelize.TEXT,
- allowNull: true,
- comment: '新闻摘要'
- },
- author: {
- type: Sequelize.STRING,
- allowNull: true,
- comment: '作者'
- },
- source: {
- type: Sequelize.STRING,
- allowNull: true,
- comment: '新闻来源'
- },
- coverImage: {
- type: Sequelize.STRING,
- allowNull: true,
- comment: '封面图片URL'
- },
- category: {
- type: Sequelize.STRING,
- allowNull: true,
- comment: '新闻分类'
- },
- tags: {
- type: Sequelize.STRING,
- allowNull: true,
- comment: '标签,用逗号分隔'
- },
- viewCount: {
- type: Sequelize.INTEGER,
- defaultValue: 0,
- comment: '浏览次数'
- },
- isPublished: {
- type: Sequelize.BOOLEAN,
- defaultValue: true,
- comment: '是否发布'
- },
- publishedAt: {
- type: Sequelize.DATE,
- allowNull: true,
- comment: '发布时间'
- },
- createdAt: {
- type: Sequelize.DATE,
- allowNull: false
- },
- updatedAt: {
- type: Sequelize.DATE,
- allowNull: false
- }
- });
- // 添加索引
- await queryInterface.addIndex('news', ['title']);
- await queryInterface.addIndex('news', ['category']);
- await queryInterface.addIndex('news', ['isPublished']);
- await queryInterface.addIndex('news', ['publishedAt']);
- },
- async down (queryInterface, Sequelize) {
- await queryInterface.dropTable('news');
- }
- };
|