Files
alrahma_sunday_school/app/Database/Migrations/2026-01-05-215851_FixPrintRequestsForeignKey.php
T
root 716cc8b8d3
Tests / PHPUnit (push) Failing after 1m20s
fix school year for all tables
2026-07-18 14:45:38 -04:00

57 lines
1.4 KiB
PHP

<?php
namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class FixPrintRequestsForeignKey extends Migration
{
public function up()
{
if (! $this->db->tableExists('print_requests')) {
return;
}
// Drop the old foreign key if it exists
try {
$this->forge->dropForeignKey('print_requests', 'print_requests_class_id_foreign');
} catch (\Throwable $e) {
// Already absent.
}
if (! $this->db->tableExists('class_sections')) {
return;
}
// Add the new foreign key
$this->forge->addForeignKey('class_id', 'class_sections', 'id', 'CASCADE', 'CASCADE');
// Process the modifications
$this->forge->processIndexes('print_requests');
}
public function down()
{
if (! $this->db->tableExists('print_requests')) {
return;
}
// Drop the new foreign key
try {
$this->forge->dropForeignKey('print_requests', 'print_requests_class_id_foreign');
} catch (\Throwable $e) {
// Already absent.
}
if (! $this->db->tableExists('classes')) {
return;
}
// Re-add the old foreign key
$this->forge->addForeignKey('class_id', 'classes', 'id', 'CASCADE', 'CASCADE');
// Process the modifications
$this->forge->processIndexes('print_requests');
}
}