From 388b441ee3dfc07adf3f0bfa88b40f20250b6172 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 3 Jul 2019 19:58:07 +1000 Subject: [PATCH] feat: added clean up sql script --- script/prod/clean-up.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 script/prod/clean-up.sql diff --git a/script/prod/clean-up.sql b/script/prod/clean-up.sql new file mode 100644 index 000000000..d9ae61f0f --- /dev/null +++ b/script/prod/clean-up.sql @@ -0,0 +1,11 @@ +-- Deletes all verifications and pact publications that are older than 60 days, +-- and cleans up orphan pacticipant versions and their tags. +-- Also removes webhook execution history. + +DELETE FROM verifications WHERE created_at < now() - '60 days'::interval; +DELETE FROM webhook_executions; +DELETE FROM triggered_webhooks; +DELETE FROM pact_publications WHERE created_at < now() - '60 days'::interval; +DELETE FROM pact_versions WHERE id NOT IN (SELECT distinct pact_version_id from pact_publications); +DELETE FROM tags WHERE version_id NOT IN (select consumer_version_id from pact_publications union select provider_version_id from verifications); +DELETE FROM versions WHERE id NOT IN (select consumer_version_id from pact_publications union select provider_version_id from verifications);