its 7am i havent slept i have no idea
This commit is contained in:
58
migrations/Version20251205134500.php
Normal file
58
migrations/Version20251205134500.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20251205134500 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add genres JSON column to albums for advanced search filters';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
if (!$this->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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user