shouldAddColumn($schema, 'albums', 'genres')) { return; } if ($this->isSqlite()) { $this->addSql("ALTER TABLE albums ADD genres CLOB NOT NULL DEFAULT '[]'"); return; } $this->addSql("ALTER TABLE albums ADD genres JSON NOT NULL DEFAULT '[]'"); } public function down(Schema $schema): void { if ($this->isSqlite()) { // SQLite cannot drop columns without rebuilding the table; leave as-is. return; } if ($schema->hasTable('albums') && $schema->getTable('albums')->hasColumn('genres')) { $this->addSql('ALTER TABLE albums DROP genres'); } } private function isSqlite(): bool { return $this->connection->getDatabasePlatform()->getName() === 'sqlite'; } private function shouldAddColumn(Schema $schema, string $tableName, string $column): bool { if (!$schema->hasTable($tableName)) { return false; } return !$schema->getTable($tableName)->hasColumn($column); } }