add triggers for follows table, lowercase username index
This commit is contained in:
parent
2c7990ff09
commit
5aa7a64354
2 changed files with 15 additions and 4 deletions
|
@ -41,8 +41,7 @@ create table if not exists watch_quests (
|
||||||
foreign key (watch) references watches (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
|
-- friend lists; created by trigger at the same time as the user, so no created_at needed
|
||||||
-- TODO: look into replacing sqlite with https://www.cozodb.org/
|
|
||||||
create table if not exists follows (
|
create table if not exists follows (
|
||||||
user blob not null primary key,
|
user blob not null primary key,
|
||||||
follows blob, -- possibly empty friends list in some app-specific format
|
follows blob, -- possibly empty friends list in some app-specific format
|
||||||
|
@ -51,18 +50,18 @@ create table if not exists follows (
|
||||||
);
|
);
|
||||||
|
|
||||||
create table if not exists watch_notes (
|
create table if not exists watch_notes (
|
||||||
id blob not null primary key,
|
|
||||||
user blob not null,
|
user blob not null,
|
||||||
watch blob not null,
|
watch blob not null,
|
||||||
note blob,
|
note blob,
|
||||||
public boolean not null,
|
public boolean not null,
|
||||||
|
created_at int not null default (unixepoch()),
|
||||||
last_updated int not null default (unixepoch()),
|
last_updated int not null default (unixepoch()),
|
||||||
foreign key (user) references users (id) on delete cascade on update no action,
|
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
|
foreign key (watch) references watches (id) on delete cascade on update no action
|
||||||
);
|
);
|
||||||
|
|
||||||
-- indices, not needed for follows
|
-- indices, not needed for follows
|
||||||
create index if not exists user_username_dex on users (username);
|
create index if not exists user_username_dex on users (lower(username));
|
||||||
create index if not exists user_email_dex on users (lower(email));
|
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 watch_title_dex on watches (lower(title));
|
||||||
create index if not exists watch_added_by_dex on watches (added_by);
|
create index if not exists watch_added_by_dex on watches (added_by);
|
||||||
|
|
|
@ -5,6 +5,18 @@ BEGIN
|
||||||
update users set last_updated = (select unixepoch()) where id=NEW.id;
|
update users set last_updated = (select unixepoch()) where id=NEW.id;
|
||||||
END;
|
END;
|
||||||
|
|
||||||
|
create trigger if not exists insert_user_follows
|
||||||
|
after insert on users
|
||||||
|
BEGIN
|
||||||
|
insert into follows (user) values (NEW.id);
|
||||||
|
END;
|
||||||
|
|
||||||
|
create trigger if not exists delete_user_follows
|
||||||
|
after delete on users
|
||||||
|
BEGIN
|
||||||
|
delete from follows where user = OLD.id;
|
||||||
|
END;
|
||||||
|
|
||||||
create trigger if not exists update_last_updated_watches
|
create trigger if not exists update_last_updated_watches
|
||||||
after update on watches
|
after update on watches
|
||||||
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
||||||
|
|
Loading…
Reference in a new issue