probably done with the db schema, next add triggers

This commit is contained in:
Joe Ardent 2023-04-27 14:21:29 -07:00
parent 394898aab2
commit 3888ba4fc7
2 changed files with 37 additions and 6 deletions

View file

@ -2,8 +2,10 @@
drop index if exists witch_dex;
drop index if exists watch_dex;
drop index if exists ww_dex;
drop index if exists note_dex;
-- tables
drop table if exists witch_watch;
drop table if exists watch_notes;
drop table if exists covens;
drop table if exists witches;
drop table if exists watches;

View file

@ -1,12 +1,17 @@
-- note: sqlite-specific migration due to the types of the columns
-- 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
-- users
create table if not exists witches (
id blob not null primary key,
last_seen int, -- date in 64-bit unix epoch
last_seen int,
name text,
email text,
secret blob not null -- encrypted password? need to figure auth out
secret blob not null, -- encrypted password? need to figure auth out
created_at int,
last_updated int
);
-- table of things to watch
@ -14,7 +19,11 @@ create table if not exists watches (
id blob not null primary key,
typ int not null, -- enum for movie or tv show or whatev
title text not null,
imdb text -- possible url for imdb or other metadata-esque site to show the user
imdb text, -- possible url for imdb or other metadata-esque site to show the user
runtime int,
release_date int,
created_at int,
last_updated int
);
-- table of what people want to watch
@ -22,9 +31,14 @@ create table if not exists witch_watch (
id blob not null primary key,
witch blob not null,
watch blob not null,
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
public boolean not null,
watched boolean not null,
notes blob, -- per-user-show notes in some app-specific format
when_added int,
when_watched int,
created_at int,
last_updated int,
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
);
@ -34,10 +48,25 @@ create table if not exists witch_watch (
create table if not exists covens (
witch blob not null primary key,
coven blob, -- possibly empty friends list in some app-specific format
created_at int,
last_updated int,
foreign key (witch) references witches (id) on delete cascade on update no action
);
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,
created_at int,
last_updated int,
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
);
-- indices, not needed for covens
create index if not exists witch_dex on witches ( name, email );
create index if not exists watch_dex on watches ( title );
create index if not exists ww_dex on witch_watch ( witch, watch );
create index if not exists watch_dex on watches ( title, runtime, release_date );
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 );