Skip to content

Commit

Permalink
RE: fixed RE of triggers when user does not have USAGE role
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalii4as committed Feb 16, 2022
1 parent 33eb1af commit cde4b0f
Showing 1 changed file with 58 additions and 23 deletions.
81 changes: 58 additions & 23 deletions reverse_engineering/helpers/queryConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,30 +282,65 @@ const queryConstants = {
GET_DATABASES:
'SELECT datname AS database_name FROM pg_catalog.pg_database WHERE datistemplate != TRUE AND datallowconn = TRUE;',
GET_TRIGGERS: `
SELECT
trigger_name,
array_agg(event_manipulation::text) AS trigger_events,
event_object_schema,
event_object_table,
action_orientation,
action_timing,
action_reference_old_table,
action_reference_new_table,
action_condition,
action_statement
FROM information_schema.triggers
SELECT trigger_name,
array_agg(event_manipulation::text) AS trigger_events,
event_object_schema,
event_object_table,
action_orientation,
action_timing,
action_reference_old_table,
action_reference_new_table,
action_condition,
action_statement
FROM
-- This is information_schema.triggers view but without permitions
(SELECT (current_database())::information_schema.sql_identifier AS trigger_catalog,
(n.nspname)::information_schema.sql_identifier AS trigger_schema,
(t.tgname)::information_schema.sql_identifier AS trigger_name,
(em.text)::information_schema.character_data AS event_manipulation,
(current_database())::information_schema.sql_identifier AS event_object_catalog,
(n.nspname)::information_schema.sql_identifier AS event_object_schema,
(c.relname)::information_schema.sql_identifier AS event_object_table,
(rank() OVER (PARTITION BY (n.nspname)::information_schema.sql_identifier,
(c.relname)::information_schema.sql_identifier,
em.num, ((t.tgtype)::integer & 1), ((t.tgtype)::integer & 66)
ORDER BY t.tgname))::information_schema.cardinal_number AS action_order,
(regexp_match(pg_get_triggerdef(t.oid), '.{35,} WHEN \((.+)\) EXECUTE FUNCTION'::text))[1]::information_schema.character_data AS action_condition,
(SUBSTRING(pg_get_triggerdef(t.oid)
FROM (POSITION(('EXECUTE FUNCTION'::text) IN (SUBSTRING(pg_get_triggerdef(t.oid)
FROM 48))) + 47)))::information_schema.character_data AS action_statement,
(CASE ((t.tgtype)::integer & 1)
WHEN 1 THEN 'ROW'::text
ELSE 'STATEMENT'::text
END)::information_schema.character_data AS action_orientation,
(CASE ((t.tgtype)::integer & 66)
WHEN 2 THEN 'BEFORE'::text
WHEN 64 THEN 'INSTEAD OF'::text
ELSE 'AFTER'::text
END)::information_schema.character_data AS action_timing,
(t.tgoldtable)::information_schema.sql_identifier AS action_reference_old_table,
(t.tgnewtable)::information_schema.sql_identifier AS action_reference_new_table,
(NULL::timestamp with time zone)::information_schema.time_stamp AS created
FROM pg_namespace n,
pg_class c,
pg_trigger t, (VALUES (4,'INSERT'::text), (8,'DELETE'::text), (16,'UPDATE'::text)) em(num, text)
WHERE ((n.oid = c.relnamespace)
AND (c.oid = t.tgrelid)
AND (((t.tgtype)::integer & em.num) <> 0)
AND (NOT t.tgisinternal)
AND (NOT pg_is_other_temp_schema(n.oid)))) AS tmp_views
WHERE event_object_schema = $1 AND event_object_table = $2
GROUP BY
trigger_schema,
trigger_name,
event_object_schema,
event_object_table,
action_orientation,
action_timing,
action_reference_old_table,
action_reference_new_table,
action_condition,
action_statement;`,
GROUP BY
trigger_schema,
trigger_name,
event_object_schema,
event_object_table,
action_orientation,
action_timing,
action_reference_old_table,
action_reference_new_table,
action_condition,
action_statement;`,
GET_TRIGGERS_ADDITIONAL_DATA: `
SELECT
pg_catalog.obj_description(pg_trigger.oid, 'pg_trigger') AS description,
Expand Down

0 comments on commit cde4b0f

Please sign in to comment.