From dc7ac176b16a1bf8b978bdb750912e4cde58d303 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Thu, 9 Feb 2023 20:49:41 +0100 Subject: [PATCH] Provide counts for already liked typologies --- migrations/037.is_domestic.up.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/migrations/037.is_domestic.up.sql b/migrations/037.is_domestic.up.sql index 3be40166..d07b31cd 100644 --- a/migrations/037.is_domestic.up.sql +++ b/migrations/037.is_domestic.up.sql @@ -1,2 +1,15 @@ ALTER TABLE buildings ADD COLUMN IF NOT EXISTS is_domestic text null; ALTER TABLE buildings ADD COLUMN IF NOT EXISTS community_type_worth_keeping_total integer DEFAULT 0; + +-- Provide counts for already liked typologies +UPDATE buildings + SET community_type_worth_keeping_total = ( + SELECT count(*) + FROM building_user_attributes + WHERE buildings.building_id = building_user_attributes.building_id + AND community_type_worth_keeping = TRUE + ) + WHERE buildings.building_id in ( + SELECT DISTINCT building_id + FROM building_user_attributes + );