From a8f9c7cbd7a94df1669232a611f922d8163a9656 Mon Sep 17 00:00:00 2001 From: Rory Doak <138574807+RODO94@users.noreply.github.com> Date: Tue, 10 Sep 2024 09:17:01 +0100 Subject: [PATCH] refactor: remove `submission_email` column from `teams` table (#3640) --- hasura.planx.uk/metadata/tables.yaml | 3 -- .../down.sql | 30 +++++++++++++++++++ .../up.sql | 30 +++++++++++++++++++ scripts/seed-database/write/teams.sql | 1 - 4 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 hasura.planx.uk/migrations/1725873202035_alter_table_public_teams_drop_column_submission_email/down.sql create mode 100644 hasura.planx.uk/migrations/1725873202035_alter_table_public_teams_drop_column_submission_email/up.sql diff --git a/hasura.planx.uk/metadata/tables.yaml b/hasura.planx.uk/metadata/tables.yaml index cd7a62e911..017b9b3ac6 100644 --- a/hasura.planx.uk/metadata/tables.yaml +++ b/hasura.planx.uk/metadata/tables.yaml @@ -2055,7 +2055,6 @@ - notify_personalisation - settings - slug - - submission_email - updated_at select_permissions: - role: api @@ -2070,7 +2069,6 @@ - reference_code - settings - slug - - submission_email - updated_at computed_fields: - boundary_bbox @@ -2130,7 +2128,6 @@ - notify_personalisation - settings - slug - - submission_email filter: {} check: null - table: diff --git a/hasura.planx.uk/migrations/1725873202035_alter_table_public_teams_drop_column_submission_email/down.sql b/hasura.planx.uk/migrations/1725873202035_alter_table_public_teams_drop_column_submission_email/down.sql new file mode 100644 index 0000000000..3096149658 --- /dev/null +++ b/hasura.planx.uk/migrations/1725873202035_alter_table_public_teams_drop_column_submission_email/down.sql @@ -0,0 +1,30 @@ +alter table "public"."teams" add column "submission_email" text; +comment on column "public"."teams"."submission_email" is E'Referenced by Send component when configured to email planning office'; + + + CREATE OR REPLACE VIEW "public"."teams_summary" AS + SELECT t.id, + t.name, + t.slug, + t.reference_code, + (t.settings ->> 'homepage'::text) AS homepage, + t.domain AS subdomain, + ti.has_planning_data AS planning_data_enabled, + '@todo'::text AS article_4s_enabled, + jsonb_build_object('helpEmail', ts.help_email, 'helpPhone', ts.help_phone, 'emailReplyToId', ts.email_reply_to_id, 'helpOpeningHours', ts.help_opening_hours) AS govnotify_personalisation, + CASE + WHEN (COALESCE(ti.production_govpay_secret, ti.staging_govpay_secret) IS NOT NULL) THEN true + ELSE false + END AS govpay_enabled, + t.submission_email AS send_to_email_address, + COALESCE(ti.production_bops_submission_url, ti.staging_bops_submission_url) AS bops_submission_url, + tt.logo, + tt.favicon, + tt.primary_colour, + tt.link_colour, + tt.action_colour + FROM (((teams t + JOIN team_integrations ti ON ((ti.team_id = t.id))) + JOIN team_themes tt ON ((tt.team_id = t.id))) + JOIN team_settings ts ON ((ts.team_id = t.id))) + ORDER BY t.name; diff --git a/hasura.planx.uk/migrations/1725873202035_alter_table_public_teams_drop_column_submission_email/up.sql b/hasura.planx.uk/migrations/1725873202035_alter_table_public_teams_drop_column_submission_email/up.sql new file mode 100644 index 0000000000..7bdd281759 --- /dev/null +++ b/hasura.planx.uk/migrations/1725873202035_alter_table_public_teams_drop_column_submission_email/up.sql @@ -0,0 +1,30 @@ + +CREATE OR REPLACE VIEW "public"."teams_summary" AS + SELECT t.id, + t.name, + t.slug, + t.reference_code, + ts.homepage AS homepage, + t.domain AS subdomain, + ti.has_planning_data AS planning_data_enabled, + '@todo'::text AS article_4s_enabled, + jsonb_build_object('helpEmail', ts.help_email, 'helpPhone', ts.help_phone, 'emailReplyToId', ts.email_reply_to_id, 'helpOpeningHours', ts.help_opening_hours) AS govnotify_personalisation, + CASE + WHEN (COALESCE(ti.production_govpay_secret, ti.staging_govpay_secret) IS NOT NULL) THEN true + ELSE false + END AS govpay_enabled, + ts.submission_email AS send_to_email_address, + COALESCE(ti.production_bops_submission_url, ti.staging_bops_submission_url) AS bops_submission_url, + tt.logo, + tt.favicon, + tt.primary_colour, + tt.link_colour, + tt.action_colour + FROM (((teams t + JOIN team_integrations ti ON ((ti.team_id = t.id))) + JOIN team_themes tt ON ((tt.team_id = t.id))) + JOIN team_settings ts ON ((ts.team_id = t.id))) + ORDER BY t.name; + + +alter table "public"."teams" drop column "submission_email" cascade; diff --git a/scripts/seed-database/write/teams.sql b/scripts/seed-database/write/teams.sql index 7cc3c73dde..5a8e6bc5dc 100644 --- a/scripts/seed-database/write/teams.sql +++ b/scripts/seed-database/write/teams.sql @@ -8,7 +8,6 @@ CREATE TEMPORARY TABLE sync_teams ( settings jsonb, notify_personalisation jsonb, domain text, - submission_email text, boundary jsonb, reference_code text );