Files
symfony-k3s/migrations/Version20260907123000.php
T

44 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260907123000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add an optional self-referencing parent task relationship for sub-tasks.';
}
public function up(Schema $schema): void
{
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
$this->addSql('ALTER TABLE task ADD parent_task_id INT DEFAULT NULL');
$this->addSql('CREATE INDEX IDX_TASK_PARENT_TASK ON task (parent_task_id)');
$this->addSql('ALTER TABLE task ADD CONSTRAINT FK_TASK_PARENT_TASK FOREIGN KEY (parent_task_id) REFERENCES task (id) ON DELETE SET NULL');
return;
}
$this->addSql('ALTER TABLE task ADD parent_task_id INT DEFAULT NULL, ADD INDEX IDX_TASK_PARENT_TASK (parent_task_id), ADD CONSTRAINT FK_TASK_PARENT_TASK FOREIGN KEY (parent_task_id) REFERENCES task (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
if ($this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
$this->addSql('ALTER TABLE task DROP CONSTRAINT FK_TASK_PARENT_TASK');
$this->addSql('DROP INDEX IDX_TASK_PARENT_TASK');
$this->addSql('ALTER TABLE task DROP parent_task_id');
return;
}
$this->addSql('ALTER TABLE task DROP FOREIGN KEY FK_TASK_PARENT_TASK, DROP INDEX IDX_TASK_PARENT_TASK, DROP parent_task_id');
}
}