diff --git a/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql b/hive/db/sql_scripts/upgrade/upgrade_table_schema.sql index fe90715f692dfb048d6b03b7f0417bf4e018a2cf..b4bb9f5b82359b7cf280fed5c04e2dcf34fa6083 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_ids = 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; @@ -408,4 +422,4 @@ CREATE INDEX IF NOT EXISTS hive_posts_promoted_id_idx ON hive_posts (promoted, i CREATE INDEX IF NOT EXISTS hive_posts_tags_ids_idx ON hive_posts USING gin(tags_ids gin__int_ops); - DROP TABLE IF EXISTS hive_post_tags; + --DROP TABLE IF EXISTS hive_post_tags;