1 drop table if exists ttrss_error_log;
2 drop table if exists ttrss_plugin_storage;
3 drop table if exists ttrss_linked_feeds;
4 drop table if exists ttrss_linked_instances;
5 drop table if exists ttrss_access_keys;
6 drop table if exists ttrss_user_labels2;
7 drop table if exists ttrss_labels2;
8 drop table if exists ttrss_feedbrowser_cache;
9 drop table if exists ttrss_version;
10 drop table if exists ttrss_labels;
11 drop table if exists ttrss_filters2_rules;
12 drop table if exists ttrss_filters2_actions;
13 drop table if exists ttrss_filters2;
14 drop table if exists ttrss_filters;
15 drop table if exists ttrss_filter_types;
16 drop table if exists ttrss_filter_actions;
17 drop table if exists ttrss_user_prefs;
18 drop table if exists ttrss_prefs;
19 drop table if exists ttrss_prefs_types;
20 drop table if exists ttrss_prefs_sections;
21 drop table if exists ttrss_tags;
22 drop table if exists ttrss_enclosures;
23 drop table if exists ttrss_settings_profiles;
24 drop table if exists ttrss_entry_comments;
25 drop table if exists ttrss_user_entries;
26 drop table if exists ttrss_entries;
27 drop table if exists ttrss_scheduled_updates;
28 drop table if exists ttrss_counters_cache;
29 drop table if exists ttrss_cat_counters_cache;
30 drop table if exists ttrss_archived_feeds;
31 drop table if exists ttrss_feeds;
32 drop table if exists ttrss_feed_categories;
33 drop table if exists ttrss_users;
34 drop table if exists ttrss_themes;
35 drop table if exists ttrss_sessions;
36 drop function if exists SUBSTRING_FOR_DATE(timestamp, int, int);
40 create table ttrss_users (id serial not null primary key,
41 login varchar(120) not null unique,
42 pwd_hash varchar(250) not null,
43 last_login timestamp default null,
44 access_level integer not null default 0,
45 email varchar(250) not null default '',
46 full_name varchar(250) not null default '',
47 email_digest boolean not null default false,
48 last_digest_sent timestamp default null,
49 salt varchar(250) not null default '',
50 twitter_oauth text default null,
51 otp_enabled boolean not null default false,
52 resetpass_token varchar(250) default null,
53 created timestamp default null);
55 insert into ttrss_users (login,pwd_hash,access_level) values ('admin',
56 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', 10);
58 create table ttrss_feed_categories(id serial not null primary key,
59 owner_uid integer not null references ttrss_users(id) on delete cascade,
60 collapsed boolean not null default false,
61 order_id integer not null default 0,
62 view_settings varchar(250) not null default '',
63 parent_cat integer references ttrss_feed_categories(id) on delete set null,
64 title varchar(200) not null);
66 create table ttrss_feeds (id serial not null primary key,
67 owner_uid integer not null references ttrss_users(id) on delete cascade,
68 title varchar(200) not null,
69 cat_id integer default null references ttrss_feed_categories(id) on delete set null,
70 feed_url text not null,
71 icon_url varchar(250) not null default '',
72 update_interval integer not null default 0,
73 purge_interval integer not null default 0,
74 last_updated timestamp default null,
75 last_error text not null default '',
76 last_modified text not null default '',
77 favicon_avg_color varchar(11) default null,
78 site_url varchar(250) not null default '',
79 auth_login varchar(250) not null default '',
80 parent_feed integer default null references ttrss_feeds(id) on delete set null,
81 private boolean not null default false,
82 auth_pass varchar(250) not null default '',
83 hidden boolean not null default false,
84 include_in_digest boolean not null default true,
85 rtl_content boolean not null default false,
86 cache_images boolean not null default false,
87 hide_images boolean not null default false,
88 cache_content boolean not null default false,
89 last_viewed timestamp default null,
90 last_update_started timestamp default null,
91 update_method integer not null default 0,
92 always_display_enclosures boolean not null default false,
93 order_id integer not null default 0,
94 mark_unread_on_update boolean not null default false,
95 update_on_checksum_change boolean not null default false,
96 strip_images boolean not null default false,
97 view_settings varchar(250) not null default '',
98 pubsub_state integer not null default 0,
99 favicon_last_checked timestamp default null,
100 feed_language varchar(100) not null default '',
101 auth_pass_encrypted boolean not null default false);
103 create index ttrss_feeds_owner_uid_index on ttrss_feeds(owner_uid);
104 create index ttrss_feeds_cat_id_idx on ttrss_feeds(cat_id);
106 insert into ttrss_feeds (owner_uid, title, feed_url) values
107 (1, 'Tiny Tiny RSS: Forum', 'http://tt-rss.org/forum/rss.php');
109 create table ttrss_archived_feeds (id integer not null primary key,
110 owner_uid integer not null references ttrss_users(id) on delete cascade,
111 title varchar(200) not null,
112 feed_url text not null,
113 site_url varchar(250) not null default '');
115 create table ttrss_counters_cache (
116 feed_id integer not null,
117 owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
118 updated timestamp not null,
119 value integer not null default 0);
121 create index ttrss_counters_cache_feed_id_idx on ttrss_counters_cache(feed_id);
122 create index ttrss_counters_cache_owner_uid_idx on ttrss_counters_cache(owner_uid);
123 create index ttrss_counters_cache_value_idx on ttrss_counters_cache(value);
125 create table ttrss_cat_counters_cache (
126 feed_id integer not null,
127 owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
128 updated timestamp not null,
129 value integer not null default 0);
131 create index ttrss_cat_counters_cache_owner_uid_idx on ttrss_cat_counters_cache(owner_uid);
133 create table ttrss_entries (id serial not null primary key,
135 guid text not null unique,
137 updated timestamp not null,
138 content text not null,
139 content_hash varchar(250) not null,
141 no_orig_date boolean not null default false,
142 date_entered timestamp not null,
143 date_updated timestamp not null,
144 num_comments integer not null default 0,
145 comments varchar(250) not null default '',
147 tsvector_combined tsvector,
149 author varchar(250) not null default '');
151 -- create index ttrss_entries_title_index on ttrss_entries(title);
152 create index ttrss_entries_date_entered_index on ttrss_entries(date_entered);
153 create index ttrss_entries_updated_idx on ttrss_entries(updated);
154 create index ttrss_entries_tsvector_combined_idx on ttrss_entries using gin(tsvector_combined);
156 create table ttrss_user_entries (
157 int_id serial not null primary key,
158 ref_id integer not null references ttrss_entries(id) ON DELETE CASCADE,
159 uuid varchar(200) not null,
160 feed_id int references ttrss_feeds(id) ON DELETE CASCADE,
161 orig_feed_id integer references ttrss_archived_feeds(id) ON DELETE SET NULL,
162 owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
163 marked boolean not null default false,
164 published boolean not null default false,
165 tag_cache text not null,
166 label_cache text not null,
168 score int not null default 0,
169 last_marked timestamp,
170 last_published timestamp,
172 unread boolean not null default true);
174 -- create index ttrss_user_entries_feed_id_index on ttrss_user_entries(feed_id);
175 create index ttrss_user_entries_owner_uid_index on ttrss_user_entries(owner_uid);
176 create index ttrss_user_entries_ref_id_index on ttrss_user_entries(ref_id);
177 create index ttrss_user_entries_feed_id on ttrss_user_entries(feed_id);
178 create index ttrss_user_entries_unread_idx on ttrss_user_entries(unread);
180 create table ttrss_entry_comments (id serial not null primary key,
181 ref_id integer not null references ttrss_entries(id) ON DELETE CASCADE,
182 owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
183 private boolean not null default false,
184 date_entered timestamp not null);
186 create index ttrss_entry_comments_ref_id_index on ttrss_entry_comments(ref_id);
187 -- create index ttrss_entry_comments_owner_uid_index on ttrss_entry_comments(owner_uid);
189 create table ttrss_filter_types (id integer not null primary key,
190 name varchar(120) unique not null,
191 description varchar(250) not null unique);
193 insert into ttrss_filter_types (id,name,description) values (1, 'title', 'Title');
194 insert into ttrss_filter_types (id,name,description) values (2, 'content', 'Content');
195 insert into ttrss_filter_types (id,name,description) values (3, 'both',
197 insert into ttrss_filter_types (id,name,description) values (4, 'link',
199 insert into ttrss_filter_types (id,name,description) values (5, 'date',
201 insert into ttrss_filter_types (id,name,description) values (6, 'author', 'Author');
202 insert into ttrss_filter_types (id,name,description) values (7, 'tag', 'Article Tags');
204 create table ttrss_filter_actions (id integer not null primary key,
205 name varchar(120) unique not null,
206 description varchar(250) not null unique);
208 insert into ttrss_filter_actions (id,name,description) values (1, 'filter',
211 insert into ttrss_filter_actions (id,name,description) values (2, 'catchup',
214 insert into ttrss_filter_actions (id,name,description) values (3, 'mark',
217 insert into ttrss_filter_actions (id,name,description) values (4, 'tag',
220 insert into ttrss_filter_actions (id,name,description) values (5, 'publish',
223 insert into ttrss_filter_actions (id,name,description) values (6, 'score',
226 insert into ttrss_filter_actions (id,name,description) values (7, 'label',
229 insert into ttrss_filter_actions (id,name,description) values (8, 'stop',
230 'Stop / Do nothing');
232 insert into ttrss_filter_actions (id,name,description) values (9, 'plugin',
235 create table ttrss_filters2(id serial not null primary key,
236 owner_uid integer not null references ttrss_users(id) on delete cascade,
237 match_any_rule boolean not null default false,
238 inverse boolean not null default false,
239 title varchar(250) not null default '',
240 order_id integer not null default 0,
241 enabled boolean not null default true);
243 create table ttrss_filters2_rules(id serial not null primary key,
244 filter_id integer not null references ttrss_filters2(id) on delete cascade,
245 reg_exp varchar(250) not null,
246 inverse boolean not null default false,
247 filter_type integer not null references ttrss_filter_types(id),
248 feed_id integer references ttrss_feeds(id) on delete cascade default null,
249 cat_id integer references ttrss_feed_categories(id) on delete cascade default null,
251 cat_filter boolean not null default false);
253 create table ttrss_filters2_actions(id serial not null primary key,
254 filter_id integer not null references ttrss_filters2(id) on delete cascade,
255 action_id integer not null default 1 references ttrss_filter_actions(id) on delete cascade,
256 action_param varchar(250) not null default '');
258 create table ttrss_tags (id serial not null primary key,
259 tag_name varchar(250) not null,
260 owner_uid integer not null references ttrss_users(id) on delete cascade,
261 post_int_id integer references ttrss_user_entries(int_id) ON DELETE CASCADE not null);
263 create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid);
264 create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
266 create table ttrss_version (schema_version int not null);
268 insert into ttrss_version values (132);
270 create table ttrss_enclosures (id serial not null primary key,
271 content_url text not null,
272 content_type varchar(250) not null,
274 duration text not null,
275 width integer not null default 0,
276 height integer not null default 0,
277 post_id integer references ttrss_entries(id) ON DELETE cascade NOT NULL);
279 create index ttrss_enclosures_post_id_idx on ttrss_enclosures(post_id);
281 create table ttrss_settings_profiles(id serial not null primary key,
282 title varchar(250) not null,
283 owner_uid integer not null references ttrss_users(id) on delete cascade);
285 create table ttrss_prefs_types (id integer not null primary key,
286 type_name varchar(100) not null);
288 insert into ttrss_prefs_types (id, type_name) values (1, 'bool');
289 insert into ttrss_prefs_types (id, type_name) values (2, 'string');
290 insert into ttrss_prefs_types (id, type_name) values (3, 'integer');
292 create table ttrss_prefs_sections (id integer not null primary key,
293 order_id integer not null,
294 section_name varchar(100) not null);
296 insert into ttrss_prefs_sections (id, section_name, order_id) values (1, 'General', 0);
297 insert into ttrss_prefs_sections (id, section_name, order_id) values (2, 'Interface', 1);
298 insert into ttrss_prefs_sections (id, section_name, order_id) values (3, 'Advanced', 3);
299 insert into ttrss_prefs_sections (id, section_name, order_id) values (4, 'Digest', 2);
301 create table ttrss_prefs (pref_name varchar(250) not null primary key,
302 type_id integer not null references ttrss_prefs_types(id),
303 section_id integer not null default 1 references ttrss_prefs_sections(id),
304 access_level integer not null default 0,
305 def_value text not null);
307 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('PURGE_OLD_DAYS', 3, '60', 1);
308 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('DEFAULT_UPDATE_INTERVAL', 3, '30', 1);
309 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('DEFAULT_ARTICLE_LIMIT', 3, '30', 2);
310 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('ALLOW_DUPLICATE_POSTS', 1, 'false', 1);
311 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('ENABLE_FEED_CATS', 1, 'true', 2);
312 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('SHOW_CONTENT_PREVIEW', 1, 'true', 2);
313 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('SHORT_DATE_FORMAT', 2, 'M d, G:i', 3);
314 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('LONG_DATE_FORMAT', 2, 'D, M d Y - G:i', 3);
315 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('COMBINED_DISPLAY_MODE', 1, 'true', 2);
316 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('HIDE_READ_FEEDS', 1, 'false', 2);
317 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 2);
318 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 2);
319 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('REVERSE_HEADLINES', 1, 'false', 2);
320 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('DIGEST_ENABLE', 1, 'false', 4);
321 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('CONFIRM_FEED_CATCHUP', 1, 'true', 2);
322 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('CDM_AUTO_CATCHUP', 1, 'false', 2);
323 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_DEFAULT_VIEW_MODE', 2, 'adaptive', 1);
324 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_DEFAULT_VIEW_LIMIT', 3, '30', 1);
325 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_PREFS_ACTIVE_TAB', 2, '', 1);
326 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('STRIP_UNSAFE_TAGS', 1, 'true', 3);
327 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('BLACKLISTED_TAGS', 2, 'main, generic, misc, uncategorized, blog, blogroll, general, news', 3);
328 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('FRESH_ARTICLE_MAX_AGE', 3, '24', 2);
329 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('DIGEST_CATCHUP', 1, 'false', 4);
330 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('CDM_EXPANDED', 1, 'true', 2);
331 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('PURGE_UNREAD_ARTICLES', 1, 'true', 3);
332 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('HIDE_READ_SHOWS_SPECIAL', 1, 'true', 2);
333 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('VFEED_GROUP_BY_FEED', 1, 'false', 2);
334 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('STRIP_IMAGES', 1, 'false', 2);
335 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_DEFAULT_VIEW_ORDER_BY', 2, 'default', 1);
336 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('ENABLE_API_ACCESS', 1, 'false', 1);
337 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_COLLAPSED_SPECIAL', 1, 'false', 1);
338 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_COLLAPSED_LABELS', 1, 'false', 1);
339 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_COLLAPSED_UNCAT', 1, 'false', 1);
340 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_COLLAPSED_FEEDLIST', 1, 'false', 1);
341 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_ENABLE_CATS', 1, 'false', 1);
342 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_SHOW_IMAGES', 1, 'false', 1);
343 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_HIDE_READ', 1, 'false', 1);
344 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_SORT_FEEDS_UNREAD', 1, 'false', 1);
345 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_THEME_ID', 2, '0', 1);
346 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_TIMEZONE', 2, 'Automatic', 1);
347 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_STYLESHEET', 2, '', 2);
348 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('SORT_HEADLINES_BY_FEED_DATE', 1, 'false', 2);
349 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_BROWSE_CATS', 1, 'true', 1);
350 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('SSL_CERT_SERIAL', 2, '', 3);
351 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('DIGEST_PREFERRED_TIME', 2, '00:00', 4);
352 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_PREFS_SHOW_EMPTY_CATS', 1, 'false', 1);
353 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_DEFAULT_INCLUDE_CHILDREN', 1, 'false', 1);
354 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('AUTO_ASSIGN_LABELS', 1, 'false', 3);
355 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_ENABLED_PLUGINS', 2, '', 1);
356 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('_MOBILE_REVERSE_HEADLINES', 1, 'false', 1);
357 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_CSS_THEME', 2, '', 2);
358 insert into ttrss_prefs (pref_name,type_id,def_value,section_id) values('USER_LANGUAGE', 2, '', 2);
360 update ttrss_prefs set access_level = 1 where pref_name in ('ON_CATCHUP_SHOW_NEXT_FEED',
361 'SORT_HEADLINES_BY_FEED_DATE',
362 'VFEED_GROUP_BY_FEED',
363 'FRESH_ARTICLE_MAX_AGE',
365 'SHOW_CONTENT_PREVIEW',
366 'AUTO_ASSIGN_LABELS',
367 'HIDE_READ_SHOWS_SPECIAL');
369 create table ttrss_user_prefs (
370 owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
371 pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE,
372 profile integer references ttrss_settings_profiles(id) ON DELETE CASCADE,
373 value text not null);
375 create index ttrss_user_prefs_owner_uid_index on ttrss_user_prefs(owner_uid);
376 create index ttrss_user_prefs_pref_name_idx on ttrss_user_prefs(pref_name);
377 -- create index ttrss_user_prefs_value_index on ttrss_user_prefs(value);
379 create table ttrss_sessions (id varchar(250) not null primary key,
381 expire integer not null);
383 create index ttrss_sessions_expire_index on ttrss_sessions(expire);
385 create function SUBSTRING_FOR_DATE(timestamp, int, int) RETURNS text AS 'SELECT SUBSTRING(CAST($1 AS text), $2, $3)' LANGUAGE 'sql';
387 create table ttrss_feedbrowser_cache (
388 feed_url text not null primary key,
390 site_url text not null,
391 subscribers integer not null);
393 create table ttrss_labels2 (id serial not null primary key,
394 owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
395 fg_color varchar(15) not null default '',
396 bg_color varchar(15) not null default '',
397 caption varchar(250) not null
400 create table ttrss_user_labels2 (
401 label_id integer not null references ttrss_labels2(id) ON DELETE CASCADE,
402 article_id integer not null references ttrss_entries(id) ON DELETE CASCADE
405 create table ttrss_access_keys (id serial not null primary key,
406 access_key varchar(250) not null,
407 feed_id varchar(250) not null,
408 is_cat boolean not null default false,
409 owner_uid integer not null references ttrss_users(id) on delete cascade);
411 create table ttrss_linked_instances (id serial not null primary key,
412 last_connected timestamp not null,
413 last_status_in integer not null,
414 last_status_out integer not null,
415 access_key varchar(250) not null unique,
416 access_url text not null);
418 create table ttrss_linked_feeds (
419 feed_url text not null,
420 site_url text not null,
422 created timestamp not null,
423 updated timestamp not null,
424 instance_id integer not null references ttrss_linked_instances(id) ON DELETE CASCADE,
425 subscribers integer not null);
427 create table ttrss_plugin_storage (
428 id serial not null primary key,
429 name varchar(100) not null,
430 owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
431 content text not null);
433 create table ttrss_error_log(
434 id serial not null primary key,
435 owner_uid integer references ttrss_users(id) ON DELETE SET NULL,
436 errno integer not null,
437 errstr text not null,
438 filename text not null,
439 lineno integer not null,
440 context text not null,
441 created_at timestamp not null);