Files
starr-philproperties/database/migrations/20260101000019-create-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

29 lines
1.6 KiB
JavaScript

'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('quiz_attempts', {
attempt_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
uuid: { type: Sequelize.UUID, defaultValue: Sequelize.UUIDV4, unique: true },
user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
quiz_id: { type: Sequelize.BIGINT, allowNull: true, references: { model: 'unit_quizzes', key: 'quiz_id' }, onDelete: 'SET NULL' },
assessment_id: { type: Sequelize.BIGINT, allowNull: true, references: { model: 'course_assessments', key: 'assessment_id' }, onDelete: 'SET NULL' },
answers: { type: Sequelize.JSONB, allowNull: false, defaultValue: {} },
total_points: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
earned_points: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
score: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
passed: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false },
createdAt: { type: Sequelize.DATE, allowNull: false },
updatedAt: { type: Sequelize.DATE, allowNull: false },
});
await queryInterface.addIndex('quiz_attempts', ['user_id']);
await queryInterface.addIndex('quiz_attempts', ['quiz_id']);
await queryInterface.addIndex('quiz_attempts', ['assessment_id']);
},
async down(queryInterface) {
await queryInterface.dropTable('quiz_attempts');
},
};