Files
competition-website/database/migrations/008-create-gaozhi-questions.js

70 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable('gaozhi_questions', {
question_uid: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '题目唯一标识',
},
question: {
type: Sequelize.TEXT,
allowNull: false,
comment: '题目内容',
},
answer: {
type: Sequelize.STRING(32),
allowNull: false,
comment: '正确答案',
},
question_type: {
type: Sequelize.STRING(16),
allowNull: false,
defaultValue: 'choice',
comment: '题目类型:choice选择题 judge判断题',
},
options: {
type: Sequelize.JSON,
allowNull: true,
comment: '选项(JSON格式)',
},
score: {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0,
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('gaozhi_questions', ['question_type'], { name: 'idx_question_type' }),
queryInterface.addIndex('gaozhi_questions', ['sort_order'], { name: 'idx_sort_order' }),
]);
});
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable('gaozhi_questions');
},
};