wtf
All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 2m0s

This commit is contained in:
2025-11-28 02:00:11 +00:00
parent 1c98a634c3
commit dae8f3d999
35 changed files with 1510 additions and 82 deletions

View File

@@ -16,7 +16,24 @@ final class Version20251114113000 extends AbstractMigration
public function up(Schema $schema): void
{
// Add nullable album_id first
if (!$schema->hasTable('reviews')) {
return;
}
$reviews = $schema->getTable('reviews');
if ($reviews->hasColumn('album_id')) {
// Already migrated (common for SQLite dev DBs)
return;
}
if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') {
// SQLite cannot add FK constraints after table creation; add the column + index and rely on app-level validation.
$this->addSql('ALTER TABLE reviews ADD COLUMN album_id INTEGER DEFAULT NULL');
$this->addSql('CREATE INDEX IF NOT EXISTS IDX_6970EF78E0C31AF9 ON reviews (album_id)');
$this->addSql('UPDATE reviews SET album_id = (SELECT a.id FROM albums a WHERE a.spotify_id = reviews.spotify_album_id) WHERE album_id IS NULL');
return;
}
// Add nullable album_id first (PostgreSQL / others that support full DDL)
$this->addSql('ALTER TABLE reviews ADD album_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE reviews ADD CONSTRAINT FK_6970EF78E0C31AF9 FOREIGN KEY (album_id) REFERENCES albums (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_6970EF78E0C31AF9 ON reviews (album_id)');
@@ -53,6 +70,20 @@ SQL);
public function down(Schema $schema): void
{
if (!$schema->hasTable('reviews')) {
return;
}
$reviews = $schema->getTable('reviews');
if (!$reviews->hasColumn('album_id')) {
return;
}
if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') {
$this->addSql('DROP INDEX IF EXISTS IDX_6970EF78E0C31AF9');
$this->addSql('ALTER TABLE reviews DROP COLUMN album_id');
return;
}
$this->addSql('ALTER TABLE reviews DROP CONSTRAINT FK_6970EF78E0C31AF9');
$this->addSql('DROP INDEX IF EXISTS IDX_6970EF78E0C31AF9');
$this->addSql('ALTER TABLE reviews DROP COLUMN album_id');