Update mgirations.

This commit is contained in:
Benjamin A. Shelton 2026-10-08 19:35:40 -06:00
commit 29d003cb63
Signed by: zancarius
GPG key ID: 8BD42DBD6C337E01

View file

@ -20,18 +20,21 @@ create table chat_config (
-- Overrides settings.toml.
create table system_config (
config text,
value text,
config text not null,
value text not null,
volatile boolean default false not null,
primary key (config)
);
insert into system_config values ('config.sql.enable', 'false');
insert into system_config values ('service.method', 'webhook');
insert into system_config values ('service.webhook.uri', 'https://example.com/bot');
insert into system_config values ('service.webhook.port', '2020');
insert into system_config values ('service.webhook.host', '::');
insert into system_config values ('system.timezone', 'America/Denver');
insert into system_config values ('translations.basedir', 'data/translations');
insert into system_config values ('translations.active', 'bsb');
-- SQL-based Bible parsing.
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,
@ -39,47 +42,6 @@ create table users (
);
insert into users values (1, 'system');
create table verses (
id integer primary key autoincrement,
submitterid integer not null default 1,
added text,
book text not null,
chapter int not null,
verse_start int not null,
verse_stop int default 0 not null,
foreign key (submitterid) references users(id)
);
create table verse_rotation (
verseid integer,
chatid integer,
count integer,
foreign key (verseid) references verses(id),
foreign key (chatid) references chats(id),
primary key (verseid, chatid)
);
create table chat_verses (
chatid integer not null,
verseid integer not null,
foreign key (chatid) references chats(id),
foreign key (verseid) references verses(id),
primary key (chatid, verseid)
);
-- Enable with PRAGMA foreign_keys = ON;
create table verse_submitters (
verseid integer,
userid integer,
foreign key (verseid) references verses(id),
foreign key (userid) references users(id),
primary key (verseid, userid)
);
-- Bible metadata.
create table translations (
id integer primary key autoincrement,
@ -87,13 +49,115 @@ create table translations (
-- 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 text,
book text not null,
chapter int not null,
verse_start int not null,
verse_stop int default 0 not null
);
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)
);
create table verse_rotation (
verseid integer,
chatid integer,
-- Indicaes how many times this verse has been used in the rotation. As
-- verses are used in any given chat, their count is incremented. Only those
-- verses with a count < MAX(count) are considered for the random rotation
-- until no more verses are found.
count integer default 0 not null,
-- Votes indicates how many times a given verse has been submitted by users
-- in the channel. This counter is only increments if the user and verse
-- identifiers are not present in `verse_votes`. The system user cannot
-- increment this value.
votes integer default 0 not null,
foreign key (verseid) references verses(id),
foreign key (chatid) references chats(id)
);
create table verse_votes (
userid integer,
verseid integer,
voted_on date default now,
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 date default now,
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)
);
-- Enable with PRAGMA foreign_keys = ON;
create table books (
id integer primary key autoincrement,