Files

69 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('news', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '新闻ID',
},
title: {
type: Sequelize.STRING(255),
allowNull: false,
comment: '新闻标题',
},
content: {
type: Sequelize.TEXT('long'),
allowNull: true,
comment: '新闻内容(富文本)',
},
wx_link: {
type: Sequelize.STRING(512),
allowNull: true,
comment: '微信链接',
},
publish_time: {
type: Sequelize.DATE,
allowNull: true,
comment: '发布时间',
},
pinned: {
type: Sequelize.TINYINT,
allowNull: false,
defaultValue: 0,
comment: '是否置顶:0否 1是',
},
group_name: {
type: Sequelize.STRING(64),
allowNull: true,
comment: '目标组别',
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
comment: '更新时间',
},
}).then(() => {
return Promise.all([
queryInterface.addIndex('news', ['publish_time'], { name: 'idx_publish_time' }),
queryInterface.addIndex('news', ['pinned', 'publish_time'], { name: 'idx_pinned_publish_time' }),
queryInterface.addIndex('news', ['group_name'], { name: 'idx_group_name' }),
]);
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('news');
},
};