Files
alrahma_sunday_school/app/Database/Migrations/2026-01-25-000000_RemoveClassAssignmentSemester.php
T
root 9de2ab2a9f
Tests / PHPUnit (push) Failing after 1m12s
fix teacher pages display between school years
2026-07-15 20:52:19 -04:00

45 lines
1.1 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class RemoveClassAssignmentSemester extends Migration
{
public function up()
{
if (
$this->db->tableExists('teacher_class')
&& $this->db->fieldExists('semester', 'teacher_class')
) {
$this->forge->dropColumn('teacher_class', 'semester');
}
}
public function down()
{
if (
$this->db->tableExists('teacher_class')
&& ! $this->db->fieldExists('semester', 'teacher_class')
) {
$this->forge->addColumn('teacher_class', [
'semester' => [
'type' => 'VARCHAR',
'constraint' => 25,
'null' => false,
'default' => '',
],
]);
}
}
private function indexExists(string $table, string $index): bool
{
$result = $this->db->query(
'SHOW INDEX FROM `' . str_replace('`', '``', $table) . '` WHERE Key_name = ' . $this->db->escape($index)
);
return $result->getNumRows() > 0;
}
}