59 lines
1.7 KiB
PHP
59 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
final class Version20260402120000 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Add nullable cover_image_path to albums for user-uploaded album artwork';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
if (!$this->hasTable($schema, 'albums') || $this->hasColumn($schema, 'albums', 'cover_image_path')) {
|
|
return;
|
|
}
|
|
|
|
if ($this->isSqlite()) {
|
|
$this->addSql('ALTER TABLE albums ADD COLUMN cover_image_path VARCHAR(255) DEFAULT NULL');
|
|
return;
|
|
}
|
|
|
|
$this->addSql('ALTER TABLE albums ADD cover_image_path VARCHAR(255) DEFAULT NULL');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
if ($this->isSqlite()) {
|
|
// SQLite column removal requires a table rebuild; keep this migration forward-only on SQLite.
|
|
return;
|
|
}
|
|
|
|
if ($this->hasTable($schema, 'albums') && $this->hasColumn($schema, 'albums', 'cover_image_path')) {
|
|
$this->addSql('ALTER TABLE albums DROP COLUMN cover_image_path');
|
|
}
|
|
}
|
|
|
|
private function hasTable(Schema $schema, string $tableName): bool
|
|
{
|
|
return $schema->hasTable($tableName);
|
|
}
|
|
|
|
private function hasColumn(Schema $schema, string $tableName, string $columnName): bool
|
|
{
|
|
return $this->hasTable($schema, $tableName) && $schema->getTable($tableName)->hasColumn($columnName);
|
|
}
|
|
|
|
private function isSqlite(): bool
|
|
{
|
|
return $this->connection->getDatabasePlatform()->getName() === 'sqlite';
|
|
}
|
|
}
|
|
|