mysql - Storing A Users Profile Privacy Settings -
suppose have database following users table:
create table if not exists `users ( `id` varchar(20) not null, `first_name` varchar(30) not null, `last_name` varchar(50) default null, `date_of_birth` date default null, `home_phone` varchar(25) default null, `mobile_phone` varchar(25) default null, `address` varchar(100) default null, `image` longblob, `added` timestamp not null default '0000-00-00 00:00:00', `modified` timestamp not null default current_timestamp on update current_timestamp, primary key (`user`) ) engine=innodb default charset=utf8 comment='user profile'; what best way store whether of information public or private.
currently involves having separate table stores whether field public (public=1) or not (public=0 or not in table)
create table if not exists `user_perms` ( `user` varchar(20) not null, `field` varchar(30) not null, `public` tinyint(1) not null, primary key (`user`,`field`) ) engine=innodb default charset=utf8; (relations not shown, user_perms.user references users.id)
so make user's first name public, following:
insert `user_perms` (`user`, `field`, `public`) values ('123', 'first_name', 1); my question is: is there better way represent profile in database?
i've thought of maybe storing each profile field, referencing owners user id , it's privacy setting in own table:
| userid | field | field_value | public | 123 first_name marco 1 it seems solution because doesn't require me update users table everytime need add new profile field. scale well? @ 1m users, assuming each user fills out 5 fields, there 5m table rows.
Comments
Post a Comment