update db schema to use real datetime
This commit is contained in:
parent
714274659e
commit
51427ecdb5
4 changed files with 17 additions and 21 deletions
|
@ -3,11 +3,11 @@ create table if not exists users (
|
|||
username text not null unique,
|
||||
displayname text,
|
||||
email text,
|
||||
last_seen int,
|
||||
last_seen datetime,
|
||||
pwhash blob not null,
|
||||
invited_by blob not null,
|
||||
is_active boolean not null default true,
|
||||
last_updated int not null default (unixepoch()),
|
||||
last_updated datetime not null default CURRENT_TIMESTAMP,
|
||||
foreign key (invited_by) references users (id)
|
||||
);
|
||||
create index if not exists users_username_dex on users (lower(username));
|
||||
|
@ -18,16 +18,16 @@ create trigger if not exists update_last_updated_users
|
|||
after update on users
|
||||
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
||||
BEGIN
|
||||
update users set last_updated = (select unixepoch()) where id=NEW.id;
|
||||
update users set last_updated = CURRENT_TIMESTAMP where id=NEW.id;
|
||||
END;
|
||||
|
||||
-- invitations
|
||||
create table if not exists invites (
|
||||
id blob not null primary key default (julid_new()),
|
||||
owner blob not null,
|
||||
expires_at int,
|
||||
expires_at datetime,
|
||||
remaining int not null default 1,
|
||||
last_updated int not null default (unixepoch()),
|
||||
last_updated datetime not null default CURRENT_TIMESTAMP,
|
||||
foreign key (owner) references users (id) on delete cascade on update no action
|
||||
);
|
||||
create index if not exists invites_owner_dex on invites (owner);
|
||||
|
@ -36,6 +36,6 @@ create trigger if not exists update_last_updated_invites
|
|||
after update on invites
|
||||
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
|
||||
BEGIN
|
||||
update invites set last_updated = (select unixepoch()) where id=NEW.id;
|
||||
update invites set last_updated = CURRENT_TIMESTAMP where id=NEW.id;
|
||||
END;
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ create table if not exists watches (
|
|||
title text not null,
|
||||
metadata_url text, -- possible url for imdb or other metadata-esque site to show the user
|
||||
length int,
|
||||
release_date int,
|
||||
release_date datetime,
|
||||
added_by blob not null, -- ID of the user that added it
|
||||
last_updated int not null default (unixepoch()),
|
||||
last_updated datetime not null default CURRENT_TIMESTAMP,
|
||||
foreign key (added_by) references users (id)
|
||||
);
|
||||
create index if not exists watches_title_dex on watches (lower(title));
|
||||
|
@ -16,7 +16,7 @@ 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;
|
||||
update watches set last_updated = CURRENT_TIMESTAMP where id=NEW.id;
|
||||
END;
|
||||
|
||||
-- table of what people want to watch
|
||||
|
@ -27,8 +27,8 @@ create table if not exists watch_quests (
|
|||
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()),
|
||||
created_at datetime not null default CURRENT_TIMESTAMP,
|
||||
last_updated datetime not null default CURRENT_TIMESTAMP,
|
||||
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)
|
||||
|
@ -40,7 +40,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 watch=NEW.watch and user=NEW.user;
|
||||
update watch_quests set last_updated = CURRENT_TIMESTAMP where watch=NEW.watch and user=NEW.user;
|
||||
END;
|
||||
|
||||
-- notes on stuff to watch
|
||||
|
@ -50,7 +50,7 @@ create table if not exists watch_notes (
|
|||
watch blob not null,
|
||||
note blob,
|
||||
public boolean not null,
|
||||
last_updated int not null default (unixepoch()),
|
||||
last_updated datetime not null default CURRENT_TIMESTAMP,
|
||||
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
|
||||
);
|
||||
|
@ -61,5 +61,5 @@ 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;
|
||||
update watch_notes set last_updated = CURRENT_TIMESTAMP where id=NEW.id;
|
||||
END;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
create table if not exists follows (
|
||||
follower blob not null,
|
||||
followee blob not null,
|
||||
created_at int not null default (unixepoch()),
|
||||
created_at datetime not null default CURRENT_TIMESTAMP,
|
||||
foreign key (follower) references users (id) on delete cascade on update no action,
|
||||
foreign key (followee) references users (id) on delete cascade on update no action,
|
||||
unique (follower, followee)
|
||||
|
|
|
@ -81,12 +81,8 @@ impl Debug for User {
|
|||
impl Display for User {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let uname = &self.username;
|
||||
let dname = if let Some(ref n) = self.displayname {
|
||||
n
|
||||
} else {
|
||||
""
|
||||
};
|
||||
let email = if let Some(ref e) = self.email { e } else { "" };
|
||||
let dname = self.displayname.as_deref().unwrap_or("");
|
||||
let email = self.email.as_deref().unwrap_or("");
|
||||
write!(f, "Username: {uname}\nDisplayname: {dname}\nEmail: {email}")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue