Files
competition-website/database/migrations/015-create-choice-questions.js

68 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('choice_questions', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '题目ID',
},
group: {
type: Sequelize.STRING(20),
allowNull: false,
comment: '组别:zhongzhi/gaozhi',
},
question: {
type: Sequelize.TEXT,
allowNull: false,
comment: '题目内容',
},
options: {
type: Sequelize.JSON,
allowNull: false,
comment: '选项列表 [{ key: "A", text: "..." }, ...]',
},
answer: {
type: Sequelize.STRING(10),
allowNull: false,
comment: '正确答案(如 A / AB / ABCD)',
},
score: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 5,
comment: '分值',
},
sort_order: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
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('choice_questions', ['group'], { name: 'idx_choice_group' }),
queryInterface.addIndex('choice_questions', ['sort_order'], { name: 'idx_choice_sort' }),
]);
});
},
down: async (queryInterface) => {
await queryInterface.dropTable('choice_questions');
},
};