-- Songs können mehreren Playlists (bisher: Alben) zugeordnet werden (Many-to-Many)
CREATE TABLE IF NOT EXISTS playlist_tracks (
    playlist_id INT NOT NULL,
    musik_id INT NOT NULL,
    PRIMARY KEY (playlist_id, musik_id),
    CONSTRAINT fk_pt_playlist FOREIGN KEY (playlist_id) REFERENCES alben(id) ON DELETE CASCADE,
    CONSTRAINT fk_pt_musik FOREIGN KEY (musik_id) REFERENCES musik(id) ON DELETE CASCADE
);

-- Bestehende Zuordnung übernehmen
INSERT IGNORE INTO playlist_tracks (playlist_id, musik_id)
SELECT album_id, id FROM musik WHERE album_id IS NOT NULL;

-- album_id aus musik entfernen
ALTER TABLE musik DROP FOREIGN KEY fk_musik_album;
ALTER TABLE musik DROP COLUMN album_id;
