189 lines
6.6 KiB
PHP
189 lines
6.6 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use App\Support\Enrollment\DeliberationDecision;
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class AddSchoolYearTransitionEnrollmentFields extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
if ($this->db->tableExists('student_decisions') && ! $this->db->fieldExists('deliberation_decision_standard', 'student_decisions')) {
|
|
$this->forge->addColumn('student_decisions', [
|
|
'deliberation_decision_standard' => [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 40,
|
|
'null' => true,
|
|
'after' => 'decision',
|
|
],
|
|
]);
|
|
}
|
|
|
|
if ($this->db->tableExists('student_decisions') && $this->db->fieldExists('deliberation_decision_standard', 'student_decisions')) {
|
|
$rows = $this->db->table('student_decisions')
|
|
->select('id, decision')
|
|
->get()
|
|
->getResultArray();
|
|
|
|
foreach ($rows as $row) {
|
|
$standard = DeliberationDecision::normalize($row['decision'] ?? null);
|
|
if ($standard === null) {
|
|
continue;
|
|
}
|
|
|
|
$this->db->table('student_decisions')
|
|
->where('id', (int) $row['id'])
|
|
->update(['deliberation_decision_standard' => $standard]);
|
|
}
|
|
}
|
|
|
|
if (! $this->db->tableExists('enrollments')) {
|
|
return;
|
|
}
|
|
|
|
$fields = [];
|
|
$this->addFieldIfMissing($fields, 'source_school_year', [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 20,
|
|
'null' => true,
|
|
'after' => 'school_year',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'deliberation_decision', [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 40,
|
|
'null' => true,
|
|
'after' => 'source_school_year',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'source_grade_id', [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
'after' => 'deliberation_decision',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'assigned_grade_id', [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
'after' => 'source_grade_id',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'source_class_section_id', [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
'after' => 'assigned_grade_id',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'assigned_class_section_id', [
|
|
'type' => 'INT',
|
|
'constraint' => 11,
|
|
'unsigned' => true,
|
|
'null' => true,
|
|
'after' => 'source_class_section_id',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'placement_status', [
|
|
'type' => 'VARCHAR',
|
|
'constraint' => 40,
|
|
'null' => true,
|
|
'after' => 'assigned_class_section_id',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'age_reference_date', [
|
|
'type' => 'DATE',
|
|
'null' => true,
|
|
'after' => 'placement_status',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'age_on_reference_date', [
|
|
'type' => 'INT',
|
|
'constraint' => 3,
|
|
'null' => true,
|
|
'after' => 'age_reference_date',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'adult_student', [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
'after' => 'age_on_reference_date',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'parent_enrollment_allowed', [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 1,
|
|
'after' => 'adult_student',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'student_self_enrollment_allowed', [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
'after' => 'parent_enrollment_allowed',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'exception_required', [
|
|
'type' => 'TINYINT',
|
|
'constraint' => 1,
|
|
'default' => 0,
|
|
'after' => 'student_self_enrollment_allowed',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'exception_reason', [
|
|
'type' => 'TEXT',
|
|
'null' => true,
|
|
'after' => 'exception_required',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'registration_submitted_at', [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
'after' => 'exception_reason',
|
|
]);
|
|
$this->addFieldIfMissing($fields, 'registration_confirmed_at', [
|
|
'type' => 'DATETIME',
|
|
'null' => true,
|
|
'after' => 'registration_submitted_at',
|
|
]);
|
|
|
|
if ($fields !== []) {
|
|
$this->forge->addColumn('enrollments', $fields);
|
|
}
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
if ($this->db->tableExists('student_decisions') && $this->db->fieldExists('deliberation_decision_standard', 'student_decisions')) {
|
|
$this->forge->dropColumn('student_decisions', 'deliberation_decision_standard');
|
|
}
|
|
|
|
if (! $this->db->tableExists('enrollments')) {
|
|
return;
|
|
}
|
|
|
|
foreach ([
|
|
'source_school_year',
|
|
'deliberation_decision',
|
|
'source_grade_id',
|
|
'assigned_grade_id',
|
|
'source_class_section_id',
|
|
'assigned_class_section_id',
|
|
'placement_status',
|
|
'age_reference_date',
|
|
'age_on_reference_date',
|
|
'adult_student',
|
|
'parent_enrollment_allowed',
|
|
'student_self_enrollment_allowed',
|
|
'exception_required',
|
|
'exception_reason',
|
|
'registration_submitted_at',
|
|
'registration_confirmed_at',
|
|
] as $field) {
|
|
if ($this->db->fieldExists($field, 'enrollments')) {
|
|
$this->forge->dropColumn('enrollments', $field);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function addFieldIfMissing(array &$fields, string $name, array $definition): void
|
|
{
|
|
if (! $this->db->fieldExists($name, 'enrollments')) {
|
|
$fields[$name] = $definition;
|
|
}
|
|
}
|
|
}
|