Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hasura Events Views #1418

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
drop view hasura.refresh_resource_type_logs;
drop view hasura.refresh_model_parameter_logs;
drop view hasura.refresh_activity_type_logs;

drop function hasura.get_event_logs(_trigger_name text);

call migrations.mark_migration_rolled_back('1');
59 changes: 59 additions & 0 deletions deployment/hasura/migrations/Aerie/1_hasura_events_views/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
create function hasura.get_event_logs(_trigger_name text)
returns table (
model_id int,
model_name text,
model_version text,
triggering_user text,
delivered boolean,
success boolean,
tries int,
created_at timestamp,
next_retry_at timestamp,
status int,
error jsonb,
error_message text,
error_type text
)
stable
security invoker
language plpgsql as $$
begin
return query (
select
(el.payload->'data'->'new'->>'id')::int as model_id,
el.payload->'data'->'new'->>'name' as model_name,
el.payload->'data'->'new'->>'version' as model_version,
el.payload->'session_variables'->>'x-hasura-user-id' as triggering_user,
el.delivered,
eil.status is not distinct from 200 as success, -- is not distinct from to catch `null`
el.tries,
el.created_at,
el.next_retry_at,
eil.status,
(eil.response -> 'data'->> 'message')::jsonb as error,
(eil.response -> 'data'->> 'message')::jsonb->>'message' as error_message,
(eil.response -> 'data'->> 'message')::jsonb->>'type' as error_type
from hdb_catalog.event_log el
join hdb_catalog.event_invocation_logs eil on el.id = eil.event_id
where trigger_name = _trigger_name);
end;
$$;
comment on function hasura.get_event_logs(_trigger_name text) is e''
'Get the logs for every run of a Hasura event with the specified trigger name.';

create view hasura.refresh_activity_type_logs as
select * from hasura.get_event_logs('refreshActivityTypes');
comment on view hasura.refresh_activity_type_logs is e''
'View containing logs for every run of the Hasura event `refreshActivityTypes`.';

create view hasura.refresh_model_parameter_logs as
select * from hasura.get_event_logs('refreshModelParameters');
comment on view hasura.refresh_model_parameter_logs is e''
'View containing logs for every run of the Hasura event `refreshModelParameters`.';

create view hasura.refresh_resource_type_logs as
select * from hasura.get_event_logs('refreshResourceTypes');
comment on view hasura.refresh_resource_type_logs is e''
'View containing logs for every run of the Hasura event `refreshResourceTypes`.';

call migrations.mark_migration_applied('1');
1 change: 1 addition & 0 deletions deployment/postgres-init-db/sql/applied_migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ This file denotes which migrations occur "before" this version of the schema.
*/

call migrations.mark_migration_applied('0');
call migrations.mark_migration_applied('1');
3 changes: 3 additions & 0 deletions deployment/postgres-init-db/sql/init_hasura.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ begin;
\ir functions/hasura/plan_branching_functions.sql
\ir functions/hasura/plan_merge_functions.sql
\ir functions/hasura/snapshot_functions.sql

-- Event Views
\ir views/hasura/hasura_event_logs.sql
end;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
create function hasura.get_event_logs(_trigger_name text)
returns table (
model_id int,
model_name text,
model_version text,
triggering_user text,
delivered boolean,
success boolean,
tries int,
created_at timestamp,
next_retry_at timestamp,
status int,
error jsonb,
error_message text,
error_type text
)
stable
security invoker
language plpgsql as $$
begin
return query (
select
(el.payload->'data'->'new'->>'id')::int as model_id,
el.payload->'data'->'new'->>'name' as model_name,
el.payload->'data'->'new'->>'version' as model_version,
el.payload->'session_variables'->>'x-hasura-user-id' as triggering_user,
el.delivered,
eil.status is not distinct from 200 as success, -- is not distinct from to catch `null`
el.tries,
el.created_at,
el.next_retry_at,
eil.status,
(eil.response -> 'data'->> 'message')::jsonb as error,
skovati marked this conversation as resolved.
Show resolved Hide resolved
(eil.response -> 'data'->> 'message')::jsonb->>'message' as error_message,
(eil.response -> 'data'->> 'message')::jsonb->>'type' as error_type
from hdb_catalog.event_log el
join hdb_catalog.event_invocation_logs eil on el.id = eil.event_id
where trigger_name = _trigger_name);
end;
$$;
comment on function hasura.get_event_logs(_trigger_name text) is e''
'Get the logs for every run of a Hasura event with the specified trigger name.';

create view hasura.refresh_activity_type_logs as
select * from hasura.get_event_logs('refreshActivityTypes');
comment on view hasura.refresh_activity_type_logs is e''
'View containing logs for every run of the Hasura event `refreshActivityTypes`.';

create view hasura.refresh_model_parameter_logs as
select * from hasura.get_event_logs('refreshModelParameters');
comment on view hasura.refresh_model_parameter_logs is e''
'View containing logs for every run of the Hasura event `refreshModelParameters`.';

create view hasura.refresh_resource_type_logs as
select * from hasura.get_event_logs('refreshResourceTypes');
comment on view hasura.refresh_resource_type_logs is e''
'View containing logs for every run of the Hasura event `refreshResourceTypes`.';