DEV Community

[Comment from a deleted post]
Collapse
 
sroehrl profile image
neoan

Since you only dove into the table setup, I will have to make the following assumptions which are very relevant for this to work:

  • a username cannot be changed
  • any uniqueness needs to be managed in code

In order to create a secure and performant solution, I suggest the following changes:
Use the user ids instead of strings and make your "post_for" a foreign key relation. Then add a unique key over the combination of author and post_for in the Like table.
I also see no reason in naming the columns author instead of userId or user_id:
If you followed a convention for foreign keys, then your model logic can be abstracted better. So instead of post_for, make it post_id, instead of author, user_id.
This way you can develop a simple orm for relations and as a developer never have to wonder about what your columns are called when your app becomes complicated.