import { MigrationInterface, QueryRunner } from 'typeorm'; export class SeedWebDevQuestions1779000000000 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { const courseId = 34; const adminId = 1; // 1. Ensure a chapter exists for the course let chapterId = 2; // Defaulting to 2 as seen previously const existingChapter = await queryRunner.query( `SELECT chapter_id FROM course_chapters WHERE course_id = ? LIMIT 1`, [courseId], ); if (existingChapter && existingChapter.length > 0) { chapterId = existingChapter[0].chapter_id; } else { const chapterResult = await queryRunner.query( `INSERT INTO course_chapters (course_id, name, chapter_order, is_active, created_at, updated_at) VALUES (?, 'Web Development Mastery', 1, 1, NOW(), NOW())`, [courseId], ); chapterId = chapterResult.insertId; } // Question generation logic const questions = this.getQuestionsData(); for (const q of questions) { const qResult = await queryRunner.query( `INSERT INTO question_bank_questions (course_id, chapter_id, question_type, difficulty, bloom_level, question_text, expected_answer_text, hints, status, created_by, updated_by, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'approved', ?, ?, NOW(), NOW())`, [ courseId, chapterId, q.type, q.difficulty, q.bloom, q.text, q.expectedAnswer || null, q.hints || null, adminId, adminId, ], ); const questionId = qResult.insertId; if (q.options && q.options.length > 0) { for (let i = 0; i < q.options.length; i++) { const opt = q.options[i]; await queryRunner.query( `INSERT INTO question_bank_options (question_id, option_text, is_correct, option_order) VALUES (?, ?, ?, ?)`, [questionId, opt.text, opt.isCorrect ? 1 : 0, i], ); } } if (q.fillBlanks && q.fillBlanks.length > 0) { for (const fb of q.fillBlanks) { await queryRunner.query( `INSERT INTO question_bank_fill_blanks (question_id, blank_key, acceptable_answer, is_case_sensitive) VALUES (?, ?, ?, ?)`, [questionId, fb.key, fb.answer, fb.isCaseSensitive ? 1 : 0], ); } } } } public async down(queryRunner: QueryRunner): Promise { // Delete the questions seeded in this migration by courseId. // Careful: this might delete user-created ones if they use courseId 34. // For safety, we only delete those created around this time or we just don't implement down. await queryRunner.query( `DELETE FROM question_bank_questions WHERE course_id = ? AND question_text LIKE '%HTML%'`, [34], ); } private getQuestionsData() { return [ // MCQs (20) { type: 'mcq', difficulty: 'easy', bloom: 'remembering', text: 'What does HTML stand for?', hints: 'Think about the structure of a web page.', options: [ { text: 'HyperText Markup Language', isCorrect: true }, { text: 'Home Tool Markup Language', isCorrect: false }, { text: 'Hyperlinks and Text Markup Language', isCorrect: false }, { text: 'HighText Machine Language', isCorrect: false }, ] }, { type: 'mcq', difficulty: 'easy', bloom: 'remembering', text: 'Which HTML element is used to specify a footer for a document or section?', options: [ { text: '