fix migration to 1) account for long trigger names and 2) correct syntax for dropping function without arguments in pg < 10

GitOrigin-RevId: b5382db23dcf8c05a9936404b8ab303a336c8a44
This commit is contained in:
Tirumarai Selvan A 2020-11-23 13:13:04 +05:30 committed by hasura-bot
parent 06ab0e537b
commit 6fe5daa702

View File

@ -37,17 +37,17 @@ WITH valid_event_triggers AS (
) )
SELECT routine_name FROM information_schema.routines SELECT routine_name FROM information_schema.routines
WHERE routine_type='FUNCTION' AND specific_schema='hdb_views' AND routine_name NOT IN ( WHERE routine_type='FUNCTION' AND specific_schema='hdb_views' AND routine_name NOT IN (
SELECT 'notify_hasura_' || name || '_INSERT' FROM valid_event_triggers SELECT left('notify_hasura_' || name || '_INSERT', 63) FROM valid_event_triggers -- trigger names are truncated to 63 chars
UNION UNION
SELECT 'notify_hasura_' || name || '_UPDATE' FROM valid_event_triggers SELECT left('notify_hasura_' || name || '_UPDATE', 63) FROM valid_event_triggers
UNION UNION
select 'notify_hasura_' || name || '_DELETE' FROM valid_event_triggers select left('notify_hasura_' || name || '_DELETE', 63) FROM valid_event_triggers
); );
DO $$ DECLARE DO $$ DECLARE
r RECORD; r RECORD;
BEGIN BEGIN
FOR r IN (SELECT routine_name from invalid_triggers) LOOP FOR r IN (SELECT routine_name from invalid_triggers) LOOP
EXECUTE 'DROP FUNCTION IF EXISTS hdb_views.' || quote_ident(r.routine_name) || ' CASCADE'; EXECUTE 'DROP FUNCTION IF EXISTS hdb_views.' || quote_ident(r.routine_name) || '() CASCADE'; -- without '()' here, PG < 10 will throw error
END LOOP; END LOOP;
END $$; END $$;