All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 2m0s
55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
|
use Doctrine\Migrations\AbstractMigration;
|
|
|
|
final class Version20251205123000 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Add profile image path to users and cover image path to albums';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
if ($this->shouldAddColumn($schema, 'users', 'profile_image_path')) {
|
|
$this->addSql('ALTER TABLE users ADD profile_image_path VARCHAR(255) DEFAULT NULL');
|
|
}
|
|
if ($this->shouldAddColumn($schema, 'albums', 'cover_image_path')) {
|
|
$this->addSql('ALTER TABLE albums ADD cover_image_path VARCHAR(255) DEFAULT NULL');
|
|
}
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
if ($this->isSqlite()) {
|
|
// SQLite cannot drop columns; leave them in place.
|
|
return;
|
|
}
|
|
if ($schema->hasTable('users') && $schema->getTable('users')->hasColumn('profile_image_path')) {
|
|
$this->addSql('ALTER TABLE users DROP profile_image_path');
|
|
}
|
|
if ($schema->hasTable('albums') && $schema->getTable('albums')->hasColumn('cover_image_path')) {
|
|
$this->addSql('ALTER TABLE albums DROP cover_image_path');
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|