2023-04-27 00:08:49 +00:00
|
|
|
-- note: sqlite-specific migration due to the types of the columns
|
2023-04-27 21:21:29 +00:00
|
|
|
-- When used for an ID, a blob is a UUID in byte form, or a vector of those like for friends list.
|
|
|
|
-- Otherwise, for content, a blob is just binary data, possibly representing UTF-8 text.
|
|
|
|
-- Dates are ints, unix epoch style
|
2023-04-27 00:08:49 +00:00
|
|
|
|
|
|
|
-- users
|
|
|
|
create table if not exists witches (
|
|
|
|
id blob not null primary key,
|
2023-05-12 19:08:18 +00:00
|
|
|
username text not null unique,
|
|
|
|
displayname text,
|
2023-04-27 00:56:11 +00:00
|
|
|
email text,
|
2023-05-12 22:36:19 +00:00
|
|
|
last_seen int,
|
|
|
|
pwhash blob not null,
|
2023-04-27 22:22:49 +00:00
|
|
|
created_at int not null default (unixepoch()),
|
|
|
|
last_updated int not null default (unixepoch())
|
2023-04-27 00:08:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
-- table of things to watch
|
|
|
|
create table if not exists watches (
|
|
|
|
id blob not null primary key,
|
2023-04-27 00:56:11 +00:00
|
|
|
typ 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
|
2023-04-27 22:22:49 +00:00
|
|
|
created_at int not null default (unixepoch()),
|
2023-06-05 23:32:42 +00:00
|
|
|
last_updated int not null default (unixepoch()),
|
|
|
|
foreign key (added_by) references witches (id)
|
2023-04-27 00:08:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
-- table of what people want to watch
|
|
|
|
create table if not exists witch_watch (
|
|
|
|
id blob not null primary key,
|
|
|
|
witch blob not null,
|
|
|
|
watch blob not null,
|
2023-04-27 21:21:29 +00:00
|
|
|
party blob, -- list of witch IDs, but we can also scan for friends that want to watch the same thing
|
|
|
|
priority int, -- 1-5 how much do you want to watch it
|
2023-04-27 00:08:49 +00:00
|
|
|
public boolean not null,
|
|
|
|
watched boolean not null,
|
2023-04-27 21:21:29 +00:00
|
|
|
when_added int,
|
|
|
|
when_watched int,
|
2023-04-27 22:22:49 +00:00
|
|
|
created_at int not null default (unixepoch()),
|
|
|
|
last_updated int not null default (unixepoch()),
|
2023-04-27 00:08:49 +00:00
|
|
|
foreign key (witch) references witches (id) on delete cascade on update no action,
|
|
|
|
foreign key (watch) references watches (id) on delete cascade on update no action
|
|
|
|
);
|
|
|
|
|
|
|
|
-- friend lists; this should really be a graph db, maybe the whole thing should be
|
2023-04-27 00:56:11 +00:00
|
|
|
-- TODO: look into replacing sqlite with https://www.cozodb.org/
|
2023-04-27 00:08:49 +00:00
|
|
|
create table if not exists covens (
|
|
|
|
witch blob not null primary key,
|
2023-04-27 00:56:11 +00:00
|
|
|
coven blob, -- possibly empty friends list in some app-specific format
|
2023-04-27 22:22:49 +00:00
|
|
|
created_at int not null default (unixepoch()),
|
|
|
|
last_updated int not null default (unixepoch()),
|
2023-04-27 00:08:49 +00:00
|
|
|
foreign key (witch) references witches (id) on delete cascade on update no action
|
|
|
|
);
|
|
|
|
|
2023-04-27 21:21:29 +00:00
|
|
|
create table if not exists watch_notes (
|
|
|
|
id blob not null primary key,
|
|
|
|
witch blob not null,
|
|
|
|
watch blob not null,
|
|
|
|
note blob,
|
|
|
|
public boolean not null,
|
2023-04-27 22:22:49 +00:00
|
|
|
created_at int not null default (unixepoch()),
|
|
|
|
last_updated int not null default (unixepoch()),
|
2023-04-27 21:21:29 +00:00
|
|
|
foreign key (witch) references witches (id) on delete cascade on update no action,
|
|
|
|
foreign key (watch) references watches (id) on delete cascade on update no action
|
|
|
|
);
|
|
|
|
|
2023-04-27 00:08:49 +00:00
|
|
|
-- indices, not needed for covens
|
2023-05-15 03:33:36 +00:00
|
|
|
create index if not exists witch_dex on witches ( username, email );
|
2023-06-05 23:32:42 +00:00
|
|
|
create index if not exists watch_dex on watches ( title, length, release_date, added_by );
|
2023-04-27 21:21:29 +00:00
|
|
|
create index if not exists ww_dex on witch_watch ( witch, watch, public );
|
|
|
|
create index if not exists note_dex on watch_notes ( witch, watch, public );
|