app/DoctrineMigrations/Version20251020000000.php line 1

Open in your IDE?
  1. <?php
    
    declare(strict_types=1);
    
    namespace DoctrineMigrations;
    
    use Doctrine\DBAL\Schema\Schema;
    use Doctrine\Migrations\AbstractMigration;
    
    /**
     * Add reserve_note_visible_flag column to dtb_school table
     */
    final class Version20251020000000 extends AbstractMigration
    {
        public function getDescription(): string
        {
            return 'Add reserve_note_visible_flag column to dtb_school table';
        }
    
        public function up(Schema $schema): void
        {
            $schemaManager = $this->connection->createSchemaManager();
            
            // テーブルが存在するかチェック
            if (!$schemaManager->tablesExist(['dtb_school'])) {
                return;
            }
            
            $columns = $schemaManager->listTableColumns('dtb_school');
            $columnNames = array_map(function($column) {
                return $column->getName();
            }, $columns);
            
            // reserve_note_visible_flagカラムが存在しない場合のみ追加
            if (!in_array('reserve_note_visible_flag', $columnNames)) {
                // Add reserve_note_visible_flag column to dtb_school table
                $this->addSql('ALTER TABLE dtb_school ADD reserve_note_visible_flag SMALLINT UNSIGNED NULL DEFAULT 1');
            }
        }
    
        public function down(Schema $schema): void
        {
            $schemaManager = $this->connection->createSchemaManager();
            
            // テーブルが存在するかチェック
            if (!$schemaManager->tablesExist(['dtb_school'])) {
                return;
            }
            
            $columns = $schemaManager->listTableColumns('dtb_school');
            $columnNames = array_map(function($column) {
                return $column->getName();
            }, $columns);
            
            // reserve_note_visible_flagカラムが存在する場合のみ削除
            if (in_array('reserve_note_visible_flag', $columnNames)) {
                // Remove reserve_note_visible_flag column from dtb_school table
                $this->addSql('ALTER TABLE dtb_school DROP reserve_note_visible_flag');
            }
        }
    }