fix db delete data issue
Tests / PHPUnit (push) Failing after 1m24s

This commit is contained in:
root
2026-07-13 01:43:32 -04:00
parent f3ac521d7c
commit 504c3bc9f9
12 changed files with 76 additions and 154 deletions
@@ -8,20 +8,8 @@ class RemoveClassAssignmentSemester extends Migration
{
public function up()
{
if ($this->db->tableExists('teacher_class') && $this->db->fieldExists('semester', 'teacher_class')) {
if ($this->indexExists('teacher_class', 'unique_teacher_assignment')) {
$this->db->query('ALTER TABLE `teacher_class` DROP INDEX `unique_teacher_assignment`');
}
$this->forge->dropColumn('teacher_class', 'semester');
$this->db->query(
'ALTER TABLE `teacher_class` ADD UNIQUE KEY `unique_teacher_assignment` (`teacher_id`, `class_section_id`, `school_year`)'
);
}
if ($this->db->tableExists('student_class') && $this->db->fieldExists('semester', 'student_class')) {
$this->forge->dropColumn('student_class', 'semester');
}
// 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()
@@ -183,8 +183,8 @@ class FinancialSystemLedgerCleanup extends Migration
protected function archivePaypalTables(): void
{
$this->renameTableIfPresent('paypal_payments', 'archived_paypal_payments');
$this->renameTableIfPresent('paypal_transactions', 'archived_paypal_transactions');
// Keep legacy PayPal tables under their original names. Renaming them
// during migrate makes restored data appear to disappear from the app.
}
protected function restorePaypalTables(): void
@@ -169,28 +169,9 @@ class FixSchoolYearColumns extends Migration
$this->db->resetDataCache();
// Remove redundant columns. Dependent non-primary indexes are removed first.
foreach ($this->tablesWithoutDirectYear as $table) {
if (! $this->db->tableExists($table) || ! $this->db->fieldExists('school_year', $table)) {
continue;
}
$this->dropIndexesContainingColumn($table, 'school_year');
$this->dropChecksContainingColumn($table, 'school_year');
$this->forge->dropColumn($table, 'school_year');
$this->db->resetDataCache();
}
foreach ($this->tablesWithoutDirectSemester as $table) {
if (! $this->db->tableExists($table) || ! $this->db->fieldExists('semester', $table)) {
continue;
}
$this->dropIndexesContainingColumn($table, 'semester');
$this->dropChecksContainingColumn($table, 'semester');
$this->forge->dropColumn($table, 'semester');
$this->db->resetDataCache();
}
// Do not drop redundant school_year/semester columns here. Restored
// production dumps may still contain meaningful historical data in
// those columns, and running migrate must not destroy it.
$this->db->resetDataCache();
@@ -61,15 +61,8 @@ final class ApplySchoolYearSemesterAuditCorrections extends Migration
$this->ensureIndex($table, 'school_year');
}
foreach ($this->semesterDropTables as $table) {
if (! $this->db->tableExists($table) || ! $this->db->fieldExists('semester', $table)) {
continue;
}
$this->dropIndexesContainingColumn($table, 'semester');
$this->dropChecksContainingColumn($table, 'semester');
$this->forge->dropColumn($table, 'semester');
}
// Preserve legacy semester columns. They may be redundant for newer
// code paths, but migration must not delete restored production data.
foreach ($this->schoolYearIndexTables as $table) {
if (! $this->db->tableExists($table) || ! $this->db->fieldExists('school_year', $table)) {