use import code from main, but schema from users_with_v4_uuids

This commit is contained in:
Joe Ardent 2023-07-12 15:36:33 -07:00
parent 70cdfe1941
commit a71420fc7b
5 changed files with 26 additions and 23 deletions

View file

@ -1,14 +1,10 @@
-- indices
drop index if exists user_username_dex;
drop index if exists user_email_dex;
drop index if exists watch_title_dex;
drop index if exists witch_added_by_dex;
drop index if exists quests_user_dex;
drop index if exists quests_watch_dex;
drop index if exists note_user_dex;
drop index if exists note_watch_dex;
drop index if exists user_dex;
drop index if exists watch_dex;
drop index if exists w2wdex;
drop index if exists note_dex;
-- tables
drop table if exists watch_quests;
drop table if exists watch_quest;
drop table if exists watch_notes;
drop table if exists follows;
drop table if exists users;

View file

@ -29,24 +29,25 @@ create table if not exists watches (
-- table of what people want to watch
create table if not exists watch_quests (
id blob not null primary key,
user blob not null,
watch blob not null,
party blob, -- list of user 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 default true,
watched boolean not null default false,
when_added int not null default (unixepoch()),
public boolean not null,
watched boolean not null,
when_added int,
when_watched int,
last_updated int not null default (unixepoch()),
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,
primary key (user, watch)
) without rowid;
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
-- TODO: look into replacing sqlite with https://www.cozodb.org/
create table if not exists follows (
user blob not null primary key,
follows blob, -- possibly empty friends list in some app-specific format
coven blob, -- possibly empty friends list in some app-specific format
last_updated int not null default (unixepoch()),
foreign key (user) references users (id) on delete cascade on update no action
);
@ -64,10 +65,10 @@ create table if not exists watch_notes (
-- indices, not needed for follows
create index if not exists user_username_dex on users (username);
create index if not exists user_email_dex on users (lower(email));
create index if not exists watch_title_dex on watches (lower(title));
create index if not exists user_email_dex on users (email);
create index if not exists watch_title_dex on watches (title);
create index if not exists watch_added_by_dex on watches (added_by);
create index if not exists quests_user_dex on watch_quests (user);
create index if not exists quests_watch_dex on watch_quests (watch);
create index if not exists questswatch_dex on watch_quests (watch);
create index if not exists note_user_dex on watch_notes (user);
create index if not exists note_watch_dex on watch_notes (watch);

View file

@ -1,5 +1,5 @@
drop trigger if exists update_last_updated_users;
drop trigger if exists update_last_updated_watches;
drop trigger if exists update_last_updated_watch_quests;
drop trigger if exists update_last_updated_watch_quest;
drop trigger if exists update_last_updated_follows;
drop trigger if exists update_last_updated_watch_notes;

View file

@ -16,7 +16,7 @@ create trigger if not exists update_last_updated_watch_quests
after update on watch_quests
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
BEGIN
update watch_quests set last_updated = (select unixepoch()) where id=NEW.id;
update watch_quest set last_updated = (select unixepoch()) where id=NEW.id;
END;
create trigger if not exists update_last_updated_follows

View file

@ -52,12 +52,18 @@ impl From<&ImportMovieOmega> for Watch {
// utility functions for building CLI tools, currently just for benchmarking
//-************************************************************************
pub async fn add_watch_quests(pool: &SqlitePool, quests: &[WatchQuest]) -> Result<(), ()> {
let mut builder = sqlx::QueryBuilder::new("insert into watch_quests (user, watch) ");
let mut builder =
sqlx::QueryBuilder::new("insert into watch_quests (id, user, watch, public, watched) ");
builder.push_values(quests, |mut b, quest| {
let id = DbId::new();
let user = quest.user;
let watch = quest.watch;
//eprintln!("{user}, {watch}");
b.push_bind(user).push_bind(watch);
b.push_bind(id)
.push_bind(user)
.push_bind(watch)
.push_bind(true)
.push_bind(false);
});
let q = builder.build();