-- @up -- Alter a few packaged tables. Specifically, verses are going to be applied -- globally rather than per-chat. -- Prior version did not store any birthday data. drop table if exists birthdays; create table if not exists birthdays ( id integer primary key autoincrement, -- User ID if applicable (or given). userid integer default null, chatid integer not null, name text default '' not null, month integer not null default 1 check (month >= 1 and month <= 12), -- Basic sanity checks. Application-level code will check valid values for -- each month with special handling for February birthdays. day integer not null default 1 check (day >= 1 and day <= 31), -- 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). 0 = no delta (non-leap day) or no preference (no preference -- is handled the same as -1). leap_delta integer not null check (leap_delta >= -1 or leap_delta <= 1), foreign key (userid) references users(id), foreign key (chatid) references chats(id) ); create index birthdays_chatid_idx on birthdays (chatid); create index birthdays_chatid_name_idx on birthdays (chatid, name); -- Scheduled verses are now global. drop table if exists scheduled_verses; create table if not exists scheduled_verses ( verseid integer not null, -- translationid should only be specified if the scheduled verse must derive -- from a specific translation. translationid integer default null, scheduled_for date not null, foreign key (verseid) references verses(id), foreign key (translationid) references translations(id), primary key (verseid, translationid) ); -- Remove chat ID from rotations and logs. create table verse_rotation2 ( verseid integer primary key, foreign key (verseid) references verses(id) ); insert into verse_rotation2 select verseid from verse_rotation group by verseid; drop table verse_rotation; alter table verse_rotation2 rename to verse_rotation; create table verse_log2 ( id integer not null primary key autoincrement, verseid integer not null, posted datetime default current_timestamp not null, foreign key (verseid) references verses(id) ); insert into verse_log2 (verseid, posted) select verseid, posted from verse_log group by verseid order by posted; drop table verse_log; alter table verse_log2 rename to verse_log; create index verse_log_posted_idx on verse_log (posted); -- Fix translations tables and move API data to its own. create table if not exists api_translations ( translationid integer not null primary key, servicename text default '' not null, api_endpoint text default '' not null, foreign key (translationid) references translations(id) ); insert into api_translations (translationid, api_endpoint) select id as translationid, api_endpoint from translations; update api_translations set servicename = 'helloao'; alter table translations drop column short_name; alter table translations drop column api_endpoint; alter table translations add column path text default '' not null; alter table translations add column enabled boolean default true not null; update translations set path = 'bsb' where code = 'bsb'; update translations set path = 'kjv' where code = 'kjv'; -- Remove translation metadata from verse list. alter table verses drop column translation; -- Move translation metadata to its own table. create table if not exists verse_translations ( verseid integer not null, translationid integer not null, foreign key (verseid) references verses(id), foreign key (translationid) references translations(id), primary key (verseid, translationid) ); -- Drop superfluous tables. drop table if exists verse_votes; drop table if exists verse_rotation_translations; drop table if exists verse_rotation_translation_votes; -- Update configurations and defaults. insert into system_config (config, value) values ('translations.default', 'bsb'); alter table system_config rename to settings;