Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Drop redundant columns from teams table #3636

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2047,30 +2047,21 @@
permission:
check: {}
columns:
- boundary
- created_at
- domain
- id
- name
- notify_personalisation
- settings
- slug
- submission_email
- updated_at
select_permissions:
- role: api
permission:
columns:
- boundary
- created_at
- domain
- id
- name
- notify_personalisation
- reference_code
- settings
- slug
- submission_email
- updated_at
computed_fields:
- boundary_bbox
Copy link
Contributor

@DafyddLlyr DafyddLlyr Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the computed field boundary_bbox is also redundant now right?

Expand All @@ -2082,25 +2073,16 @@
- 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:
Expand All @@ -2113,9 +2095,6 @@
- domain
- id
- name
- notify_personalisation
- reference_code
- settings
- slug
- updated_at
computed_fields:
Expand All @@ -2127,38 +2106,9 @@
columns:
- domain
- name
- notify_personalisation
- settings
- slug
- submission_email
filter: {}
check: null
- table:
name: teams_summary
Comment on lines -2136 to -2137
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where my previous comment went but this is still being incorrectly removed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! That was in the submission email PR, but this is the exact same issue. Removing columns and not repointing the View creation. My bad for missing this again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DafyddLlyr for this one, if we merge my submission_email PR (#3640), I have already changed the references in the View creation, so this won't be an issue?

Could be a nice candidate to re-do this on a clean branch once #3640 is merged and reopen a new PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, I would be repeating code across the migrations

schema: public
select_permissions:
- role: platformAdmin
permission:
columns:
- govpay_enabled
- planning_data_enabled
- id
- govnotify_personalisation
- action_colour
- article_4s_enabled
- bops_submission_url
- favicon
- homepage
- link_colour
- logo
- name
- primary_colour
- reference_code
- send_to_email_address
- slug
- subdomain
filter: {}
comment: ""
- table:
name: uniform_applications
schema: public
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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" alter column "settings" drop not null;


alter table "public"."teams" add column "notify_personalisation" jsonb;
alter table "public"."teams" alter column "notify_personalisation" drop not null;

alter table "public"."teams" add column "reference_code" text;
alter table "public"."teams" alter column "reference_code" drop not null;
comment on column "public"."teams"."reference_code" is E"Team name in three letter short form";


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;
alter table "public"."teams" alter column "boundary" drop not null;
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.";
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
alter table "public"."teams" drop column "settings" cascade;

alter table "public"."teams" drop column "boundary" cascade;

alter table "public"."teams" drop column "notify_personalisation" cascade;

alter table "public"."teams" drop column "reference_code" 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,41 +5,25 @@ CREATE TEMPORARY TABLE sync_teams (
slug text,
created_at timestamptz,
updated_at timestamptz,
settings jsonb,
notify_personalisation jsonb,
domain text,
submission_email text,
boundary jsonb,
reference_code text
submission_email 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;
Loading