User library-supporting tables.
This commit is contained in:
parent
826269619f
commit
af20b3ac25
1 changed files with 39 additions and 5 deletions
|
|
@ -1,6 +1,6 @@
|
|||
-- @up
|
||||
|
||||
create table library_books (
|
||||
create table books (
|
||||
id integer primary key autoincrement,
|
||||
isbn integer default 0 not null,
|
||||
-- ISBN-10 check digit. If it is the maximum allowable value in the base-11 format (i.e. the ISBN-10 ends with "X") this will be "1".
|
||||
|
|
@ -11,8 +11,18 @@ create table library_books (
|
|||
);
|
||||
create unique index library_books_isbn_check_idx on library_books(isbn, isbn_check);
|
||||
|
||||
create table library (
|
||||
id integer primary key autoincrement,
|
||||
bookid integer,
|
||||
chatid integer,
|
||||
available boolean default true not null,
|
||||
|
||||
foreign key bookid references books(id)
|
||||
)
|
||||
create unique index bookid_chatid_library_idx on library(bookid, chatid);
|
||||
|
||||
create table library_checkout (
|
||||
bookid integer default 0 not null,
|
||||
libraryid integer default 0 not null,
|
||||
-- Checkout user, if available.
|
||||
userid integer default null,
|
||||
|
||||
|
|
@ -24,12 +34,12 @@ create table library_checkout (
|
|||
returned_at datetime default null,
|
||||
|
||||
foreign key (userid) references users(id),
|
||||
foreign key (bookid) references library_books(id)
|
||||
foreign key (libraryid) references library(id)
|
||||
);
|
||||
|
||||
-- The queue table contains individuals waiting in the queue for a book that is
|
||||
-- currently loaned out.
|
||||
create table library_queue(
|
||||
create table library_queue (
|
||||
bookid integer default 0 not null,
|
||||
userid integer default null,
|
||||
requester text default '' not null,
|
||||
|
|
@ -38,4 +48,28 @@ create table library_queue(
|
|||
foreign key (userid) references users(id)
|
||||
|
||||
);
|
||||
create index library_queue_bookid_idx on library_queue (bookid);
|
||||
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.
|
||||
json_response text default '' not null,
|
||||
);
|
||||
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)');
|
||||
Loading…
Reference in a new issue