wtf
All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 2m0s
All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 2m0s
This commit is contained in:
@@ -16,14 +16,39 @@ final class Version20251205123000 extends AbstractMigration
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE users ADD profile_image_path VARCHAR(255) DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE albums ADD cover_image_path VARCHAR(255) DEFAULT NULL');
|
||||
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
|
||||
{
|
||||
$this->addSql('ALTER TABLE users DROP profile_image_path');
|
||||
$this->addSql('ALTER TABLE albums DROP cover_image_path');
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user