db->tableExists('question_pools')) { $this->forge->addField([ 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'name' => ['type' => 'VARCHAR', 'constraint' => 150], 'subject_tag' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true], 'created_by' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true], 'created_at' => ['type' => 'DATETIME', 'null' => true], 'updated_at' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('id', true); $this->forge->addKey('subject_tag'); $this->forge->createTable('question_pools', true); } if (! $this->db->tableExists('assessment_questions')) { $this->forge->addField([ 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'pool_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'type' => ['type' => 'ENUM', 'constraint' => ['multiple_choice', 'short_answer', 'true_false', 'essay']], 'text' => ['type' => 'TEXT'], 'options' => ['type' => 'TEXT', 'null' => true], 'correct_answer' => ['type' => 'TEXT', 'null' => true], 'points' => ['type' => 'DECIMAL', 'constraint' => '8,2', 'default' => 0], 'order_index' => ['type' => 'INT', 'constraint' => 11, 'default' => 0], 'created_at' => ['type' => 'DATETIME', 'null' => true], 'updated_at' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('id', true); $this->forge->addKey(['pool_id', 'order_index']); $this->forge->addForeignKey('pool_id', 'question_pools', 'id', 'CASCADE', 'CASCADE'); $this->forge->createTable('assessment_questions', true); } if (! $this->db->tableExists('assessment_forms')) { $this->forge->addField([ 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'name' => ['type' => 'VARCHAR', 'constraint' => 150], 'pool_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'created_by' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true], 'status' => ['type' => 'ENUM', 'constraint' => ['draft', 'published', 'archived'], 'default' => 'draft'], 'created_at' => ['type' => 'DATETIME', 'null' => true], 'updated_at' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('id', true); $this->forge->addKey(['pool_id', 'status']); $this->forge->addForeignKey('pool_id', 'question_pools', 'id', 'RESTRICT', 'CASCADE'); $this->forge->createTable('assessment_forms', true); } if (! $this->db->tableExists('assessment_form_questions')) { $this->forge->addField([ 'form_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'question_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'order_index' => ['type' => 'INT', 'constraint' => 11, 'default' => 0], ]); $this->forge->addKey(['form_id', 'question_id'], true); $this->forge->addKey(['form_id', 'order_index']); $this->forge->addForeignKey('form_id', 'assessment_forms', 'id', 'CASCADE', 'CASCADE'); $this->forge->addForeignKey('question_id', 'assessment_questions', 'id', 'RESTRICT', 'CASCADE'); $this->forge->createTable('assessment_form_questions', true); } if (! $this->db->tableExists('student_assessments')) { $this->forge->addField([ 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'form_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'student_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'status' => ['type' => 'ENUM', 'constraint' => ['not_started', 'in_progress', 'completed', 'graded'], 'default' => 'not_started'], 'assigned_at' => ['type' => 'DATETIME', 'null' => true], 'started_at' => ['type' => 'DATETIME', 'null' => true], 'submitted_at' => ['type' => 'DATETIME', 'null' => true], 'graded_at' => ['type' => 'DATETIME', 'null' => true], 'graded_by' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true], 'score' => ['type' => 'DECIMAL', 'constraint' => '10,2', 'null' => true], 'education_committee_note' => ['type' => 'TEXT', 'null' => true], 'created_at' => ['type' => 'DATETIME', 'null' => true], 'updated_at' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('id', true); $this->forge->addUniqueKey(['form_id', 'student_id'], 'uq_assessment_form_student'); $this->forge->addKey(['student_id', 'status']); $this->forge->addForeignKey('form_id', 'assessment_forms', 'id', 'RESTRICT', 'CASCADE'); $this->forge->addForeignKey('student_id', 'students', 'id', 'CASCADE', 'CASCADE'); $this->forge->createTable('student_assessments', true); } if (! $this->db->tableExists('student_answers')) { $this->forge->addField([ 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'student_assessment_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'question_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'answer_value' => ['type' => 'TEXT', 'null' => true], 'is_correct' => ['type' => 'TINYINT', 'constraint' => 1, 'null' => true], 'points_awarded' => ['type' => 'DECIMAL', 'constraint' => '8,2', 'null' => true], 'created_at' => ['type' => 'DATETIME', 'null' => true], 'updated_at' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('id', true); $this->forge->addUniqueKey(['student_assessment_id', 'question_id'], 'uq_student_answer_question'); $this->forge->addForeignKey('student_assessment_id', 'student_assessments', 'id', 'CASCADE', 'CASCADE'); $this->forge->addForeignKey('question_id', 'assessment_questions', 'id', 'RESTRICT', 'CASCADE'); $this->forge->createTable('student_answers', true); } } public function down() { foreach (['student_answers', 'student_assessments', 'assessment_form_questions', 'assessment_forms', 'assessment_questions', 'question_pools'] as $table) { $this->forge->dropTable($table, true); } } }