<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260221130000 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add slug column to task table and backfill from existing titles';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE task ADD slug VARCHAR(255) DEFAULT NULL');
// Backfill: generate a basic slug from the existing title for all rows.
// The PHP-side slugify does transliteration; here we do a simpler SQL version
// which is good enough for seeding — the app will overwrite on next save.
$this->addSql("
UPDATE task
SET slug = LOWER(
TRIM(BOTH '-' FROM
REGEXP_REPLACE(
CONVERT(title USING ascii),
'[^a-zA-Z0-9]+',
'-'
)
)
)
WHERE slug IS NULL AND title IS NOT NULL AND title != ''
");
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE task DROP slug');
}
}