diff --git a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql index fe90715f692dfb048d6b03b7f0417bf4e018a2cf..348e6602f3bd144a044d784a3c1860e081ae5c99 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;