<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20251029200507 extends AbstractMigration
{
public function getDescription(): string
{
return 'Atualiza a tabela std_ads_zones: remove allowed_formats e adiciona width, height e position.';
}
public function up(Schema $schema): void
{
// Primeiro tenta remover a coluna (sem IF EXISTS, com try/catch SQL)
try {
$this->addSql("ALTER TABLE `std_ads_zones` DROP COLUMN `allowed_formats`;");
} catch (\Throwable $e) {
// ignora erro se a coluna não existir
}
// Agora aplica as alterações estruturais
$this->addSql(<<<'SQL'
ALTER TABLE `std_ads_zones`
MODIFY `description` TEXT NULL,
ADD COLUMN `width` INT DEFAULT NULL AFTER `description`,
ADD COLUMN `height` INT DEFAULT NULL AFTER `width`,
ADD COLUMN `position` VARCHAR(100) DEFAULT NULL AFTER `height`;
SQL);
}
public function down(Schema $schema): void
{
$this->addSql(<<<'SQL'
ALTER TABLE `std_ads_zones`
ADD COLUMN `allowed_formats` JSON DEFAULT NULL AFTER `description`,
DROP COLUMN `width`,
DROP COLUMN `height`,
DROP COLUMN `position`;
SQL);
}
}