Open History to see the last commit
1CREATE TABLE IF NOT EXISTS hn_items (
2 id integer PRIMARY KEY, type text NOT NULL, title text NOT NULL, url text,
3 author text, created integer NOT NULL, score integer NOT NULL DEFAULT 0,
4 comments integer NOT NULL DEFAULT 0, deleted boolean NOT NULL DEFAULT false,
5 dead boolean NOT NULL DEFAULT false, committed_at text NOT NULL
6);
7CREATE TABLE IF NOT EXISTS hn_feed_entries (
8 feed text NOT NULL CHECK (feed IN ('top','new')), item_id integer NOT NULL REFERENCES hn_items(id),
9 rank integer NOT NULL CHECK (rank > 0), PRIMARY KEY (feed,item_id)
10);
11CREATE INDEX IF NOT EXISTS hn_feed_rank ON hn_feed_entries(feed,rank,item_id);
12ALTER TABLE hn_items REPLICA IDENTITY FULL;
13ALTER TABLE hn_feed_entries REPLICA IDENTITY FULL;
14CREATE TABLE IF NOT EXISTS ingest_leases (
15 id integer PRIMARY KEY CHECK (id=1), active_owner text, active_until timestamptz,
16 active_session_end timestamptz, active_deadline timestamptz, fencing bigint NOT NULL DEFAULT 0,
17 standby_owner text, standby_until timestamptz, standby_deadline timestamptz,
18 standby_ready boolean NOT NULL DEFAULT false, heartbeat_at timestamptz
19);
20INSERT INTO ingest_leases(id) VALUES(1) ON CONFLICT DO NOTHING;
21CREATE TABLE IF NOT EXISTS ingest_status (
22 id integer PRIMARY KEY CHECK(id=1), state text NOT NULL DEFAULT 'starting',
23 checked_at timestamptz, reconciled_at timestamptz, source_event_at timestamptz,
24 committed_at timestamptz, failure_at timestamptz, failure text,
25 handoff_at timestamptz, handoff_from text, handoff_ms integer,
26 owner text, writes bigint NOT NULL DEFAULT 0
27);
28INSERT INTO ingest_status(id) VALUES(1) ON CONFLICT DO NOTHING;
29CREATE TABLE IF NOT EXISTS ingest_events (
30 id bigserial PRIMARY KEY, owner text NOT NULL, kind text NOT NULL,
31 occurred_at timestamptz NOT NULL DEFAULT clock_timestamp(), details jsonb NOT NULL DEFAULT '{}'
32);
33CREATE INDEX IF NOT EXISTS ingest_events_time ON ingest_events(occurred_at);