55 lines
2.1 KiB
PHP
55 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class AddRegistrationExperienceFinancialFields extends Migration
|
|
{
|
|
public function up()
|
|
{
|
|
if (! $this->db->tableExists('school_years')) {
|
|
return;
|
|
}
|
|
|
|
$fields = [];
|
|
$this->addColumnIfMissing($fields, 'registration_fee', ['type' => 'DECIMAL', 'constraint' => '10,2', 'default' => 0, 'after' => 'adult_student_registration_enabled']);
|
|
$this->addColumnIfMissing($fields, 'tuition_due_at_registration', ['type' => 'DECIMAL', 'constraint' => '10,2', 'default' => 0, 'after' => 'registration_fee']);
|
|
$this->addColumnIfMissing($fields, 'mandatory_fees', ['type' => 'DECIMAL', 'constraint' => '10,2', 'default' => 0, 'after' => 'tuition_due_at_registration']);
|
|
$this->addColumnIfMissing($fields, 'carry_over_balance_behavior', ['type' => 'VARCHAR', 'constraint' => 60, 'default' => 'information_only', 'after' => 'mandatory_fees']);
|
|
$this->addColumnIfMissing($fields, 'financial_policy_message', ['type' => 'TEXT', 'null' => true, 'after' => 'carry_over_balance_behavior']);
|
|
$this->addColumnIfMissing($fields, 'payment_plan_available', ['type' => 'TINYINT', 'constraint' => 1, 'default' => 0, 'after' => 'financial_policy_message']);
|
|
|
|
if ($fields !== []) {
|
|
$this->forge->addColumn('school_years', $fields);
|
|
}
|
|
}
|
|
|
|
public function down()
|
|
{
|
|
if (! $this->db->tableExists('school_years')) {
|
|
return;
|
|
}
|
|
|
|
foreach ([
|
|
'registration_fee',
|
|
'tuition_due_at_registration',
|
|
'mandatory_fees',
|
|
'carry_over_balance_behavior',
|
|
'financial_policy_message',
|
|
'payment_plan_available',
|
|
] as $field) {
|
|
if ($this->db->fieldExists($field, 'school_years')) {
|
|
$this->forge->dropColumn('school_years', $field);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function addColumnIfMissing(array &$fields, string $name, array $definition): void
|
|
{
|
|
if (! $this->db->fieldExists($name, 'school_years')) {
|
|
$fields[$name] = $definition;
|
|
}
|
|
}
|
|
}
|