-- there are no valid recordings and mixes at this time
DELETE FROM recorded_tracks;
DELETE FROM mixes;

-- store full path to s3 bucket for mix and recorded_track

ALTER TABLE recorded_tracks ADD COLUMN url varchar(1024);

ALTER TABLE mixes ADD COLUMN url varchar(1024);

-- greater than 64 bytes come back from amazon for upload ids
ALTER TABLE recorded_tracks ALTER COLUMN upload_id TYPE varchar(1024);

-- store offset on server
ALTER TABLE recorded_tracks ADD COLUMN file_offset bigint DEFAULT 0;

-- make length be a bigint, since it can in theory be that large
ALTER TABLE recorded_tracks ALTER COLUMN length TYPE bigint;

-- store the client's track_id in addition to our own
ALTER TABLE recorded_tracks ADD COLUMN client_track_id varchar(64) NOT NULL;

-- is a part being stored
ALTER TABLE recorded_tracks ADD COLUMN is_part_uploading BOOLEAN NOT NULL DEFAULT false; 

-- track error counts for the recorded_track as whole 
ALTER TABLE recorded_tracks ADD COLUMN upload_failures int NOT NULL DEFAULT 0;

-- track error counts for the current part
ALTER TABLE recorded_tracks ADD COLUMN part_failures int NOT NULL DEFAULT 0;

-- create a auto-incrementing primary key for recorded_tracks
-- create a auto-incrementing primary key for mixes
-- and have them share the same sequence
CREATE SEQUENCE tracks_next_tracker_seq;
ALTER TABLE recorded_tracks ALTER COLUMN id DROP DEFAULT;
ALTER TABLE mixes ALTER COLUMN id DROP DEFAULT;
ALTER TABLE recorded_tracks ALTER COLUMN id TYPE BIGINT USING 0;
ALTER TABLE mixes ALTER COLUMN id TYPE BIGINT USINg 0;
ALTER TABLE recorded_tracks ALTER COLUMN id SET DEFAULT nextval('tracks_next_tracker_seq');
ALTER TABLE mixes ALTER COLUMN id SET DEFAULT nextval('tracks_next_tracker_seq');

--ALTER TABLE recorded_tracks ADD COLUMN next_tracker bigint NOT NULL DEFAULT nextval('tracks_next_tracker_seq');
--ALTER TABLE mixes ADD COLUMN next_tracker bigint NOT NULL DEFAULT nextval('tracks_next_tracker_seq');
