CREATE TABLE jamblasters (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
  user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE SET NULL,
  serial_no VARCHAR(1000) UNIQUE,
  vtoken VARCHAR(1000) UNIQUE,
  client_id VARCHAR(64) UNIQUE,
  created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL,
  updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL
);

CREATE TABLE jamblasters_users (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
  user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  jamblaster_id VARCHAR(64) NOT NULL REFERENCES jamblasters(id) ON DELETE CASCADE,
  created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL,
  updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL
);

CREATE TABLE jamblaster_pairing_requests (
  id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL,
  user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
  jamblaster_id VARCHAR(64) NOT NULL REFERENCES jamblasters(id) ON DELETE CASCADE,
  jamblaster_client_id VARCHAR(64) NOT NULL,
  sibling_client_id VARCHAR(64) NOT NULL,
  sibling_key VARCHAR(1000) NOT NULL,
  created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL,
  updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL
);
