From bdb8642fdab624f760e257bdd5e03528abc1c48b Mon Sep 17 00:00:00 2001 From: ChrisBAshton Date: Mon, 16 Sep 2024 15:25:21 +0100 Subject: [PATCH] Remove 'scrub access limited' SQL The original intention was to keep this as the main copy of the SQL sanitisation script (the script that is applied to data when it is copied from Production to Integration in the nightly env sync). A code comment deleted here refers to https://github.com/alphagov/env-sync-and-backup/blob/master/sanitising-sql/sanitise_content_publisher_production.sql, which is the 'copy' of this main copy, and should be kept in sync. The env sync process has since moved from env-sync-and-backup to govuk-helm-charts. The SQL script is referred to here: https://github.com/alphagov/govuk-helm-charts/blob/61d36eeb6339c13600f1c5cecc725a71ff593053/charts/db-backup/values.yaml#L329 ...and the SQL script it is referring to lives here: https://github.com/alphagov/govuk-helm-charts/blob/main/charts/db-backup/scripts/content-publisher.sql There is currently a TODO comment in that repo: ``` -- TODO: Fix the CI in alphagov/content-publisher to pull in this script -- (perhaps via git submodule) instead of running tests against its own copy. ``` So let's do that. This commit removes our local copy of the SQL sanitisation, and pulls in the remote copy instead (the version that is actually used in the env sync job, which is far more useful). --- .github/workflows/rspec.yml | 6 ++ db/scrub_access_limited.sql | 95 ---------------------------- spec/db/scrub_access_limited_spec.rb | 2 +- 3 files changed, 7 insertions(+), 96 deletions(-) delete mode 100644 db/scrub_access_limited.sql diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 36f8e31ce1..a638699364 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -38,6 +38,12 @@ jobs: ref: ${{ inputs.publishingApiRef }} path: vendor/publishing-api + - name: Checkout govuk-helm-charts (for data sanitisation SQL) + uses: actions/checkout@v3 + with: + repository: alphagov/govuk-helm-charts + path: vendor/govuk-helm-charts + - name: Setup Ruby uses: ruby/setup-ruby@v1 with: diff --git a/db/scrub_access_limited.sql b/db/scrub_access_limited.sql deleted file mode 100644 index 96b266e2af..0000000000 --- a/db/scrub_access_limited.sql +++ /dev/null @@ -1,95 +0,0 @@ --- This script is to be executed by https://github.com/alphagov/env-sync-and-backup --- (private repo) as part of the data sync from production to integration. --- It is used to remove any access limited content from Content Publisher at --- the point of copying to integration. --- It is kept in this repo to be tested with the application, whenever changes --- are made it should be re-copied to the env-sync-and-backup repository. - --- Remove current status of any access limited editions -UPDATE editions -SET current = false -WHERE access_limit_id IS NOT NULL; - --- Set the live editions to current for any docs with an access limited draft -UPDATE editions -SET current = true -WHERE live = true -AND document_id IN ( - SELECT document_id - FROM editions - WHERE access_limit_id IS NOT NULL -); - --- Delete any access limited editions -DELETE FROM editions WHERE access_limit_id IS NOT NULL; - --- Delete orphaned revisions -DELETE FROM revisions WHERE NOT EXISTS ( - SELECT 1 - FROM editions_revisions - WHERE editions_revisions.revision_id = revisions.id -); - -DELETE FROM content_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM revisions - WHERE revisions.content_revision_id = content_revisions.id -); - -DELETE FROM tags_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM revisions - WHERE revisions.tags_revision_id = tags_revisions.id -); - -DELETE FROM metadata_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM revisions - WHERE revisions.metadata_revision_id = metadata_revisions.id -); - -DELETE FROM image_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM revisions_image_revisions - WHERE revisions_image_revisions.image_revision_id = image_revisions.id -); - -DELETE FROM image_blob_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM image_revisions - WHERE image_revisions.blob_revision_id = image_blob_revisions.id -); - -DELETE FROM image_metadata_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM image_revisions - WHERE image_revisions.metadata_revision_id = image_metadata_revisions.id -); - -DELETE FROM file_attachment_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM revisions_file_attachment_revisions - WHERE revisions_file_attachment_revisions.file_attachment_revision_id = file_attachment_revisions.id -); - -DELETE FROM file_attachment_blob_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM file_attachment_revisions - WHERE file_attachment_revisions.blob_revision_id = file_attachment_blob_revisions.id -); - -DELETE FROM file_attachment_metadata_revisions WHERE NOT EXISTS ( - SELECT 1 - FROM file_attachment_revisions - WHERE file_attachment_revisions.metadata_revision_id = file_attachment_metadata_revisions.id -); - -DELETE FROM active_storage_blobs WHERE NOT EXISTS ( - SELECT 1 - FROM image_blob_revisions - WHERE image_blob_revisions.blob_id = active_storage_blobs.id -) AND NOT EXISTS ( - SELECT 1 - FROM file_attachment_blob_revisions - WHERE file_attachment_blob_revisions.blob_id = active_storage_blobs.id -); diff --git a/spec/db/scrub_access_limited_spec.rb b/spec/db/scrub_access_limited_spec.rb index 604e4dc173..76f6102331 100644 --- a/spec/db/scrub_access_limited_spec.rb +++ b/spec/db/scrub_access_limited_spec.rb @@ -1,6 +1,6 @@ RSpec.describe "Scrub Access Limited SQL Script" do def execute_sql - sql = File.read(Rails.root.join("db/scrub_access_limited.sql")) + sql = File.read(Rails.root.join("vendor/govuk-helm-charts/charts/db-backup/scripts/content-publisher.sql")) ActiveRecord::Base.connection.execute(sql) end