247 lines
7.9 KiB
SQL
247 lines
7.9 KiB
SQL
-- @up
|
|
|
|
create table chats (
|
|
id integer primary key,
|
|
name text not null
|
|
) strict;
|
|
insert into chats values (1, 'all chats');
|
|
|
|
create table chat_config (
|
|
chatid integer,
|
|
timezone text not null default 'America/Denver',
|
|
cron text not null default 'inherit',
|
|
scripture_daily text not null default '0 8 * * *',
|
|
scripture_daily_enable boolean not null default true,
|
|
birthdays_weekly text not null default '30 7 * * 0',
|
|
birthdays_weekly_enable boolean not null default true,
|
|
birthdays_daily text not null default '30 7 * * 1-6',
|
|
birthdays_daily_enable boolean not null default true,
|
|
foreign key (chatid) references chats(id)
|
|
);
|
|
|
|
-- Overrides settings.toml.
|
|
create table system_config (
|
|
config text not null,
|
|
value text not null,
|
|
volatile boolean default false not null,
|
|
primary key (config)
|
|
);
|
|
|
|
-- SQL-based Bible parsing.
|
|
insert into system_config values ('bible.sql.enable', 'false', true);
|
|
-- Enable SQL configuration override. Requires setting the connection DSN via an
|
|
-- environment variable (DBCONN).
|
|
insert into system_config values ('config.sql.enable', 'false', true);
|
|
insert into system_config (config, value) values ('service.method', 'webhook');
|
|
insert into system_config (config, value) values ('service.webhook.uri', 'https://example.com/bot');
|
|
insert into system_config (config, value) values ('service.webhook.port', '2020');
|
|
insert into system_config (config, value) values ('service.webhook.host', '::');
|
|
insert into system_config (config, value) values ('system.timezone', 'America/Denver');
|
|
insert into system_config (config, value) values ('translations.basedir', 'data/translations');
|
|
insert into system_config (config, value) values ('translations.active', 'bsb');
|
|
|
|
create table users (
|
|
id integer primary key,
|
|
username text not null,
|
|
firstname text not null,
|
|
lastname text default '' not null
|
|
);
|
|
create unique index users_username_idx on users(username);
|
|
create index users_firstname_idx on users(firstname);
|
|
insert into users (id, username, firstname) values (1, 'system', 'system');
|
|
|
|
-- Bible metadata.
|
|
create table translations (
|
|
id integer primary key autoincrement,
|
|
|
|
-- Translations "code" or ID. For some translations this will be 3 characters. Others may use a longer identifier.
|
|
code text not null,
|
|
|
|
short_name text not null,
|
|
|
|
-- Helloao endpoint for this translation.
|
|
api_endpoint text default "" not null,
|
|
|
|
title text not null
|
|
);
|
|
create unique index translations_code_idx on translations(code);
|
|
insert into translations (
|
|
code, short_name, api_endpoint, title
|
|
) values (
|
|
'bsb', 'BSB', '/api/BSB', 'Berean Standard Bible'
|
|
), (
|
|
'kjv', 'KJV', '/api/eng_kjv', 'King James (Authorized) Version'
|
|
);
|
|
|
|
create table verses (
|
|
id integer primary key autoincrement,
|
|
added datetime default current_timestamp not null,
|
|
translation text default 'bsb' not null,
|
|
book text not null,
|
|
chapter int not null,
|
|
verse_start int not null,
|
|
verse_stop int default 0 not null
|
|
);
|
|
create unique index verses_book_chapter_verses_idx on verses (book, chapter, verse_start, verse_stop);
|
|
|
|
create table verses_submitter (
|
|
verseid integer not null,
|
|
chatid integer not null,
|
|
submitterid integer not null,
|
|
|
|
foreign key (verseid) references verses(id),
|
|
foreign key (chatid) references chats(id),
|
|
foreign key (submitterid) references users(id),
|
|
|
|
primary key (verseid, chatid, submitterid)
|
|
);
|
|
|
|
-- Verses added to the rotation will slowly atrophy the number available in
|
|
-- `verses`. Clients should delete entries from this table once the intersection
|
|
-- of verses available and verses loaded here fully coincide.
|
|
create table verse_rotation (
|
|
verseid integer,
|
|
chatid integer,
|
|
foreign key (verseid) references verses(id),
|
|
foreign key (chatid) references chats(id)
|
|
);
|
|
create unique index verse_rotation_verseid_chatid_idx on verse_rotation (verseid, chatid);
|
|
|
|
create table verse_log (
|
|
verseid integer not null,
|
|
chatid integer not null,
|
|
posted datetime default current_timestamp not null,
|
|
|
|
foreign key (verseid) references verses(id),
|
|
foreign key (chatid) references chat(id)
|
|
);
|
|
create index verse_log_verseid_chatid_idx on verse_log (verseid, chatid);
|
|
create index verse_log_posted_idx on verse_log (posted);
|
|
|
|
create table verse_votes (
|
|
userid integer,
|
|
verseid integer,
|
|
|
|
voted_on datetime default current_timestamp not null,
|
|
|
|
foreign key (userid) references users(id),
|
|
foreign key (verseid) references verses(id),
|
|
|
|
primary key (userid, verseid)
|
|
);
|
|
|
|
create table verse_rotation_translations (
|
|
chatid integer,
|
|
verseid integer,
|
|
translationid integer not null,
|
|
votes integer default 0 not null,
|
|
|
|
foreign key (chatid) references chats(id),
|
|
foreign key (verseid) references verses(id),
|
|
foreign key (translationid) references translations(id),
|
|
|
|
primary key (chatid, verseid, translationid)
|
|
);
|
|
|
|
create table verse_rotation_translation_votes (
|
|
chatid integer,
|
|
verseid integer,
|
|
translationid integer not null,
|
|
voted_on datetime default current_timestamp not null,
|
|
|
|
foreign key (chatid) references chats(id),
|
|
foreign key (verseid) references verses(id),
|
|
foreign key (translationid) references translations(id),
|
|
|
|
primary key (chatid, verseid, translationid)
|
|
);
|
|
|
|
create table scheduled_verses (
|
|
verseid integer not null,
|
|
chatid integer not null,
|
|
translationid integer not null,
|
|
scheduled_for date not null,
|
|
|
|
foreign key (verseid) references verses(id),
|
|
foreign key (chatid) references chats(id),
|
|
foreign key (translationid) references translations(id),
|
|
|
|
primary key (verseid, chatid, translationid)
|
|
);
|
|
|
|
create table birthdays (
|
|
userid integer not null,
|
|
chatid integer not null,
|
|
|
|
month integer not null,
|
|
day integer not null,
|
|
|
|
-- If the birthday falls on a leap year and is February 29th, offer the user
|
|
-- an opportunity to apply an adjustment of either -1 (February 28th) or +1
|
|
-- (March 1st).
|
|
leap_adjust integer not null,
|
|
|
|
foreign key (userid) references users(id),
|
|
foreign key (chatid) references chats(id),
|
|
|
|
primary key (userid, chatid)
|
|
);
|
|
|
|
create table anniversaries (
|
|
id integer primary key autoincrement,
|
|
month integer not null,
|
|
day integer not null,
|
|
year integer default 0 not null,
|
|
title text defalt '' not null
|
|
);
|
|
create index anniversaries_month_day_idx on anniversaries (month, day);
|
|
|
|
create table announcements (
|
|
id integer primary key autoincrement,
|
|
scheduled_for datetime not null,
|
|
reminders boolean default true not null,
|
|
title text default '' not null,
|
|
content text default '' not null
|
|
);
|
|
|
|
-- Enable with PRAGMA foreign_keys = ON;
|
|
|
|
create table books (
|
|
id integer primary key autoincrement,
|
|
|
|
translationid integer not null,
|
|
|
|
-- 3 letter book ID/code.
|
|
code text not null,
|
|
|
|
chapter_count integer default 0 not null,
|
|
verse_count integer default 0 not null,
|
|
apocrypha boolean default false not null,
|
|
|
|
-- 0 = no Testament (apocryphal, pseudepigraphical)
|
|
-- 1 = Old Testament
|
|
-- 2 = New Testament
|
|
-- 3 = other
|
|
testament integer default 0 not null,
|
|
|
|
-- 0 = default variant reading (OT = Masoretic Text, NT = Alexandrian)
|
|
-- 1 = alternate reading #1 (OT = DSS, NT = Byzantine/Majority Text)
|
|
-- 2 = alternate reading #2 (OT = LXX, NT = Western/Latin)
|
|
variant integer default 0 not null,
|
|
|
|
foreign key (translationid) references translations(id)
|
|
);
|
|
create unique index books_code_idx on books(code);
|
|
|
|
create table chapters (
|
|
id integer primary key autoincrement,
|
|
num integer default 0 not null,
|
|
bookid integer default 0 not null,
|
|
verse_count integer default 0 not null,
|
|
|
|
-- Mapping code is used to adjust the chapter count, such as for the Septuagint. Mapping codes currently only function for adjusting the chapter count to adjust for the Masoretic Text reading.
|
|
mapping_code integer default 0 not null,
|
|
|
|
foreign key (bookid) references book(id)
|
|
);
|
|
create unique index chapters_id_num_idx on chapters(id, num);
|