From d7def11d4fd21ed46207181c0d049ed4196051a4 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Wed, 16 Feb 2022 16:08:29 +0100 Subject: [PATCH] Replace State-owned by Government-owned part of #734 --- .../building/data-containers/community.tsx | 2 +- migrations/025.state_to_government.down.sql | 26 +++++++++++++++++++ migrations/025.state_to_government.up.sql | 26 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 migrations/025.state_to_government.down.sql create mode 100644 migrations/025.state_to_government.up.sql diff --git a/app/src/frontend/building/data-containers/community.tsx b/app/src/frontend/building/data-containers/community.tsx index 85a23ea6..2bb6e066 100644 --- a/app/src/frontend/building/data-containers/community.tsx +++ b/app/src/frontend/building/data-containers/community.tsx @@ -107,7 +107,7 @@ const CommunityView: React.FunctionComponent = (props) => { title={dataFields.community_public_ownership.title} value={props.building.community_public_ownership} options={[ - 'State-owned', + 'Government-owned', 'Charity-owned', 'Community-owned/cooperative', 'Owned by other non-profit body', diff --git a/migrations/025.state_to_government.down.sql b/migrations/025.state_to_government.down.sql new file mode 100644 index 00000000..0559b2c7 --- /dev/null +++ b/migrations/025.state_to_government.down.sql @@ -0,0 +1,26 @@ +-- new enum value +ALTER TYPE public_ownership_type ADD VALUE IF NOT EXISTS 'State-owned' BEFORE 'Charity-owned'; + +-- convert existing values +UPDATE buildings +SET community_public_ownership = 'State-owned' +WHERE community_public_ownership = 'Government-owned'; + +CREATE TYPE public_ownership_type_new + AS ENUM ( + 'State-owned', + 'Charity-owned', + 'Community-owned/cooperative', + 'Owned by other non-profit body', + 'Not in public/community ownership' + ); + +-- Convert to the new type, casting via text representation +ALTER TABLE buildings + ALTER COLUMN community_public_ownership TYPE public_ownership_type_new + USING (community_public_ownership::text::public_ownership_type_new); + +-- And swap the types +DROP TYPE public_ownership_type; + +ALTER TYPE public_ownership_type_new RENAME TO public_ownership_type; diff --git a/migrations/025.state_to_government.up.sql b/migrations/025.state_to_government.up.sql new file mode 100644 index 00000000..f7a53901 --- /dev/null +++ b/migrations/025.state_to_government.up.sql @@ -0,0 +1,26 @@ +-- new enum value +ALTER TYPE public_ownership_type ADD VALUE IF NOT EXISTS 'Government-owned' BEFORE 'Charity-owned'; + +-- convert existing values +UPDATE buildings +SET community_public_ownership = 'Government-owned' +WHERE community_public_ownership = 'State-owned'; + +CREATE TYPE public_ownership_type_new + AS ENUM ( + 'Government-owned', + 'Charity-owned', + 'Community-owned/cooperative', + 'Owned by other non-profit body', + 'Not in public/community ownership' + ); + +-- Convert to the new type, casting via text representation +ALTER TABLE buildings + ALTER COLUMN community_public_ownership TYPE public_ownership_type_new + USING (community_public_ownership::text::public_ownership_type_new); + +-- And swap the types +DROP TYPE public_ownership_type; + +ALTER TYPE public_ownership_type_new RENAME TO public_ownership_type;