CREATE TABLE join_requests (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE,
    music_session_id VARCHAR(64) REFERENCES music_sessions(id) ON DELETE CASCADE,
    text VARCHAR(2000),
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE join_requests ADD CONSTRAINT user_music_session_uniqkey UNIQUE (user_id, music_session_id);

ALTER TABLE invitations ADD COLUMN join_request_id VARCHAR(64) REFERENCES join_requests(id) ON DELETE CASCADE;
