简体   繁体   中英

How to make a User Privacy Table in MYSQL

I am working on a social networking website in which I have idea of creating groups, events and friend list. I want user privacy for his friends like as given below :

1. User can select friends who can view his personal info or who can't. 2. User can manage who can see his events and groups and who can't.

I have designed a table structure for the same that I am pasting below :

  1. User_location_id
  2. User_id
  3. Allow_friends(ids separated by comma)
  4. Deny_friends(ids separated by comma)
  5. Allow_groups(ids separated by comma)
  6. Deny_groups(ids separated by comma)
  7. Allow_search (Chapters of State,City)
  8. Friends (Visible to Some, Hide from Some) ( if 0 then I am geeting friends ids from allow_friends else Deny_friends)
  9. Groups (Visible to Some, Hide from Some) ( if 0 then I am geeting friends ids from allow_groups else Deny_groups)
  10. Privacy_for_type
  11. Privacy_for_name

Should there be any other structure that will be efficient and can minimize database hits and don't make database intensive.

If you're going to design database tables, you might want to read about normalization: http://en.wikipedia.org/wiki/Database_normalization

Storing ids separated by commas makes it difficult to update those records and to prevent duplicates. I'd recommend your allow and deny columns be split into separate related tables. This will not make it any more database intensive as you'll still only need one query, it just means you might have to have a query with a join.

I'd recommend using two (or three) tables, separating users + groups, and permissions.

The users/groups table can contain information specific (and isolated) to the user/group (so #'s 1 and 2 for the user) and then you can add a field for "type" or "category" that says if it is a user or group. If the information you're storing for users and groups are different enough, you can just have separate tables for each.

The permissions table can contain any permissions, including #'s 4-9 on your list (I don't really know the context of 10/11.) The table can also be use to manage group membership. The following is an example of how you could structure the permissions table:

  • : arbitrary unique primary key auto_increm column :任意唯一主键auto_increm列
  • : the category (or table name) to which the asset belongs :资产所属的类别(或表名称)
  • : the userid, groupid, etc. for which the permission describes :权限描述的用户标识,组标识等
  • : The user who is seeking permission :正在寻求许可的用户
  • : the permission being sought for the asset_id by the uid :uid正在为asset_id请求的权限
  • : the value of that permission :该权限的值


Some example entries:

//Same as listing 1338 in user 1337's Allow_Friends Field
1002, 'user', '1337', '1338', 'Allow_Friends', 'True'

//Lists 1337 as a member in group # 43
1003, 'group', '43', '1337', 'Member', 'True'

These are just some examples to help you get started. Let me know if this was helpful, or if you need me to clarify anything :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM