diff --git a/migrations/sqlite/0004_library.sql b/migrations/sqlite/0004_library.sql index 154b488..d1562ac 100644 --- a/migrations/sqlite/0004_library.sql +++ b/migrations/sqlite/0004_library.sql @@ -1,3 +1,5 @@ +-- @up + create table library_books ( id integer primary key autoincrement, isbn integer default 0 not null, @@ -7,4 +9,32 @@ create table library_books ( authors text default '' not null, meta jsonb default '{}' not null ); -create unique index library_books_isbn_check_idx on library_books(isbn, isbn_check); \ No newline at end of file +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) + +); \ No newline at end of file