fix db for tests
Tests / PHPUnit (push) Successful in 1m16s

This commit is contained in:
root
2026-07-16 00:23:49 -04:00
parent 745c294012
commit 7c341ca624
2 changed files with 29 additions and 4 deletions
@@ -12,7 +12,16 @@ class RemoveClassAssignmentSemester extends Migration
$this->db->tableExists('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(
'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));
}
}