我正在尝试构建一个小型社交网络,我想向我的用户提供控制其数据可见性/隐私的能力,就像Facebook一样...
例如,他们可以制作他们的数据( Pseudo,City,Birthday,Gender,... )私人,公开或 OnlyFriends ...
我已经构建了用户表:user,user_profiles,...
create table user(
id int unsigned not null auto_increment,
pseudo varchar(64) not null,
password char(64) not null,
lname varchar(48) not null,
fname varchar(48) not null,
gender char(1) not null,
--Other fields
primary key(id),
unique(pseudo)
);
create table user_profile(
uid int unsigned not null,
birthday date,
phone varchar(15),
address varchar(255),
city varchar(64),
postal_code varchar(10),
-- ... Other fields
);
为了存储这些可见性数据我试过这个:
create table data_visibility(
id smallint unsigned not null auto_increment,
name char(15) not null,
primary key(id),
unique(name)
);
create table user_visibility(
uid int unsigned not null,
pseudo smallint not null,
lname smallint not null,
fname smallint not null,
email smallint not null,
gender smallint not null,
birthday smallint not null,
-- ... Other fields
primary key(uid),
foreign key(uid) references user(id) on delete cascade on update cascade,
foreign key(pseudo) references data_visibility(id),
foreign key(lname) references data_visibility(id),
foreign key(fname) references data_visibility(id)
-- ... Other foreigns
);
但是我对这个解决方案不满意如果我通过添加新字段来更改用户表,我还需要更新user_visibility字段,所有这些外键看起来都很奇怪......
程序员通常会做些什么来解决这个问题?