-- musicians
CREATE TABLE users_likers (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    liker_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE users_likers ADD CONSTRAINT user_liker_uniqkey UNIQUE (user_id, liker_id);

-- bands
CREATE TABLE bands_likers (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    band_id VARCHAR(64) NOT NULL REFERENCES bands(id) ON DELETE CASCADE,
    liker_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE bands_likers ADD CONSTRAINT band_liker_uniqkey UNIQUE (band_id, liker_id);

-- recordings
CREATE TABLE recordings_likers (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE,
    liker_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE recordings_likers ADD CONSTRAINT recording_liker_uniqkey UNIQUE (recording_id, liker_id);

-- sessions
CREATE TABLE music_sessions_likers (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    music_session_id VARCHAR(64) NOT NULL REFERENCES music_sessions(id) ON DELETE CASCADE,
    liker_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE music_sessions_likers ADD CONSTRAINT music_sessions_liker_uniqkey UNIQUE (music_session_id, liker_id);