--up
CREATE TABLE tracks_for_sharing (
    id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    s3_key text NOT NULL,
    author_id integer NOT NULL REFERENCES users (id) ON UPDATE RESTRICT ON DELETE RESTRICT,
    name text NOT NULL,
    uuid text NOT NULL UNIQUE,
    s3_url text NOT NULL,
    band_energy jsonb NOT NULL
);
CREATE INDEX tracks_for_sharing_author_id_idx ON tracks_for_sharing USING btree (author_id);

CREATE TABLE shared_tracks_plays (
    id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    user_id integer REFERENCES users (id) ON UPDATE RESTRICT ON DELETE RESTRICT,
    track_id integer NOT NULL REFERENCES tracks_for_sharing (id) ON UPDATE RESTRICT ON DELETE RESTRICT
);
CREATE INDEX shared_tracks_plays_track_id_idx ON shared_tracks_plays USING btree (track_id);

ALTER TABLE users ADD COLUMN share_name text;

--down
DROP TABLE shared_tracks_plays;
DROP TABLE tracks_for_sharing;
ALTER TABLE users DROP COLUMN share_name;
