发布特定用户的可见度

时间:2015-07-16 12:25:52

标签: php mysql database database-design

我即将开始编程某种类似于以下网站的网站:

用户登录,如果他是普通用户(不是管理员),他将会收到一些与他的帐户相关的帖子(Accouns由管理员提供并由管理员提供)

管理员做的是创建这些帖子,在创建帖子时,他说谁有权访问该帖子(例如检查将看到它的用户,或者几个用户或者所有用户都能看到它)

我的问题是,我应该在我的数据库中创建什么样的表以及哪些列。 我的第一个计划是拥有ofc:  1)用户表  2)帖子表   3)权限表 权限表将包含字段([postID],然后像[user1],[user2] .... [userN])这样的文件,表中的示例行看起来像 21 | true | true | false | true | .... | true | 表示这些用户将能够看到该帖子。并且可以在创建新用户时以dinamically方式创建这些字段[userN] 我正在征求关于这种数据库的意见,以及你对这个数据库的想法。

1 个答案:

答案 0 :(得分:1)

create table users
(   id int not null auto_increment primary key,
    fullName varchar(100) not null
);

create table posts
(   id int not null auto_increment primary key,
    postName varchar(200) not null
);

create table post_user_junction
(   id int not null auto_increment primary key,
    userId int not null,
    postId int not null,
    UNIQUE (userId,postId),
    -- foreign key (FK) referential integrity:
    FOREIGN KEY (userId) REFERENCES users(id),
    FOREIGN KEY (postId) REFERENCES posts(id)
);

insert post_user_junction (userId,postId) values (1,1);
-- ooops, Error 1452, FK violation, user and post do not exist yet

insert users(fullName) values ('a');
insert posts(postName) values ('a');

-- works:
insert post_user_junction (userId,postId) values (1,1);

-- do it again, does not work, already there:
insert post_user_junction (userId,postId) values (1,1);

你去了,你应该走出上面的大门,至少开始。