Gui
Gui

Reputation: 9803

Database Design - Users and their privacy

Basically i've a table for my users (it's nightclub website) and now i'm trying to improve they privacy.

Until now i just show some information to logged in users, but now i want to give that choose to users.

My question is: What would be the better approach to do it?

What do you recommend me, create a new property for each property that i want users to manage the privacy?

Example of table "Users":

-Id

-Email

-Phone

-ShowEmail (int) and 0 would be to no-one, 1 to logged in users and 2 to friends

-ShowPhone (int)

It's a good choose? I'm not quite sure if i should create a new table to handle the privacy settings. I must admit that database design isn't my specialty so really need some feedback about this.

Thanks!

Edit: the privacy isn't just about simple properties. I would need to handle the events that the user signed up, photos where user is tagged, etc.

Upvotes: 4

Views: 769

Answers (1)

dtech
dtech

Reputation: 14060

That is a possibility, but it makes your table very large and with kinda redundant fields. You have two options which I personally like better:

  1. Use a flag field. The advantage is that you only need 1 field, the disadvantage that it kinda goes against good relational DB practices and that queries become more vague if you want to select something from it.
  2. use another table with only 3 fields, e.g. "UserID", "FieldName" and "ShowTo", the latter being a ENUM (or integer if you like that better). This is more work but is immidiatly clear and imho much better.

Queries would look something like this: 1.

SELECT phone, (privacyFlags&8) AS showPhone FROM users

2.

SELECT user.phone, privacy.ShowTo AS showPhone FROM users
    JOIN privacy ON privacy.userID=users.userID
WHERE privacy.FieldName = 'phone'

Upvotes: 2

Related Questions