CREATE TABLE download_trackers (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
  user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE,
  remote_ip VARCHAR(400) NOT NULL,
  jam_track_id VARCHAR (64) NOT NULL REFERENCES jam_tracks(id) ON DELETE CASCADE,
  paid BOOLEAN NOT NULL DEFAULT FALSE,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX index_download_trackers_on_user_id ON download_trackers USING btree (user_id);
CREATE INDEX index_download_trackers_on_remote_ip ON download_trackers USING btree (remote_ip);
CREATE INDEX index_download_trackers_on_created_at ON download_trackers USING btree (created_at, paid);


CREATE TABLE ip_blacklists (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
  remote_ip VARCHAR(400) UNIQUE NOT NULL,
  notes VARCHAR,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);


CREATE TABLE user_blacklists (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
  user_id VARCHAR(64) UNIQUE NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  notes VARCHAR,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);