@@ -12,7 +12,16 @@ class RemoveClassAssignmentSemester extends Migration
|
|||||||
$this->db->tableExists('teacher_class')
|
$this->db->tableExists('teacher_class')
|
||||||
&& $this->db->fieldExists('semester', 'teacher_class')
|
&& $this->db->fieldExists('semester', 'teacher_class')
|
||||||
) {
|
) {
|
||||||
$this->forge->dropColumn('teacher_class', 'semester');
|
foreach ($this->indexesContainingColumn('teacher_class', 'semester') as $index) {
|
||||||
|
$this->db->query(
|
||||||
|
'DROP INDEX ' . $this->db->escapeIdentifiers($index) . ' ON ' . $this->db->escapeIdentifiers('teacher_class')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->query(
|
||||||
|
'ALTER TABLE ' . $this->db->escapeIdentifiers('teacher_class')
|
||||||
|
. ' DROP COLUMN ' . $this->db->escapeIdentifiers('semester')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,12 +42,21 @@ class RemoveClassAssignmentSemester extends Migration
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function indexExists(string $table, string $index): bool
|
private function indexesContainingColumn(string $table, string $column): array
|
||||||
{
|
{
|
||||||
$result = $this->db->query(
|
$result = $this->db->query(
|
||||||
'SHOW INDEX FROM `' . str_replace('`', '``', $table) . '` WHERE Key_name = ' . $this->db->escape($index)
|
'SHOW INDEX FROM ' . $this->db->escapeIdentifiers($table)
|
||||||
|
. ' WHERE Column_name = ' . $this->db->escape($column)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $result->getNumRows() > 0;
|
$indexes = [];
|
||||||
|
foreach ($result->getResultArray() as $row) {
|
||||||
|
$index = (string) ($row['Key_name'] ?? '');
|
||||||
|
if ($index !== '' && $index !== 'PRIMARY') {
|
||||||
|
$indexes[] = $index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_unique($indexes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ class RepairModelSchemaColumns extends Migration
|
|||||||
'after' => 'close_description',
|
'after' => 'close_description',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->addColumnIfMissing('current_flag', 'action_taken', [
|
||||||
|
'type' => 'TEXT',
|
||||||
|
'null' => true,
|
||||||
|
'after' => 'close_description',
|
||||||
|
]);
|
||||||
|
|
||||||
$this->addColumnIfMissing('user_preferences', 'timezone', [
|
$this->addColumnIfMissing('user_preferences', 'timezone', [
|
||||||
'type' => 'VARCHAR',
|
'type' => 'VARCHAR',
|
||||||
'constraint' => 64,
|
'constraint' => 64,
|
||||||
@@ -50,6 +56,7 @@ class RepairModelSchemaColumns extends Migration
|
|||||||
'calendar_events' => 'event_type',
|
'calendar_events' => 'event_type',
|
||||||
'exams' => 'school_year',
|
'exams' => 'school_year',
|
||||||
'flag' => 'action_taken',
|
'flag' => 'action_taken',
|
||||||
|
'current_flag' => 'action_taken',
|
||||||
'user_preferences' => 'timezone',
|
'user_preferences' => 'timezone',
|
||||||
'student_class' => 'is_event_only',
|
'student_class' => 'is_event_only',
|
||||||
] as $table => $column) {
|
] as $table => $column) {
|
||||||
|
|||||||
Reference in New Issue
Block a user