isSqlite()) { // SQLite schema already ships with these columns/defaults. return; } $this->addSql("ALTER TABLE albums ADD local_id VARCHAR(64) DEFAULT NULL"); $this->addSql("ALTER TABLE albums ADD source VARCHAR(16) NOT NULL DEFAULT 'spotify'"); $this->addSql("ALTER TABLE albums ADD created_by_id INT DEFAULT NULL"); $this->addSql("ALTER TABLE albums ALTER spotify_id DROP NOT NULL"); $this->addSql("CREATE UNIQUE INDEX uniq_album_local_id ON albums (local_id)"); $this->addSql("ALTER TABLE albums ADD CONSTRAINT FK_F4E2474FB03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE"); $this->addSql("CREATE INDEX IDX_F4E2474FB03A8386 ON albums (created_by_id)"); $this->addSql("UPDATE albums SET source = 'spotify' WHERE source IS NULL"); } public function down(Schema $schema): void { if ($this->isSqlite()) { return; } $this->addSql("ALTER TABLE albums DROP CONSTRAINT FK_F4E2474FB03A8386"); $this->addSql("DROP INDEX IF EXISTS uniq_album_local_id"); $this->addSql("DROP INDEX IF EXISTS IDX_F4E2474FB03A8386"); $this->addSql("ALTER TABLE albums DROP COLUMN local_id"); $this->addSql("ALTER TABLE albums DROP COLUMN source"); $this->addSql("ALTER TABLE albums DROP COLUMN created_by_id"); $this->addSql("ALTER TABLE albums ALTER spotify_id SET NOT NULL"); } private function isSqlite(): bool { return $this->connection->getDatabasePlatform()->getName() === 'sqlite'; } }