Thank you for reporting this Jay!
Seems like an issue with the ensure_consistency rake task. I just checked on a migration I’m working on now (haven’t run the ensure_consistency task yet) and the TopicUser records were already created with posted: false (the default). When the rake task reaches this point it generates a “duplicate key” error and the records are not created because of the ON CONFLICT DO NOTHING
def insert_topic_users
log "Inserting topic users..."
DB.exec <<-SQL
INSERT INTO topic_users (user_id, topic_id, posted, last_read_post_number, first_visited_at, last_visited_at, total_msecs_viewed)
SELECT user_id, topic_id, 't' , MAX(post_number), MIN(created_at), MAX(created_at), COUNT(id) * #{MS_SPEND_CREATING_POST}
FROM posts
WHERE user_id > 0
GROUP BY user_id, topic_id
ON CONFLICT DO NOTHING
SQL
end
The TopicUser records are created at the create_topic step, more specifically here discourse/lib/topic_creator.rb at main · discourse/discourse · GitHub.
I opened a PR with a fix that you could run now: