-- "rsvp_slots_instrument_id_fkey" FOREIGN KEY (instrument_id) REFERENCES instruments(id)
-- "musicians_instruments_instrument_id_fkey" FOREIGN KEY (instrument_id) REFERENCES instruments(id) ON DELETE CASCADE
-- "saved_tracks_instrument_id_fkey" FOREIGN KEY (instrument_id) REFERENCES instruments(id) ON DELETE CASCADE
ALTER TABLE rsvp_slots DROP CONSTRAINT rsvp_slots_instrument_id_fkey;
ALTER TABLE musicians_instruments DROP CONSTRAINT musicians_instruments_instrument_id_fkey;
ALTER TABLE recorded_tracks DROP CONSTRAINT saved_tracks_instrument_id_fkey;
UPDATE instruments SET id = 'double bass', description = 'Double Bass' WHERE id = 'upright bass';
UPDATE rsvp_slots SET instrument_id = 'double bass' where instrument_id = 'upright bass';
UPDATE musicians_instruments SET instrument_id = 'double bass' where instrument_id = 'upright bass';
UPDATE recorded_tracks SET instrument_id = 'double bass' where instrument_id = 'upright bass';
ALTER TABLE rsvp_slots ADD CONSTRAINT rsvp_slots_instrument_id_fkey FOREIGN KEY (instrument_id) REFERENCES instruments(id) ON DELETE SET NULL;
ALTER TABLE musicians_instruments ADD CONSTRAINT musicians_instruments_instrument_id_fkey FOREIGN KEY (instrument_id) REFERENCES instruments(id) ON DELETE CASCADE;
ALTER TABLE recorded_tracks ADD CONSTRAINT saved_tracks_instrument_id_fkey FOREIGN KEY (instrument_id) REFERENCES instruments(id) ON DELETE CASCADE;

INSERT INTO instruments (id, description, popularity) VALUES ('steel guitar', 'Steel Guitar', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('orchestra', 'Orchestra', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('glockenspiel', 'Glockenspiel', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('dobro', 'Dobro', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('harp', 'Harp', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('vocoder', 'Vocoder', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('flugelhorn', 'Flugelhorn', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('timpani', 'Timpani', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('bassoon', 'Bassoon', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('charango', 'Charango', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('theremin', 'Theremin', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('sitar', 'Sitar', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('piccolo', 'Piccolo', 1);
INSERT INTO instruments (id, description, popularity) VALUES ('bagpipes', 'Bagpipes', 1);
ALTER TABLE jam_tracks ADD COLUMN onboarding_exceptions JSON;
ALTER TABLE jam_track_tracks ADD COLUMN original_filename VARCHAR;
ALTER TABLE jam_tracks ADD COLUMN additional_info VARCHAR;
ALTER TABLE jam_tracks ADD COLUMN language VARCHAR NOT NULL DEFAULT 'eng';
ALTER TABLE jam_tracks ADD COLUMN year INTEGER;
ALTER TABLE jam_tracks ADD COLUMN vendor_id VARCHAR;

INSERT INTO jam_track_licensors (name, description) VALUES ('Tency Music', 'Tency Music is a music production company specialized in re-recordings.');

CREATE TABLE genres_jam_tracks (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
  jam_track_id VARCHAR(64) NOT NULL REFERENCES jam_tracks(id) ON DELETE CASCADE,
  genre_id VARCHAR(64) NOT NULL REFERENCES genres(id) ON DELETE CASCADE,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO genres_jam_tracks (jam_track_id, genre_id)  ((SELECT jam_tracks.id, jam_tracks.genre_id FROM jam_tracks));
ALTER TABLE jam_tracks DROP COLUMN genre_id;

-- holds precount, click.wav, click.txt
CREATE TABLE jam_track_files (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
  jam_track_id VARCHAR(64) REFERENCES jam_tracks(id) ON DELETE CASCADE,
  file_type VARCHAR NOT NULL,
  original_filename VARCHAR NOT NULL,
  precount_num INTEGER,
  url VARCHAR,
  md5 VARCHAR,
  length bigint,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO genres (id, description) VALUES ('soft rock', 'Soft Rock');
INSERT INTO genres (id, description) VALUES ('rap', 'Rap');
INSERT INTO genres (id, description) VALUES ('tv & movie soundtrack', 'TV & Movie Soundtrack');
INSERT INTO genres (id, description) VALUES ('holiday', 'Holiday');
INSERT INTO genres (id, description) VALUES ('kids', 'Kids');
INSERT INTO genres (id, description) VALUES ('disco', 'Disco');
INSERT INTO genres (id, description) VALUES ('soul', 'Soul');
INSERT INTO genres (id, description) VALUES ('hard rock', 'Hard Rock');
INSERT INTO genres (id, description) VALUES ('funk', 'Funk');
INSERT INTO genres (id, description) VALUES ('dance', 'Dance');
INSERT INTO genres (id, description) VALUES ('creole', 'Creole');
INSERT INTO genres (id, description) VALUES ('traditional', 'Traditional');
INSERT INTO genres (id, description) VALUES ('oldies', 'Oldies');
INSERT INTO genres (id, description) VALUES ('world', 'World');
INSERT INTO genres (id, description) VALUES ('musical', 'Musical');
INSERT INTO genres (id, description) VALUES ('celtic', 'Celtic');
