Skip to content
Dan Neumann edited this page Mar 8, 2015 · 1 revision

Change the forum_id of all topics in ORIGIN_FORUM:

-- Move topics
UPDATE topics
SET forum_id = FROM_FORUM.id
WHERE forum_id = TO_FORUM.id

Re-calculate TO_FORUM's column caches:

UPDATE forums
SET 
  topics_count = sub.topics_count,
  posts_count = sub.posts_count
FROM (
	SELECT 
    f.id forum_id,
    COUNT(t.id) topics_count,
    SUM(t.posts_count) posts_count
	FROM forums f
	JOIN topics t ON f.id = t.forum_id
	GROUP BY f.id
) sub
WHERE forums.id = sub.forum_id AND forums.id = TO_FORUM.id

Delete FROM_FORUM

DELETE FROM forums
WHERE id = 32

Clone this wiki locally