users.id)'; } public function up(Schema $schema): void { if ($this->isSqlite()) { $this->addSql('ALTER TABLE albums ADD COLUMN owner_id INTEGER DEFAULT NULL'); $this->addSql('CREATE INDEX IF NOT EXISTS IDX_ALBUM_OWNER ON albums (owner_id)'); return; } $this->addSql('ALTER TABLE albums ADD owner_id INT DEFAULT NULL'); $this->addSql('CREATE INDEX IDX_ALBUM_OWNER ON albums (owner_id)'); $this->addSql('ALTER TABLE albums ADD CONSTRAINT FK_ALBUM_OWNER FOREIGN KEY (owner_id) REFERENCES users (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); } public function down(Schema $schema): void { if ($this->isSqlite()) { // SQLite down-migration omitted to avoid lossy table rebuild. return; } $this->addSql('ALTER TABLE albums DROP CONSTRAINT FK_ALBUM_OWNER'); $this->addSql('DROP INDEX IDX_ALBUM_OWNER'); $this->addSql('ALTER TABLE albums DROP COLUMN owner_id'); } private function isSqlite(): bool { return $this->connection->getDatabasePlatform()->getName() === 'sqlite'; } }