Files
alrahma_sunday_school/app/Database/Migrations/2026-01-25-000000_RemoveClassAssignmentSemester.php
T
root 504c3bc9f9
Tests / PHPUnit (push) Failing after 1m24s
fix db delete data issue
2026-07-13 01:43:32 -04:00

48 lines
1.3 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class RemoveClassAssignmentSemester extends Migration
{
public function up()
{
// Keep the legacy semester columns in place. They may be ignored by newer
// code, but dropping them during a post-restore migrate destroys data.
}
public function down()
{
if ($this->db->tableExists('teacher_class')) {
$this->forge->addColumn('teacher_class', [
'semester' => [
'type' => 'VARCHAR',
'constraint' => 25,
'null' => false,
'default' => '',
],
]);
}
if ($this->db->tableExists('student_class')) {
$this->forge->addColumn('student_class', [
'semester' => [
'type' => 'VARCHAR',
'constraint' => 255,
'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;
}
}