db->tableExists('school_years')) { $schoolYearFields = []; $this->addColumnIfMissing($schoolYearFields, 'school_years', 'registration_opens_at', ['type' => 'DATETIME', 'null' => true, 'after' => 'registration_starts_on']); $this->addColumnIfMissing($schoolYearFields, 'school_years', 'registration_deadline_at', ['type' => 'DATETIME', 'null' => true, 'after' => 'registration_ends_on']); $this->addColumnIfMissing($schoolYearFields, 'school_years', 'late_registration_blocked', ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1, 'after' => 'registration_deadline_at']); $this->addColumnIfMissing($schoolYearFields, 'school_years', 'administrative_exceptions_permitted', ['type' => 'TINYINT', 'constraint' => 1, 'default' => 1, 'after' => 'late_registration_blocked']); $this->addColumnIfMissing($schoolYearFields, 'school_years', 'registration_exception_roles', ['type' => 'TEXT', 'null' => true, 'after' => 'administrative_exceptions_permitted']); $this->addColumnIfMissing($schoolYearFields, 'school_years', 'adult_student_registration_enabled', ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'registration_exception_roles']); if ($schoolYearFields !== []) { $this->forge->addColumn('school_years', $schoolYearFields); } } if (! $this->db->tableExists('enrollment_age_rules')) { $this->forge->addField([ 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'school_year' => ['type' => 'VARCHAR', 'constraint' => 20], 'campus' => ['type' => 'VARCHAR', 'constraint' => 100, 'null' => true], 'grade_class_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true], 'education_level' => ['type' => 'VARCHAR', 'constraint' => 80, 'null' => true], 'minimum_age' => ['type' => 'INT', 'constraint' => 3, 'null' => true], 'maximum_age' => ['type' => 'INT', 'constraint' => 3, 'null' => true], 'age_reference_date' => ['type' => 'DATE', 'null' => true], 'behavior' => ['type' => 'VARCHAR', 'constraint' => 20, 'default' => 'blocking'], 'exceptions_allowed' => ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0], 'exception_roles' => ['type' => 'TEXT', 'null' => true], 'created_at' => ['type' => 'DATETIME', 'null' => true], 'updated_at' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('id', true); $this->forge->addKey(['school_year', 'grade_class_id']); $this->forge->createTable('enrollment_age_rules', true); } if (! $this->db->tableExists('enrollment_flags')) { $this->forge->addField([ 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'flag_type' => ['type' => 'VARCHAR', 'constraint' => 80], 'student_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'school_year' => ['type' => 'VARCHAR', 'constraint' => 20], 'source_school_year' => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true], 'status' => ['type' => 'VARCHAR', 'constraint' => 40, 'default' => 'open'], 'priority' => ['type' => 'VARCHAR', 'constraint' => 20, 'default' => 'normal'], 'assigned_to' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true], 'details_json' => ['type' => 'TEXT', 'null' => true], 'created_at' => ['type' => 'DATETIME', 'null' => true], 'resolved_at' => ['type' => 'DATETIME', 'null' => true], 'resolution_notes' => ['type' => 'TEXT', 'null' => true], ]); $this->forge->addKey('id', true); $this->forge->addKey(['student_id', 'school_year', 'flag_type']); $this->forge->createTable('enrollment_flags', true); } if (! $this->db->tableExists('enrollment_transition_audits')) { $this->forge->addField([ 'id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'auto_increment' => true], 'student_id' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true], 'school_year' => ['type' => 'VARCHAR', 'constraint' => 20], 'source_school_year' => ['type' => 'VARCHAR', 'constraint' => 20, 'null' => true], 'action' => ['type' => 'VARCHAR', 'constraint' => 80], 'performed_by' => ['type' => 'INT', 'constraint' => 11, 'unsigned' => true, 'null' => true], 'original_values_json' => ['type' => 'TEXT', 'null' => true], 'new_values_json' => ['type' => 'TEXT', 'null' => true], 'reason' => ['type' => 'TEXT', 'null' => true], 'created_at' => ['type' => 'DATETIME', 'null' => true], ]); $this->forge->addKey('id', true); $this->forge->addKey(['student_id', 'school_year', 'created_at']); $this->forge->createTable('enrollment_transition_audits', true); } } public function down() { $this->forge->dropTable('enrollment_transition_audits', true); $this->forge->dropTable('enrollment_flags', true); $this->forge->dropTable('enrollment_age_rules', true); if (! $this->db->tableExists('school_years')) { return; } foreach ([ 'registration_opens_at', 'registration_deadline_at', 'late_registration_blocked', 'administrative_exceptions_permitted', 'registration_exception_roles', 'adult_student_registration_enabled', ] as $field) { if ($this->db->fieldExists($field, 'school_years')) { $this->forge->dropColumn('school_years', $field); } } } private function addColumnIfMissing(array &$fields, string $table, string $name, array $definition): void { if (! $this->db->fieldExists($name, $table)) { $fields[$name] = $definition; } } }