DEV: Add for_topic column to bookmarks (PR #14343)

This new column will be used to indicate that a bookmark is at the topic level. The first post of a topic can be bookmarked twice after this change – with for_topic set to true and with for_topic set to false.

A later PR will use this column for logic to bookmark the topic, and then topic-level bookmark links will take you to the last unread post in the topic.

See also 22208836c5f2adcf8c85a62d27b67968743b20f0

GitHub

I am thinking if a new column is required here. What would happen if in the case of a global topic bookmark we would skip setting post_id? So global bookmark is where(post_id: nil).

It might be a bit less confusing in the future. Like why did I have a post_id set when I bookmarked the topic?

We can describe behaviour with methods like

def for_topic?
  post_id.blank?
 end

and scopes etc.

Minor but you don’t need to pluck the column here.

is_first_post = Post.exists?: post_id, post_number: 1)