diff --git a/schema/deploy/policies/graphile_worker_timestamp_policies.sql b/schema/deploy/policies/graphile_worker_timestamp_policies.sql deleted file mode 100644 index 0cdcd224dc..0000000000 --- a/schema/deploy/policies/graphile_worker_timestamp_policies.sql +++ /dev/null @@ -1,16 +0,0 @@ --- Deploy ggircs-portal:policies/graphile_worker_timestamp_policies to pg --- requires: tables/graphile_worker_timestamp - -begin; - -do -$policy$ -begin - -create policy all_select on ggircs_portal_private.graphile_worker_timestamp using (true); -create policy all_insert on ggircs_portal_private.graphile_worker_timestamp using(true) with check (true); - -end -$policy$; - -commit; diff --git a/schema/deploy/tables/graphile_worker_timestamp.sql b/schema/deploy/tables/graphile_worker_timestamp.sql deleted file mode 100644 index 00d831db68..0000000000 --- a/schema/deploy/tables/graphile_worker_timestamp.sql +++ /dev/null @@ -1,22 +0,0 @@ --- Deploy ggircs-portal:tables/graphile_worker_timestamp to pg --- requires: schema_ggircs_portal_private - -begin; - -create table ggircs_portal_private.graphile_worker_timestamp ( - id integer primary key generated always as identity, - called_at timestamptz not null -); - -grant select, insert on ggircs_portal_private.graphile_worker_timestamp to ciip_administrator; -grant select, insert on ggircs_portal_private.graphile_worker_timestamp to ciip_analyst; -grant select, insert on ggircs_portal_private.graphile_worker_timestamp to ciip_industry_user; -grant select, insert on ggircs_portal_private.graphile_worker_timestamp to ciip_guest; - -alter table ggircs_portal_private.graphile_worker_timestamp enable row level security; - -comment on table ggircs_portal_private.graphile_worker_timestamp is 'Table of timestamped calls to grahpile_worker.addjob()'; -comment on column ggircs_portal_private.graphile_worker_timestamp.id is 'Unique ID for the timestamp'; -comment on column ggircs_portal_private.graphile_worker_timestamp.called_at is 'Timestamped call time of the function'; - -commit; diff --git a/schema/revert/policies/graphile_worker_timestamp_policies.sql b/schema/revert/policies/graphile_worker_timestamp_policies.sql deleted file mode 100644 index fc5a21253d..0000000000 --- a/schema/revert/policies/graphile_worker_timestamp_policies.sql +++ /dev/null @@ -1,8 +0,0 @@ --- Revert ggircs-portal:policies/graphile_worker_timestamp_policies from pg - -BEGIN; - -drop policy all_select on ggircs_portal_private.graphile_worker_timestamp; -drop policy all_insert on ggircs_portal_private.graphile_worker_timestamp; - -COMMIT; diff --git a/schema/revert/tables/graphile_worker_timestamp.sql b/schema/revert/tables/graphile_worker_timestamp.sql deleted file mode 100644 index 93fc79d5ad..0000000000 --- a/schema/revert/tables/graphile_worker_timestamp.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Revert ggircs-portal:tables/graphile_worker_timestamp from pg - -begin; - -drop table ggircs_portal_private.graphile_worker_timestamp; - -commit; diff --git a/schema/sqitch.plan b/schema/sqitch.plan index d0c8861e40..82e994f106 100644 --- a/schema/sqitch.plan +++ b/schema/sqitch.plan @@ -138,4 +138,3 @@ trigger_functions/organisation_access_approved [trigger_functions/organisation_a trigger_functions/run_graphile_worker_job [trigger_functions/run_graphile_worker_job@v1.0.0-rc.5 schema_ggircs_portal] 2020-06-20T00:11:19Z Kristen Cooke # Adds more data to application status change and signed by certifier email jobs tables/graphile_worker_timestamp [schema_ggircs_portal_private] 2020-06-19T20:30:46Z Dylan Leard # Table tracks calls to graphile_worker.addjob() database_functions/graphile_worker_job_definer [database_functions/graphile_worker_job_definer@v1.0.0-rc.5] 2020-06-22T16:36:16Z Dylan Leard # change to graphile_worker_job_definer adds add_job() throttling -policies/graphile_worker_timestamp_policies [tables/graphile_worker_timestamp] 2020-06-22T18:21:46Z Dylan Leard # Row level security policies for graphile_worker_timestamp table diff --git a/schema/test/unit/database_functions/graphile_worker_job_definer_test.sql b/schema/test/unit/database_functions/graphile_worker_job_definer_test.sql index ccd19965da..e19622005f 100644 --- a/schema/test/unit/database_functions/graphile_worker_job_definer_test.sql +++ b/schema/test/unit/database_functions/graphile_worker_job_definer_test.sql @@ -3,86 +3,12 @@ create extension if not exists pgtap; reset client_min_messages; begin; -select plan(6); +select plan(1); select has_function( 'ggircs_portal_private', 'graphile_worker_job_definer', 'Function graphile_worker_job_definer should exist' ); -create or replace function ggircs_portal_private.graphile_worker_job_definer(task text, payload json) -returns void as $$ - declare - calls_past_minute int; - defer_run_multiplier int; - begin - - calls_past_minute := (select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at > (now() - interval '1 minute')); - defer_run_multiplier := (calls_past_minute/100); - - -- Update the function for test purposes, so it can be run without attempting to call the graphile_worker schema. - -- perform graphile_worker.add_job(task, payload, run_at := now() + ((defer_run_multiplier) * INTERVAL '1 minute')); - insert into ggircs_portal_private.graphile_worker_timestamp(called_at) values (now() + ((defer_run_multiplier) * INTERVAL '1 minute')); - - end; -$$ language plpgsql volatile security definer; - --- Test function adds a defined number of applications, which in turn calls graphile_worker_job_definer via a trigger -create or replace function add_apps(max int) - returns void as $$ -begin - for i in 1..max loop - perform ggircs_portal.create_application_mutation_chain(1); - end loop; -end; -$$ language plpgsql; - -select is_empty( - $$ - select * from ggircs_portal_private.graphile_worker_timestamp; - $$, - 'The graphile_worker_timestamp table is empty' -); - --- Make 201 calls to graphile_worker_job_definer -select add_apps(201); - -select * from ggircs_portal_private.graphile_worker_timestamp; - -select results_eq( - $$ - select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at between now() - interval '1 minute' and now(); - $$, - ARRAY['100'::bigint], - 'There are 100 entries in graphile_worker_timestamp where the timestamp is between now and now() - 1 minute' -); - -select results_eq( - $$ - select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at between now() + interval '1 second' and now() + interval '1 minute'; - $$, - ARRAY['100'::bigint], - 'There are 100 entries in graphile_worker_timestamp where the timestamp is between now() and now() + 1 minute' -); - -select results_eq( - $$ - select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at between now() + interval '1 minute' + interval '1 second' and now() + interval '2 minutes'; - $$, - ARRAY['1'::bigint], - 'There is one entry in graphile_worker_timestamp where the timestamp is between now() + 1 minute and now() + 2 minutes' -); - --- Make another call to graphile_worker_job_definer -select add_apps(1); - -select results_eq( - $$ - select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at between now() + interval '1 minute' + interval '1 second' and now() + interval '2 minutes'; - $$, - ARRAY['2'::bigint], - 'There are two entries in graphile_worker_timestamp where the timestamp is between now() + 1 minute and now() + 2 minutes' -); - select finish(); rollback; diff --git a/schema/verify/policies/graphile_worker_timestamp_policies.sql b/schema/verify/policies/graphile_worker_timestamp_policies.sql deleted file mode 100644 index f88cc5845c..0000000000 --- a/schema/verify/policies/graphile_worker_timestamp_policies.sql +++ /dev/null @@ -1,17 +0,0 @@ --- Verify ggircs-portal:policies/graphile_worker_timestamp_policies on pg - -begin; - -select exists( - select * from pg_policy - where polname = 'all_select' - and polrelid = (select 'ggircs_portal_private.graphile_worker_timestamp'::regclass::oid) -); - -select exists( - select * from pg_policy - where polname = 'all_insert' - and polrelid = (select 'ggircs_portal_private.graphile_worker_timestamp'::regclass::oid) -); - -rollback; diff --git a/schema/verify/tables/graphile_worker_timestamp.sql b/schema/verify/tables/graphile_worker_timestamp.sql deleted file mode 100644 index 2d34cb2b0a..0000000000 --- a/schema/verify/tables/graphile_worker_timestamp.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Verify ggircs-portal:tables/graphile_worker_timestamp on pg - -begin; - -select pg_catalog.has_table_privilege('ggircs_portal_private.graphile_worker_timestamp', 'select'); - -rollback;