-- Add migration script here

CREATE TABLE actor (
  did VARCHAR PRIMARY KEY,
  handle VARCHAR UNIQUE,
  indexed_at VARCHAR NOT NULL
);

CREATE TABLE event (
  uri VARCHAR PRIMARY KEY,
  cid VARCHAR NOT NULL,
  organizer VARCHAR NOT NULL,

  summary VARCHAR,
  description VARCHAR,
  location VARCHAR,
  status VARCHAR,
  timezone VARCHAR,

  starts_at_original VARCHAR NOT NULL,
  starts_at TIMESTAMPTZ NOT NULL,
  ends_ats VARCHAR,

  created_at VARCHAR,
  indexed_at VARCHAR NOT NULL
);
CREATE INDEX idx_event_starts_at ON event(starts_at);

CREATE TABLE rsvp (
  uri VARCHAR PRIMARY KEY,
  cid VARCHAR NOT NULL,
  attendee VARCHAR NOT NULL,

  event_uri VARCHAR NOT NULL,
  event_cid VARCHAR NOT NULL,
  status VARCHAR NOT NULL DEFAULT 'GOING',

  indexed_at VARCHAR NOT NULL
);
CREATE INDEX idx_rsvp_event_uri ON rsvp(event_uri);
CREATE INDEX idx_rsvp_attendee_event ON rsvp(attendee, event_uri);
