From dbf4189ac717e58b8761d0bc1a6c6ae7a513b1bd Mon Sep 17 00:00:00 2001 From: Marcin Ickiewicz <mickiewicz@syncad.com> Date: Wed, 25 Nov 2020 21:45:53 +0100 Subject: [PATCH] fix for drop hive_post_dags without assign tags to post during upgrades --- .../sql_scripts/upgrade/upgrade_table_schema.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql index fe90715f6..348e6602f 100644 --- a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql +++ b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql @@ -225,6 +225,20 @@ IF NOT EXISTS(SELECT data_type FROM information_schema.columns WHERE table_name = 'hive_posts' AND column_name = 'tags_ids') THEN ALTER TABLE ONLY hive_posts ADD COLUMN tags_ids INTEGER[]; + + UPDATE hive_posts hp + SET + tags_id = tags.tags + FROM + ( + SELECT + post_id as post_id, + array_agg( hpt.tag_id ) as tags + FROM + hive_post_tags hpt + GROUP BY post_id + ) as tags + WHERE hp.id = tags.post_id; ELSE RAISE NOTICE 'SKIPPING hive_posts upgrade - adding a tags_ids column'; END IF; -- GitLab