-- Create the "current" table and a useful index
CREATE TABLE IF NOT EXISTS "current" (
  id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  ep_num INTEGER NOT NULL,
  ep_title TEXT NOT NULL,
  season_name TEXT NOT NULL,
  start_time TIME NOT NULL,
  playback_length INTERVAL NOT NULL,
  current_ep BOOLEAN NOT NULL DEFAULT FALSE,
  date_created TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS current_date_created_idx
  ON "current" (date_created DESC);

-- Archive table (no identity; just store the id from "current")
CREATE TABLE IF NOT EXISTS current_archive (
  id BIGINT NOT NULL,
  ep_num INTEGER NOT NULL,
  ep_title TEXT NOT NULL,
  season_name TEXT NOT NULL,
  start_time TIME NOT NULL,
  playback_length INTERVAL NOT NULL,
  current_ep BOOLEAN NOT NULL DEFAULT FALSE,
  date_created TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  date_archived TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  CONSTRAINT current_archive_pkey PRIMARY KEY (id)
);