migrations/Version20251029200507.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20251029200507 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Atualiza a tabela std_ads_zones: remove allowed_formats e adiciona width, height e position.';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         // Primeiro tenta remover a coluna (sem IF EXISTS, com try/catch SQL)
  15.         try {
  16.             $this->addSql("ALTER TABLE `std_ads_zones` DROP COLUMN `allowed_formats`;");
  17.         } catch (\Throwable $e) {
  18.             // ignora erro se a coluna não existir
  19.         }
  20.         // Agora aplica as alterações estruturais
  21.         $this->addSql(<<<'SQL'
  22.             ALTER TABLE `std_ads_zones`
  23.             MODIFY `description` TEXT NULL,
  24.             ADD COLUMN `width` INT DEFAULT NULL AFTER `description`,
  25.             ADD COLUMN `height` INT DEFAULT NULL AFTER `width`,
  26.             ADD COLUMN `position` VARCHAR(100) DEFAULT NULL AFTER `height`;
  27.         SQL);
  28.     }
  29.     public function down(Schema $schema): void
  30.     {
  31.         $this->addSql(<<<'SQL'
  32.             ALTER TABLE `std_ads_zones`
  33.             ADD COLUMN `allowed_formats` JSON DEFAULT NULL AFTER `description`,
  34.             DROP COLUMN `width`,
  35.             DROP COLUMN `height`,
  36.             DROP COLUMN `position`;
  37.         SQL);
  38.     }
  39. }