41 lines
1.8 KiB
JavaScript
41 lines
1.8 KiB
JavaScript
|
|
'use strict';
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 迁移 020:为 zhongzhi_submissions / gaozhi_submissions 增加 question_type 列
|
|||
|
|
*
|
|||
|
|
* 背景(Bug #11 / B11):选择题(choice_questions)与判断题(judge_questions)的 id
|
|||
|
|
* 在不同表中数值重叠(如 choice#5 与 judge#5 均为 5),原 saveAnswers 仅按
|
|||
|
|
* (aggregation_uid, question_uid) 查找并 upsert,导致同 id 的选择题与判断题被
|
|||
|
|
* 折叠成一条记录,考生作答数少于抽题数、部分答案静默丢失。
|
|||
|
|
*
|
|||
|
|
* 修复:新增 question_type 列(choice/judge),与 question_uid 联合唯一标识一道题;
|
|||
|
|
* service.saveAnswers 的查找/写入键改为 (aggregation_uid, question_uid, question_type);
|
|||
|
|
* autoScore 判分不受影响(其本就按 question_type 选模型 + 用原始 id 作主键)。
|
|||
|
|
*/
|
|||
|
|
module.exports = {
|
|||
|
|
up: async (queryInterface, Sequelize) => {
|
|||
|
|
const addCol = async (table) => {
|
|||
|
|
await queryInterface.addColumn(table, 'question_type', {
|
|||
|
|
type: Sequelize.STRING(16),
|
|||
|
|
allowNull: false,
|
|||
|
|
defaultValue: '',
|
|||
|
|
comment: '题型:choice/judge,与 question_uid 联合区分题目',
|
|||
|
|
});
|
|||
|
|
await queryInterface.addIndex(
|
|||
|
|
table,
|
|||
|
|
['aggregation_uid', 'question_uid', 'question_type'],
|
|||
|
|
{ name: `idx_${table}_agg_qtype` }
|
|||
|
|
);
|
|||
|
|
};
|
|||
|
|
await addCol('zhongzhi_submissions');
|
|||
|
|
await addCol('gaozhi_submissions');
|
|||
|
|
},
|
|||
|
|
|
|||
|
|
down: async (queryInterface, Sequelize) => {
|
|||
|
|
await queryInterface.removeIndex('zhongzhi_submissions', 'idx_zhongzhi_submissions_agg_qtype');
|
|||
|
|
await queryInterface.removeColumn('zhongzhi_submissions', 'question_type');
|
|||
|
|
await queryInterface.removeIndex('gaozhi_submissions', 'idx_gaozhi_submissions_agg_qtype');
|
|||
|
|
await queryInterface.removeColumn('gaozhi_submissions', 'question_type');
|
|||
|
|
},
|
|||
|
|
};
|