41 lines
No EOL
1.4 KiB
SQL
41 lines
No EOL
1.4 KiB
SQL
-- @up
|
|
|
|
create table library_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".
|
|
isbn_check integer default 0 not null,
|
|
title text default '' not null,
|
|
authors text default '' not null,
|
|
meta jsonb default '{}' not null
|
|
);
|
|
create unique index library_books_isbn_check_idx on library_books(isbn, isbn_check);
|
|
|
|
create table library_checkout (
|
|
bookid integer default 0 not null,
|
|
-- 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),
|
|
foreign key (bookid) references library_books(id)
|
|
);
|
|
|
|
-- The queue table contains individuals waiting in the queue for a book that is
|
|
-- currently loaned out.
|
|
create table library_queue(
|
|
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)
|
|
|
|
);
|
|
create index library_queue_bookid_idx on library_queue (bookid); |