48 lines
1.3 KiB
PHP
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;
|
|
}
|
|
}
|