From df2f2dcd4686782b34f3af2e960d5fdda13e7333 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 28 Oct 2020 16:08:35 -0400 Subject: [PATCH] implement handlers table --- migrations/2020-10-28-190823_handlers/down.sql | 1 + migrations/2020-10-28-190823_handlers/up.sql | 18 ++++++++++++++++++ src/main.rs | 4 ++-- src/schema.rs | 15 +++++++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 migrations/2020-10-28-190823_handlers/down.sql create mode 100644 migrations/2020-10-28-190823_handlers/up.sql diff --git a/migrations/2020-10-28-190823_handlers/down.sql b/migrations/2020-10-28-190823_handlers/down.sql new file mode 100644 index 0000000..291a97c --- /dev/null +++ b/migrations/2020-10-28-190823_handlers/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` \ No newline at end of file diff --git a/migrations/2020-10-28-190823_handlers/up.sql b/migrations/2020-10-28-190823_handlers/up.sql new file mode 100644 index 0000000..5271903 --- /dev/null +++ b/migrations/2020-10-28-190823_handlers/up.sql @@ -0,0 +1,18 @@ +CREATE TABLE IF NOT EXISTS handlers + ( id UUID DEFAULT uuid_generate_v4() NOT NULL + , user_id UUID NOT NULL + , human_name VARCHAR NOT NULL + , current_version VARCHAR NOT NULL + , async_impl BOOLEAN DEFAULT false + , created_at TIMESTAMP NOT NULL DEFAULT NOW() + , updated_at TIMESTAMP NOT NULL DEFAULT NOW() + , PRIMARY KEY (id) + , CONSTRAINT fk_user_id + FOREIGN KEY (user_id) + REFERENCES users(id) + ); + +CREATE TRIGGER set_timestamp_handlers + BEFORE UPDATE ON handlers + FOR EACH ROW + EXECUTE PROCEDURE trigger_set_timestamp(); diff --git a/src/main.rs b/src/main.rs index 54c4a77..e279381 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,10 +100,10 @@ fn gitea_callback( user_id: user.id.clone(), }) .get_result(&*conn) - .expect("create token information"); + .map_err(api::Error::Database)?; info!("created new token for {} with id {}", user.id, tok.id); - let tok = jwt::make(user.id, tok.id).expect("to sign JWT"); + let tok = jwt::make(user.id, tok.id).map_err(api::Error::InternalServerError)?; cookies.add_private( Cookie::build("token", tok.clone()) diff --git a/src/schema.rs b/src/schema.rs index 4ac66b9..b67a783 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -9,6 +9,18 @@ table! { } } +table! { + handlers (id) { + id -> Uuid, + user_id -> Uuid, + human_name -> Varchar, + current_version -> Varchar, + async_impl -> Nullable, + created_at -> Timestamp, + updated_at -> Timestamp, + } +} + table! { tokens (id) { id -> Uuid, @@ -32,10 +44,9 @@ table! { } } -joinable!(gitea_tokens -> users (user_id)); - allow_tables_to_appear_in_same_query!( gitea_tokens, + handlers, tokens, users, );