'Implementing notion/figma alike commenting feature

I'm building an application that creates offer templates. Each offer has different sections, (for eg; offerTeams, offerFeatures, ...) A user can add a comment to any section in the page. The logic similar to notion or figma's commenting feature.

I wanted to ask how to tackle this on backend side, what to save exactly on the database in order to keep record of the comment's position.

I don't know whether technologies used would have an impact on implementing this feature but here us what I'm using; on the frontend: React, Backend: Ruby, DB: Postgresql.

2 solutions came to my mind:

1- Add two columns to the Comments table, offerSectionId and offerSectiontype (offerTeams, offerFeatures, ...).

2- Add commentId column to each offer section table, (for eg; OfferTeams table would have a column offerCommentId field)

These are the solutions I thought of, I don't know whether there is a better way to implement this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source