-- extensions
CREATE EXTENSION IF NOT EXISTS "plv8" SCHEMA pg_catalog;
CREATE EXTENSION IF NOT EXISTS "pg_cron" SCHEMA pg_catalog;
CREATE EXTENSION IF NOT EXISTS "pg_net" SCHEMA extensions;

-- request ID is inserted by first cron job, then a trigger handles
-- insertion of response.
CREATE TABLE IF NOT EXISTS raw_bus_positions (
  id BIGINT GENERATED ALWAYS AS IDENTITY,
  request_id INT NOT NULL,
  created TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
  response_status INT NULL,
  response_json JSONB NULL
);
