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