'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'); }, };