Files
haushalt/backend/migrations/Version20260326165702.php
2026-03-30 15:42:44 +02:00

51 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260326165702 extends AbstractMigration
{
public function getDescription(): string
{
return 'Rename task → task_schema, task_occurrence → task';
}
public function up(Schema $schema): void
{
// 1. Drop FKs on task_occurrence that reference task
$this->addSql('ALTER TABLE task_occurrence DROP FOREIGN KEY FK_A2EECA5C8DB60186');
// 2. Drop FK on task.category_id
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB2512469DE2');
// 3. Rename tables
$this->addSql('RENAME TABLE task TO task_schema');
$this->addSql('RENAME TABLE task_occurrence TO task');
// 4. Re-create FK: task.task_id → task_schema.id
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB258DB60186 FOREIGN KEY (task_id) REFERENCES task_schema (id) ON DELETE CASCADE');
// 5. Re-create FK: task_schema.category_id → category.id
$this->addSql('ALTER TABLE task_schema ADD CONSTRAINT FK_8327C58112469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// Drop FKs
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_527EDB258DB60186');
$this->addSql('ALTER TABLE task_schema DROP FOREIGN KEY FK_8327C58112469DE2');
// Rename back
$this->addSql('RENAME TABLE task TO task_occurrence');
$this->addSql('RENAME TABLE task_schema TO task');
// Re-create original FKs
$this->addSql('ALTER TABLE task_occurrence ADD CONSTRAINT FK_A2EECA5C8DB60186 FOREIGN KEY (task_id) REFERENCES task (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_527EDB2512469DE2 FOREIGN KEY (category_id) REFERENCES category (id) ON DELETE SET NULL');
}
}