app/DoctrineMigrations/Version20250925000000.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. /**
  7.  * Add sex_show_noanswer flag to dtb_school so per-school setting can be persisted
  8.  */
  9. final class Version20250925000000 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return 'Add sex_show_noanswer boolean column to dtb_school (default false)';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         $schemaManager $this->connection->createSchemaManager();
  18.         if (!$schemaManager->tablesExist(['dtb_school'])) {
  19.             return;
  20.         }
  21.         $columns $schemaManager->listTableColumns('dtb_school');
  22.         $hasColumn false;
  23.         foreach ($columns as $column) {
  24.             if ($column->getName() === 'sex_show_noanswer') {
  25.                 $hasColumn true;
  26.                 break;
  27.             }
  28.         }
  29.         if (!$hasColumn) {
  30.             // boolean type; some DBs use TINYINT, use SMALLINT to be portable
  31.             $this->addSql('ALTER TABLE dtb_school ADD sex_show_noanswer TINYINT(1) DEFAULT 0');
  32.         }
  33.     }
  34.     public function down(Schema $schema): void
  35.     {
  36.         $schemaManager $this->connection->createSchemaManager();
  37.         if (!$schemaManager->tablesExist(['dtb_school'])) {
  38.             return;
  39.         }
  40.         $columns $schemaManager->listTableColumns('dtb_school');
  41.         $hasColumn false;
  42.         foreach ($columns as $column) {
  43.             if ($column->getName() === 'sex_show_noanswer') {
  44.                 $hasColumn true;
  45.                 break;
  46.             }
  47.         }
  48.         if ($hasColumn) {
  49.             $this->addSql('ALTER TABLE dtb_school DROP sex_show_noanswer');
  50.         }
  51.     }
  52. }