Passionate generalist conquering the web one project at a time. Whether authoring libraries for node, JS, PHP, or Rust, I am always on the lookout for better solutions to common problems.
Location
USA
Work
Lead Developer & Co-founder at corpscrypt, CTO at REtech
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Since you only dove into the table setup, I will have to make the following assumptions which are very relevant for this to work:
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.