-- allow a user to be readily deleted by adding cascades
ALTER TABLE music_sessions_user_history DROP CONSTRAINT music_sessions_user_history_user_id_fkey;
ALTER TABLE ONLY music_sessions_user_history ADD CONSTRAINT music_sessions_user_history_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;

ALTER TABLE crash_dumps DROP CONSTRAINT crash_dumps_user_id_fkey;
ALTER TABLE ONLY crash_dumps ADD CONSTRAINT crash_dumps_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;

ALTER TABLE music_sessions_history DROP CONSTRAINT music_sessions_history_user_id_fkey;
ALTER TABLE music_sessions_history ADD CONSTRAINT music_sessions_history_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;

ALTER TABLE music_sessions_user_history DROP CONSTRAINT "music_sessions_user_history_music_session_id_fkey";
ALTER TABLE music_sessions_user_history ADD CONSTRAINT "music_sessions_user_history_music_session_id_fkey" FOREIGN KEY (music_session_id) REFERENCES music_sessions_history(music_session_id) ON DELETE CASCADE;

ALTER TABLE "recordings" DROP CONSTRAINT "recordings_creator_id_fkey";
ALTER TABLE "recordings" ADD CONSTRAINT "recordings_creator_id_fkey" FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE;

ALTER TABLE playable_plays DROP CONSTRAINT "playable_plays_claimed_recording_id_fkey";
ALTER TABLE playable_plays ADD CONSTRAINT "playable_plays_claimed_recording_id_fkey" FOREIGN KEY (claimed_recording_id) REFERENCES claimed_recordings(id) ON DELETE CASCADE;