Skip to content

Commit

Permalink
refactor: drop redundant columns from teams table (#3648)
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 authored Sep 11, 2024
1 parent 80b88d3 commit a319b06
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 54 deletions.
34 changes: 0 additions & 34 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2035,43 +2035,27 @@
table:
name: team_members
schema: public
computed_fields:
- name: boundary_bbox
definition:
function:
name: boundary_bbox
schema: public
comment: Bounding box of the team's full boundary
insert_permissions:
- role: platformAdmin
permission:
check: {}
columns:
- boundary
- created_at
- domain
- id
- name
- notify_personalisation
- settings
- slug
- updated_at
select_permissions:
- role: api
permission:
columns:
- boundary
- created_at
- domain
- id
- name
- notify_personalisation
- reference_code
- settings
- slug
- updated_at
computed_fields:
- boundary_bbox
filter: {}
- role: platformAdmin
permission:
Expand All @@ -2080,29 +2064,18 @@
- domain
- id
- name
- notify_personalisation
- reference_code
- settings
- slug
- updated_at
computed_fields:
- boundary_bbox
filter: {}
- role: public
permission:
columns:
- boundary
- created_at
- domain
- id
- name
- notify_personalisation
- reference_code
- settings
- slug
- updated_at
computed_fields:
- boundary_bbox
filter: {}
- role: teamEditor
permission:
Expand All @@ -2111,22 +2084,15 @@
- domain
- id
- name
- notify_personalisation
- reference_code
- settings
- slug
- updated_at
computed_fields:
- boundary_bbox
filter: {}
update_permissions:
- role: platformAdmin
permission:
columns:
- domain
- name
- notify_personalisation
- settings
- slug
filter: {}
check: null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
alter table "public"."teams" add column "notify_personalisation" jsonb;

alter table "public"."teams" add column "settings" jsonb;
alter table "public"."teams" alter column "settings" set default '{"externalPlanningSite": {"url": "https://www.planningportal.co.uk/", "name": "Planning Portal"}}'::jsonb;

alter table "public"."teams" add column "reference_code" text;
comment on column "public"."teams"."reference_code" is E'Organisation reference code sourced from planning.data.gov.uk/dataset/local-authority';

alter table "public"."teams" add column "boundary" jsonb;
alter table "public"."teams" alter column "boundary" set default '{"type": "Feature", "geometry": {"type": "Polygon", "coordinates": [[[1.9134116, 49.528423], [1.9134116, 61.331151], [1.9134116, 61.331151], [-10.76418, 61.331151], [-10.76418, 49.528423]]]}, "properties": {}}'::jsonb;
comment on column "public"."teams"."boundary" is E'GeoJSON boundary for team provided by planning.data.gov.uk. Simplified boundary_bbox should generally by used where possible. Defaults to UK extent.';


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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

CREATE OR REPLACE VIEW "public"."teams_summary" AS
SELECT t.id,
t.name,
t.slug,
ts.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 "notify_personalisation" cascade;
alter table "public"."teams" drop column "settings" cascade;
alter table "public"."teams" drop column "reference_code" cascade;
alter table "public"."teams" drop column "boundary" cascade;
24 changes: 4 additions & 20 deletions scripts/seed-database/write/teams.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,24 @@ CREATE TEMPORARY TABLE sync_teams (
slug text,
created_at timestamptz,
updated_at timestamptz,
settings jsonb,
notify_personalisation jsonb,
domain text,
boundary jsonb,
reference_code text
domain text
);

\copy sync_teams FROM '/tmp/teams.csv' WITH (FORMAT csv, DELIMITER ';');

INSERT INTO teams (
id,
name,
slug,
settings,
notify_personalisation,
boundary,
reference_code
slug
)
SELECT
id,
name,
slug,
settings,
notify_personalisation,
boundary,
reference_code
slug
FROM sync_teams
ON CONFLICT (id) DO UPDATE
SET
name = EXCLUDED.name,
slug = EXCLUDED.slug,
settings = EXCLUDED.settings,
notify_personalisation = EXCLUDED.notify_personalisation,
boundary = EXCLUDED.boundary,
reference_code = EXCLUDED.reference_code;
slug = EXCLUDED.slug;

SELECT setval('teams_id_seq', max(id)) FROM teams;

0 comments on commit a319b06

Please sign in to comment.