Files
starr-philproperties/database/migrations/20260101000041-add-attempt-number-passing-score-course-id-to-quiz-attempts.js
T
kennethobsequio 439bb33f77 ready to test
Testing

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
2026-06-22 10:06:58 +08:00

36 lines
1.3 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.addColumn('quiz_attempts', 'attempt_number', {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 1,
comment: '1-based counter per user + quiz (or user + assessment). Derived at insert time from prior attempt count.',
});
await queryInterface.addColumn('quiz_attempts', 'passing_score', {
type: Sequelize.INTEGER,
allowNull: true,
comment: 'Snapshot of the required passing score at the time of submission.',
});
await queryInterface.addColumn('quiz_attempts', 'course_id', {
type: Sequelize.BIGINT,
allowNull: true,
references: { model: 'courses', key: 'course_id' },
onDelete: 'SET NULL',
comment: 'Denormalized course reference for fast per-course attempt queries.',
});
await queryInterface.addIndex('quiz_attempts', { fields: ['course_id'], name: 'idx_qa_course_id' });
},
async down(queryInterface) {
await queryInterface.removeIndex('quiz_attempts', 'idx_qa_course_id');
await queryInterface.removeColumn('quiz_attempts', 'course_id');
await queryInterface.removeColumn('quiz_attempts', 'passing_score');
await queryInterface.removeColumn('quiz_attempts', 'attempt_number');
},
};