DROP TABLE bands_musicians;
DROP TABLE musicians_instruments;
DROP TABLE musicians;

ALTER TABLE users ADD COLUMN musician BOOLEAN NOT NULL DEFAULT false;
ALTER TABLE bands ADD COLUMN website VARCHAR(4000) NULL;
ALTER TABLE bands ADD COLUMN biography VARCHAR(4000) NOT NULL;

-- musician -> band mapping
CREATE TABLE bands_users (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    band_id VARCHAR(64) REFERENCES bands(id) ON DELETE CASCADE,
    user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE,
    is_admin BOOLEAN NOT NULL DEFAULT false,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE bands_users ADD CONSTRAINT band_user_uniqkey UNIQUE (band_id, user_id);

-- musician -> instrument mapping
CREATE TABLE users_instruments (
    id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
    user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE,
    instrument_id VARCHAR(64) REFERENCES instruments(id) ON DELETE CASCADE,
    proficiency_level SMALLINT NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

ALTER TABLE users_instruments ADD CONSTRAINT user_instrument_uniqkey UNIQUE (user_id, instrument_id);
