what2watch/migrations/20230426221940_init.up.sql

41 lines
1.4 KiB
MySQL
Raw Normal View History

2023-04-27 00:08:49 +00:00
-- note: sqlite-specific migration due to the types of the columns
-- users
create table if not exists witches (
id blob not null primary key,
last_seen int, -- date in 64-bit unix epoch
name text,
email text
);
-- table of things to watch
create table if not exists watches (
id blob not null primary key,
typ int not null, -- enum for movie or tv or whatev
title text not null,
imdb text -- possible url for imdb entry
);
-- 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,
public boolean not null,
watched boolean not null,
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
create table if not exists covens (
witch blob not null primary key,
coven blob, -- possibly empty friends list in some format the application will understand
foreign key (witch) references witches (id) on delete cascade on update no action
);
-- indices, not needed for covens
create index if not exists witch_dex on witches ( id, name, email );
create index if not exists watch_dex on watches ( id, title, typ );
create index if not exists ww_dex on witch_watch ( id, witch, watch );