Lines of
rsstg.sql
from check-in 61df933942
that are changed by the sequence of edits moving toward
check-in 0191d490fe:
1: create table rsstg_updates (owner integer, update jsonb);
2:
3: create unique index rsstg_updates__id on rsstg_updates(update->>'update_id');
4:
5: -- create table rsstg_users (id integer);
6: create table rsstg_channel (
7: channel_id bigint primary key,
8: username text);
9: create unique index rsstg_channel__username on rsstg_channel(username);
10:
11: create table rsstg_source (
12: source_id serial,
13: channel_id integer not null,
14: url text not null,
15: last_fetch timestamptz,
16: last_scrape timestamptz default now(),
17: enabled boolean default false,
18: iv_hash text,
19: owner bigint not null);
20: create unique index rsstg_source__source_id on rsstg_source(source_id);
21: create unique index rsstg_source__channel_id__owner on rsstg_source(channel_id, owner);
22: create index rsstg_source__owner on rsstg_source(owner);
23:
24: create table rsstg_post (
25: source_id integer not null,
26: date int not null,
27: url text not null,
28: hour smallint generated always as (extract('hour' from posted)) stored,
29: FOREIGN KEY (source_id) REFERENCES rsstg_source(source_id)
30: );
31: create unique index rsstg_post__url on rsstg_post(url);
32: create index rsstg_post__hour on rsstg_post(hour);
33:
34: create or replace view rsstg_order as
61df933942 2020-11-18 35: select source_id, coalesce(last_scrape + make_interval(0,0,0,0,0,(60 / coalesce(activity, 1))::integer), now() - interval '1 minute') as next_fetch
36: from rsstg_source natural left join
37: (select source_id, count(*) as activity
38: from rsstg_post where
39: hour = extract('hour' from now())
40: group by source_id) as act
41: where enabled
42: order by next_fetch;