2023-04-27 00:08:49 +00:00
|
|
|
-- table of things to watch
|
|
|
|
create table if not exists watches (
|
2023-07-27 00:10:52 +00:00
|
|
|
id blob not null primary key default (julid_new()),
|
2023-06-16 00:00:45 +00:00
|
|
|
kind int not null, -- enum for movie or tv show or whatev
|
2023-04-27 00:08:49 +00:00
|
|
|
title text not null,
|
2023-06-05 23:32:42 +00:00
|
|
|
metadata_url text, -- possible url for imdb or other metadata-esque site to show the user
|
|
|
|
length int,
|
2023-04-27 21:21:29 +00:00
|
|
|
release_date int,
|
2023-06-05 23:32:42 +00:00
|
|
|
added_by blob not null, -- ID of the user that added it
|
|
|
|
last_updated int not null default (unixepoch()),
|
2023-07-09 04:21:12 +00:00
|
|
|
foreign key (added_by) references users (id)
|
2023-04-27 00:08:49 +00:00
|
|
|
);
|
2024-01-15 23:11:39 +00:00
|
|
|
create index if not exists watches_title_dex on watches (lower(title));
|
2023-04-27 00:08:49 +00:00
|
|
|
|
2024-01-17 04:21:38 +00:00
|
|
|
create trigger if not exists update_last_updated_watches
|
|
|
|
after update on watches
|
|
|
|
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
|
|
|
BEGIN
|
|
|
|
update watches set last_updated = (select unixepoch()) where id=NEW.id;
|
|
|
|
END;
|
|
|
|
|
2023-04-27 00:08:49 +00:00
|
|
|
-- table of what people want to watch
|
2023-07-09 05:00:26 +00:00
|
|
|
create table if not exists watch_quests (
|
2023-07-09 04:21:12 +00:00
|
|
|
user blob not null,
|
2023-04-27 00:08:49 +00:00
|
|
|
watch blob not null,
|
2023-04-27 21:21:29 +00:00
|
|
|
priority int, -- 1-5 how much do you want to watch it
|
2023-07-08 20:16:05 +00:00
|
|
|
public boolean not null default true,
|
|
|
|
watched boolean not null default false,
|
2023-04-27 21:21:29 +00:00
|
|
|
when_watched int,
|
2023-07-15 00:13:31 +00:00
|
|
|
created_at int not null default (unixepoch()),
|
2023-04-27 22:22:49 +00:00
|
|
|
last_updated int not null default (unixepoch()),
|
2023-07-09 04:21:12 +00:00
|
|
|
foreign key (user) references users (id) on delete cascade on update no action,
|
2023-07-18 17:26:16 +00:00
|
|
|
foreign key (watch) references watches (id) on delete cascade on update no action,
|
|
|
|
primary key (user, watch)
|
2023-07-15 00:13:31 +00:00
|
|
|
);
|
2024-01-15 23:11:39 +00:00
|
|
|
create index if not exists quests_user_dex on watch_quests (user);
|
|
|
|
create index if not exists quests_watch_dex on watch_quests (watch);
|
2023-04-27 00:08:49 +00:00
|
|
|
|
2024-01-17 04:21:38 +00:00
|
|
|
create trigger if not exists update_last_updated_watch_quests
|
|
|
|
after update on watch_quests
|
|
|
|
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
|
|
|
BEGIN
|
|
|
|
update watch_quests set last_updated = (select unixepoch()) where watch=NEW.watch and user=NEW.user;
|
|
|
|
END;
|
2023-04-27 00:08:49 +00:00
|
|
|
|
2024-01-17 04:21:38 +00:00
|
|
|
-- notes on stuff to watch
|
2023-04-27 21:21:29 +00:00
|
|
|
create table if not exists watch_notes (
|
2023-07-27 00:10:52 +00:00
|
|
|
id blob not null primary key default (julid_new()), -- a user can have multiple notes about the same thing
|
2023-07-09 04:21:12 +00:00
|
|
|
user blob not null,
|
2023-04-27 21:21:29 +00:00
|
|
|
watch blob not null,
|
|
|
|
note blob,
|
|
|
|
public boolean not null,
|
2023-04-27 22:22:49 +00:00
|
|
|
last_updated int not null default (unixepoch()),
|
2023-07-09 04:21:12 +00:00
|
|
|
foreign key (user) references users (id) on delete cascade on update no action,
|
2023-04-27 21:21:29 +00:00
|
|
|
foreign key (watch) references watches (id) on delete cascade on update no action
|
|
|
|
);
|
2023-07-18 17:26:16 +00:00
|
|
|
create index if not exists notes_user_dex on watch_notes (user);
|
|
|
|
create index if not exists notes_watch_dex on watch_notes (watch);
|
2024-01-15 23:11:39 +00:00
|
|
|
|
2024-01-17 04:21:38 +00:00
|
|
|
create trigger if not exists update_last_updated_watch_notes
|
|
|
|
after update on watch_notes
|
|
|
|
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
|
|
|
BEGIN
|
|
|
|
update watch_notes set last_updated = (select unixepoch()) where id=NEW.id;
|
|
|
|
END;
|