From 356afa575dbe610155af91ddc0e2cf360d22288e Mon Sep 17 00:00:00 2001 From: Jim Lambert Date: Fri, 4 Sep 2020 15:41:14 -0400 Subject: [PATCH] add insert_session() --- internal/db/migrations/postgres.gen.go | 32 +++++++++++++++++++ .../db/migrations/postgres/50_session.up.sql | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/internal/db/migrations/postgres.gen.go b/internal/db/migrations/postgres.gen.go index e89b26ef74..85728474d7 100644 --- a/internal/db/migrations/postgres.gen.go +++ b/internal/db/migrations/postgres.gen.go @@ -3439,6 +3439,38 @@ begin; before insert on session for each row execute procedure default_create_time(); + + create or replace function + insert_session() + returns trigger + as $$ + begin + case + when new.user_id is null then + raise exception 'user_id is null'; + when new.host_id is null then + raise exception 'host_id is null'; + when new.server_id is null then + raise exception 'server_id is null'; + when new.target_id is null then + raise exception 'target_id is null'; + when new.set_id is null then + raise exception 'set_id is null'; + when new.auth_token_id is null then + raise exception 'auth_token_id is null'; + when new.scope_id is null then + raise exception 'scope_id is null'; + else + end case; + return new; + end; + $$ language plpgsql; + + create trigger + insert_session + before insert on session + for each row execute procedure insert_session(); + create table session_state_enm ( name text primary key diff --git a/internal/db/migrations/postgres/50_session.up.sql b/internal/db/migrations/postgres/50_session.up.sql index 86b877ccd4..ce0ab82d73 100644 --- a/internal/db/migrations/postgres/50_session.up.sql +++ b/internal/db/migrations/postgres/50_session.up.sql @@ -186,6 +186,38 @@ begin; before insert on session for each row execute procedure default_create_time(); + + create or replace function + insert_session() + returns trigger + as $$ + begin + case + when new.user_id is null then + raise exception 'user_id is null'; + when new.host_id is null then + raise exception 'host_id is null'; + when new.server_id is null then + raise exception 'server_id is null'; + when new.target_id is null then + raise exception 'target_id is null'; + when new.set_id is null then + raise exception 'set_id is null'; + when new.auth_token_id is null then + raise exception 'auth_token_id is null'; + when new.scope_id is null then + raise exception 'scope_id is null'; + else + end case; + return new; + end; + $$ language plpgsql; + + create trigger + insert_session + before insert on session + for each row execute procedure insert_session(); + create table session_state_enm ( name text primary key