what2watch/migrations/20230426221940_init.up.sql

72 lines
2.8 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
-- 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
2023-07-09 04:21:12 +00:00
create table if not exists users (
2023-04-27 00:08:49 +00:00
id blob not null primary key,
2023-05-12 19:08:18 +00:00
username text not null unique,
displayname text,
email text,
2023-05-12 22:36:19 +00:00
last_seen int,
pwhash blob not null,
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-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,
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
);
-- 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,
priority int, -- 1-5 how much do you want to watch it
public boolean not null default true,
watched boolean not null default false,
when_watched int,
created_at int not null default (unixepoch()),
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,
foreign key (watch) references watches (id) on delete cascade on update no action
);
2023-04-27 00:08:49 +00:00
-- friend lists; created by trigger at the same time as the user, so no created_at needed
2023-07-09 05:00:26 +00:00
create table if not exists follows (
2023-07-09 04:21:12 +00:00
user blob not null primary key,
2023-07-09 05:00:26 +00:00
follows blob, -- possibly empty friends list in some app-specific format
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 00:08:49 +00:00
);
create table if not exists watch_notes (
2023-07-09 04:21:12 +00:00
user blob not null,
watch blob not null,
note blob,
public boolean not null,
created_at int not null default (unixepoch()),
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,
foreign key (watch) references watches (id) on delete cascade on update no action
);
2023-07-09 05:00:26 +00:00
-- indices, not needed for follows
create index if not exists user_username_dex on users (lower(username));
2023-07-10 18:15:24 +00:00
create index if not exists user_email_dex on users (lower(email));
create index if not exists watch_title_dex on watches (lower(title));
2023-06-25 18:00:33 +00:00
create index if not exists watch_added_by_dex on watches (added_by);
2023-07-09 05:00:26 +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-07-09 04:21:12 +00:00
create index if not exists note_user_dex on watch_notes (user);
2023-06-25 18:00:33 +00:00
create index if not exists note_watch_dex on watch_notes (watch);