add update triggers and default values for dates
This commit is contained in:
parent
3888ba4fc7
commit
3aa83dcbc3
3 changed files with 50 additions and 10 deletions
|
@ -10,8 +10,8 @@ create table if not exists witches (
|
|||
name text,
|
||||
email text,
|
||||
secret blob not null, -- encrypted password? need to figure auth out
|
||||
created_at int,
|
||||
last_updated int
|
||||
created_at int not null default (unixepoch()),
|
||||
last_updated int not null default (unixepoch())
|
||||
);
|
||||
|
||||
-- table of things to watch
|
||||
|
@ -22,8 +22,8 @@ create table if not exists watches (
|
|||
imdb text, -- possible url for imdb or other metadata-esque site to show the user
|
||||
runtime int,
|
||||
release_date int,
|
||||
created_at int,
|
||||
last_updated int
|
||||
created_at int not null default (unixepoch()),
|
||||
last_updated int not null default (unixepoch())
|
||||
);
|
||||
|
||||
-- table of what people want to watch
|
||||
|
@ -37,8 +37,8 @@ create table if not exists witch_watch (
|
|||
watched boolean not null,
|
||||
when_added int,
|
||||
when_watched int,
|
||||
created_at int,
|
||||
last_updated int,
|
||||
created_at int not null default (unixepoch()),
|
||||
last_updated int not null default (unixepoch()),
|
||||
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
|
||||
);
|
||||
|
@ -48,8 +48,8 @@ create table if not exists witch_watch (
|
|||
create table if not exists covens (
|
||||
witch blob not null primary key,
|
||||
coven blob, -- possibly empty friends list in some app-specific format
|
||||
created_at int,
|
||||
last_updated int,
|
||||
created_at int not null default (unixepoch()),
|
||||
last_updated int not null default (unixepoch()),
|
||||
foreign key (witch) references witches (id) on delete cascade on update no action
|
||||
);
|
||||
|
||||
|
@ -59,8 +59,8 @@ create table if not exists watch_notes (
|
|||
watch blob not null,
|
||||
note blob,
|
||||
public boolean not null,
|
||||
created_at int,
|
||||
last_updated int,
|
||||
created_at int not null default (unixepoch()),
|
||||
last_updated int not null default (unixepoch()),
|
||||
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
|
||||
);
|
||||
|
|
6
migrations/20230427212229_update_triggers.down.sql
Normal file
6
migrations/20230427212229_update_triggers.down.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
-- Add down migration script here
|
||||
drop trigger if exists update_last_updated_witches;
|
||||
drop trigger if exists update_last_updated_watches;
|
||||
drop trigger if exists update_last_updated_witch_watch;
|
||||
drop trigger if exists update_last_updated_covens;
|
||||
drop trigger if exists update_last_updated_watch_notes;
|
34
migrations/20230427212229_update_triggers.up.sql
Normal file
34
migrations/20230427212229_update_triggers.up.sql
Normal file
|
@ -0,0 +1,34 @@
|
|||
create trigger if not exists update_last_updated_witches
|
||||
after update on witches
|
||||
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
||||
BEGIN
|
||||
update witches set last_updated = (select unixepoch()) where id=NEW.id;
|
||||
END;
|
||||
|
||||
create trigger if not exists update_last_updated_watches
|
||||
after update on watches
|
||||
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
||||
BEGIN
|
||||
update watches set last_updated = (select unixepoch()) where id=NEW.id;
|
||||
END;
|
||||
|
||||
create trigger if not exists update_last_updated_witch_watch
|
||||
after update on witch_watch
|
||||
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
||||
BEGIN
|
||||
update witch_watch set last_updated = (select unixepoch()) where id=NEW.id;
|
||||
END;
|
||||
|
||||
create trigger if not exists update_last_updated_covens
|
||||
after update on covens
|
||||
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
||||
BEGIN
|
||||
update covens set last_updated = (select unixepoch()) where id=NEW.id;
|
||||
END;
|
||||
|
||||
create trigger if not exists update_last_updated_watch_notes
|
||||
after update on watch_notes
|
||||
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
||||
BEGIN
|
||||
update watch_notes set last_updated = (select unixepoch()) where id=NEW.id;
|
||||
END;
|
Loading…
Reference in a new issue