I’m creating a database users. I want to let users to choose notifications they want to receive by email.
Now I have the next columns in table users (boolean type):
-
notification_comment_photo. -
notification_comment_comment. -
notification_vote_photo. -
notification_vote_comment. -
notification_pm. -
notification_followed. -
notification_news.
What do you think, should I normalise table users and create another table notifications, considering that this table would have one-to-one relationship to table users?
Also I have the same problem with social links (twitter, facebook, google+, etc). Is it better to make a separate table links?
upd. Thanks all, I’ll add the separate tables.
It’s hard to answer your question, because you’re not telling us what problem you’re trying to solve.
One issue with your current design is that it requires a schema change for every new type of notification you want to store – if you want to notify users when they’ve been un_followed, you have to add a column to your users table.
I’d consider a schema like:
You could leave the “subscribed” column out of user_notification_subscriptions and decide that any record linking a user to a notification type means they have subscribed.
This design allows you to add new subscription types without changing the schema. I believe it’s similar to the design @Daniel suggests, but he doesn’t include the notification_type table, relying instead on name-value pairs. I’m not a fan of this – it can lead to silly, hard-to-find bugs when typos slip into the TYPE column.