2026-11-03 22:41:44 -07:00
|
|
|
-- @up
|
|
|
|
|
|
2026-11-11 15:36:57 -07:00
|
|
|
create table library_books (
|
2026-11-02 23:03:41 -07:00
|
|
|
id integer primary key autoincrement,
|
2026-11-12 19:28:09 -07:00
|
|
|
isbn text default '' not null,
|
2026-11-02 23:03:41 -07:00
|
|
|
title text default '' not null,
|
|
|
|
|
authors text default '' not null,
|
|
|
|
|
meta jsonb default '{}' not null
|
|
|
|
|
);
|
2026-11-03 22:41:44 -07:00
|
|
|
create unique index library_books_isbn_check_idx on library_books(isbn, isbn_check);
|
|
|
|
|
|
2026-11-11 15:31:20 -07:00
|
|
|
create table library (
|
|
|
|
|
id integer primary key autoincrement,
|
|
|
|
|
bookid integer,
|
|
|
|
|
chatid integer,
|
|
|
|
|
available boolean default true not null,
|
|
|
|
|
|
2026-11-11 15:36:57 -07:00
|
|
|
foreign key (bookid) references library_books(id)
|
|
|
|
|
);
|
2026-11-11 15:31:20 -07:00
|
|
|
create unique index bookid_chatid_library_idx on library(bookid, chatid);
|
|
|
|
|
|
2026-11-03 22:41:44 -07:00
|
|
|
create table library_checkout (
|
2026-11-11 15:31:20 -07:00
|
|
|
libraryid integer default 0 not null,
|
2026-11-03 22:41:44 -07:00
|
|
|
-- Checkout user, if available.
|
|
|
|
|
userid integer default null,
|
|
|
|
|
|
|
|
|
|
-- Checkout recipient. This should only be populated if the user ID is not
|
|
|
|
|
-- present.
|
|
|
|
|
recipient text default '' not null,
|
|
|
|
|
|
|
|
|
|
checked_out datetime default current_timestamp not null,
|
|
|
|
|
returned_at datetime default null,
|
|
|
|
|
|
|
|
|
|
foreign key (userid) references users(id),
|
2026-11-11 15:31:20 -07:00
|
|
|
foreign key (libraryid) references library(id)
|
2026-11-03 22:41:44 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
-- The queue table contains individuals waiting in the queue for a book that is
|
|
|
|
|
-- currently loaned out.
|
2026-11-11 15:31:20 -07:00
|
|
|
create table library_queue (
|
2026-11-03 22:41:44 -07:00
|
|
|
bookid integer default 0 not null,
|
|
|
|
|
userid integer default null,
|
|
|
|
|
requester text default '' not null,
|
|
|
|
|
|
|
|
|
|
foreign key (bookid) references library_books(id),
|
|
|
|
|
foreign key (userid) references users(id)
|
2026-11-04 13:07:48 -07:00
|
|
|
);
|
2026-11-11 15:31:20 -07:00
|
|
|
create index library_queue_bookid_idx on library_queue (bookid);
|
|
|
|
|
|
|
|
|
|
-- OpenLibrary response cache.
|
|
|
|
|
--
|
|
|
|
|
-- 4xx status codes will be rechecked no sooner than 1 month if a user attempts
|
|
|
|
|
-- to add a book with the missing ISBN to the library.
|
|
|
|
|
--
|
|
|
|
|
-- 5xx status codes will be rechecked no sooner than 1 week if a user attempts
|
|
|
|
|
-- to add a book matching an ISBN that generated the error.
|
|
|
|
|
--
|
|
|
|
|
-- 3xx redirects are not recorded. These should resolve into 200 or an error.
|
|
|
|
|
--
|
|
|
|
|
-- 200 OK status codes will not be rechecked. JSON data will be retrieved from
|
|
|
|
|
-- this table instead of upstream.
|
|
|
|
|
create table ol_cache (
|
|
|
|
|
isbn text default '' not null,
|
|
|
|
|
response_code integer default 0 not null,
|
|
|
|
|
requested datetime default current_timestamp not null,
|
|
|
|
|
|
|
|
|
|
-- We cache the full response for later debugging, if needed.
|
2026-11-11 15:36:57 -07:00
|
|
|
json_response text default '' not null
|
2026-11-11 15:31:20 -07:00
|
|
|
);
|
|
|
|
|
create unique index ol_cache_isbn_idx on ol_cache(isbn);
|
|
|
|
|
|
|
|
|
|
insert into settings (config, value) values ('library.lookup.useragent', 'BibleBot/1.0 (contact: $contact; using go/please)');
|