From 65a32f1f20df6c572580d796e1044bce807fd3b6 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 26 Apr 2023 17:08:49 -0700 Subject: [PATCH] create initial db migrations --- migrations/20230426221940_init.down.sql | 10 +++++++ migrations/20230426221940_init.up.sql | 40 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 migrations/20230426221940_init.down.sql create mode 100644 migrations/20230426221940_init.up.sql diff --git a/migrations/20230426221940_init.down.sql b/migrations/20230426221940_init.down.sql new file mode 100644 index 0000000..4832342 --- /dev/null +++ b/migrations/20230426221940_init.down.sql @@ -0,0 +1,10 @@ +-- indices +drop index if exists witch_dex; +drop index if exists watch_dex; +drop index if exists ww_dex; +-- tables +drop table if exists witch_watch; +drop table if exists covens; +drop table if exists witches; +drop table if exists watches; + diff --git a/migrations/20230426221940_init.up.sql b/migrations/20230426221940_init.up.sql new file mode 100644 index 0000000..87f293c --- /dev/null +++ b/migrations/20230426221940_init.up.sql @@ -0,0 +1,40 @@ +-- 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 );