|
| 1 | +drop database if exists fangtx; |
| 2 | + |
| 3 | +create database fangtx default charset utf8 collate utf8_bin; |
| 4 | + |
| 5 | +use fangtx; |
| 6 | + |
| 7 | +/* 创建用户表 */ |
| 8 | +create table `tb_user` |
| 9 | +( |
| 10 | + `userid` int auto_increment comment '编号', |
| 11 | + `username` varchar(20) not null comment '用户名', |
| 12 | + `password` char(32) not null comment '用户口令', |
| 13 | + `realname` varchar(20) not null comment '真实姓名', |
| 14 | + `sex` bool default 1 comment '性别', |
| 15 | + `tel` varchar(20) not null comment '手机号', |
| 16 | + `email` varchar(255) default '' comment '邮箱', |
| 17 | + `regdate` datetime default now() comment '注册日期', |
| 18 | + `point` int default 0 comment '积分', |
| 19 | + `lastvisit` datetime default now() comment '最后访问时间', |
| 20 | + `is_authenticated` bit default 0 comment '是否认证', |
| 21 | + primary key (`userid`) |
| 22 | +); |
| 23 | + |
| 24 | +/* 创建地区表 */ |
| 25 | +create table `tb_district` |
| 26 | +( |
| 27 | + `distid` int not null comment '编号', |
| 28 | + `pid` int comment '父级行政单位', |
| 29 | + `name` varchar(255) not null comment '名称', |
| 30 | + `ishot` bool default 0 comment '是否为热门城市', |
| 31 | + `intro` varchar(255) default '' comment '介绍', |
| 32 | + primary key (distid) |
| 33 | +); |
| 34 | + |
| 35 | +/* 创建经理人表 */ |
| 36 | +create table `tb_agent` |
| 37 | +( |
| 38 | + `agentid` int not null auto_increment comment '编号', |
| 39 | + `name` varchar(255) not null comment '姓名', |
| 40 | + `tel` varchar(20) not null comment '电话', |
| 41 | + `servstar` int not null default 0 comment '满意度星级', |
| 42 | + `realstar` int not null default 0 comment '真实度星级', |
| 43 | + `profstar` int not null default 0 comment '专业度星级', |
| 44 | + `certificated` bool not null default 0 comment '是否持有专业认证', |
| 45 | + primary key (`agentid`) |
| 46 | +); |
| 47 | + |
| 48 | +/* 创建用户登录日志表 */ |
| 49 | +create table `tb_login_log` |
| 50 | +( |
| 51 | + `logid` bigint auto_increment comment '编号', |
| 52 | + `userid` int not null comment '用户', |
| 53 | + `ipaddr` varchar(255) not null comment 'IP地址', |
| 54 | + `logdate` datetime default now() comment '登录时间日期', |
| 55 | + `devcode` varchar(255) default '' comment '设备代码', |
| 56 | + primary key (`logid`) |
| 57 | +); |
| 58 | + |
| 59 | +/* 创建楼盘表 */ |
| 60 | +create table `tb_estate` |
| 61 | +( |
| 62 | + `estateid` int not null auto_increment comment '编号', |
| 63 | + `distid` int not null comment '所在三级行政区域', |
| 64 | + `name` varchar(255) not null comment '名称', |
| 65 | + `hot` int default 0 comment '热度', |
| 66 | + `intro` varchar(511) default '' comment '介绍', |
| 67 | + primary key (`estateid`) |
| 68 | +); |
| 69 | + |
| 70 | +/* 创建经理人楼盘中间表 */ |
| 71 | +create table `tb_agent_estate` |
| 72 | +( |
| 73 | + `agent_estate_id` int not null auto_increment comment '编号', |
| 74 | + `agentid` int not null comment '经理人', |
| 75 | + `estateid` int not null comment '楼盘', |
| 76 | + primary key (`agent_estate_id`) |
| 77 | +); |
| 78 | + |
| 79 | +/* 创建户型表 */ |
| 80 | +create table `tb_house_type` |
| 81 | +( |
| 82 | + `typeid` int comment '编号', |
| 83 | + `name` varchar(255) not null comment '名称', |
| 84 | + primary key (`typeid`) |
| 85 | +); |
| 86 | + |
| 87 | +/* 创建房源信息表 */ |
| 88 | +create table `tb_house_info` |
| 89 | +( |
| 90 | + `houseid` int not null auto_increment comment '编号', |
| 91 | + `title` varchar(50) not null comment '标题', |
| 92 | + `area` int not null comment '面积', |
| 93 | + `floor` int not null comment '楼层', |
| 94 | + `totalfloor` int not null comment '总楼层', |
| 95 | + `direction` varchar(10) not null comment '朝向', |
| 96 | + `price` int not null comment '价格', |
| 97 | + `priceunit` varchar(10) not null comment '价格单位', |
| 98 | + `detail` varchar(511) default '' comment '详情', |
| 99 | + `mainphoto` varchar(255) not null comment '主图', |
| 100 | + `pubdate` date not null comment '发布日期', |
| 101 | + `street` varchar(255) not null comment '街道', |
| 102 | + `hassubway` bool default 0 comment '是否有地铁', |
| 103 | + `isshared` bool default 0 comment '是否支持合租', |
| 104 | + `hasagentfees` bool default 0 comment '是否有中介费', |
| 105 | + `typeid` int not null comment '户型', |
| 106 | + `userid` int not null comment '发布用户', |
| 107 | + `distid2` int not null comment '所在二级行政区域', |
| 108 | + `distid3` int not null comment '所在三级行政区域', |
| 109 | + `estateid` int comment '楼盘', |
| 110 | + `agentid` int comment '经理人', |
| 111 | + primary key (`houseid`) |
| 112 | +); |
| 113 | + |
| 114 | +/* 创建房源照片表 */ |
| 115 | +create table `tb_house_photo` |
| 116 | +( |
| 117 | + `photoid` int not null auto_increment comment '编号', |
| 118 | + `houseid` int not null comment '房源', |
| 119 | + `path` varchar(255) not null comment '资源路径', |
| 120 | + primary key (`photoid`) |
| 121 | +); |
| 122 | + |
| 123 | +/* 创建标签表 */ |
| 124 | +create table `tb_tag` |
| 125 | +( |
| 126 | + `tagid` int auto_increment comment '编号', |
| 127 | + `content` varchar(20) not null comment '内容', |
| 128 | + primary key (`tagid`) |
| 129 | +); |
| 130 | + |
| 131 | +/* 创建房源标签中间表 */ |
| 132 | +create table `tb_house_tag` |
| 133 | +( |
| 134 | + `house_tag_id` int auto_increment comment '编号', |
| 135 | + `houseid` int not null comment '房源', |
| 136 | + `tagid` int not null comment '标签', |
| 137 | + primary key (`house_tag_id`) |
| 138 | +); |
| 139 | + |
| 140 | + |
| 141 | +/* 创建用户浏览历史记录表 */ |
| 142 | +create table `tb_record` |
| 143 | +( |
| 144 | + `recordid` bigint auto_increment comment '编号', |
| 145 | + `userid` int not null comment '用户', |
| 146 | + `houseid` int not null comment '房源', |
| 147 | + `recorddate` datetime not null comment '浏览时间日期', |
| 148 | + primary key (`recordid`) |
| 149 | +); |
| 150 | + |
| 151 | +/* 创建用户令牌表 */ |
| 152 | +create table `tb_user_token` |
| 153 | +( |
| 154 | + `tokenid` int auto_increment comment '编号', |
| 155 | + `token` char(32) not null comment '令牌', |
| 156 | + `userid` int not null comment '用户', |
| 157 | + primary key (`tokenid`) |
| 158 | +); |
| 159 | + |
| 160 | +/* 创建角色表 */ |
| 161 | +create table `tb_role` |
| 162 | +( |
| 163 | + `roleid` int auto_increment comment '编号', |
| 164 | + `rolename` varchar(255) not null comment '角色名', |
| 165 | + primary key (`roleid`) |
| 166 | +); |
| 167 | + |
| 168 | +/* 创建权限表 */ |
| 169 | +create table `tb_privilege` |
| 170 | +( |
| 171 | + `privid` int auto_increment comment '编号', |
| 172 | + `method` varchar(15) not null comment '请求方法', |
| 173 | + `url` varchar(1024) not null comment '资源的URL', |
| 174 | + PRIMARY KEY (`privid`) |
| 175 | +); |
| 176 | + |
| 177 | +/* 创建用户角色中间表 */ |
| 178 | +create table `tb_user_role` |
| 179 | +( |
| 180 | + `urid` int auto_increment comment '编号', |
| 181 | + `userid` int not null comment '用户', |
| 182 | + `roleid` int not null comment '角色', |
| 183 | + primary key (`urid`) |
| 184 | +); |
| 185 | + |
| 186 | +/* 创建角色权限中间表 */ |
| 187 | +create table `tb_role_privilege` |
| 188 | +( |
| 189 | + `rpid` int auto_increment comment '编号', |
| 190 | + `roleid` int not null comment '角色', |
| 191 | + `privid` int not null comment '权限', |
| 192 | + primary key (`rpid`) |
| 193 | +); |
| 194 | + |
| 195 | +create unique index `uni_idx_agent_estate` on `tb_agent_estate` (`agentid`, `estateid`); |
| 196 | + |
| 197 | +create unique index `uni_idx_record` on `tb_record` (`userid`, `houseid`); |
| 198 | + |
| 199 | +create unique index `uni_idx_userid` on `tb_user_token` (`userid`); |
| 200 | + |
| 201 | +create unique index `uni_idx_username` on `tb_user` (`username`); |
| 202 | + |
| 203 | +create unique index `uni_idx_tel` on `tb_user` (`tel`); |
| 204 | + |
| 205 | +create unique index `uni_idx_email` on `tb_user` (`email`); |
| 206 | + |
| 207 | +create unique index `uni_idx_house_tag` on `tb_house_tag` (`houseid`, `tagid`); |
| 208 | + |
| 209 | +alter table `tb_agent_estate` add constraint `fk_agent_estate_agentid` foreign key (`agentid`) references `tb_agent` (`agentid`); |
| 210 | + |
| 211 | +alter table `tb_agent_estate` add constraint `fk_agent_estate_estateid` foreign key (`estateid`) references `tb_estate` (`estateid`); |
| 212 | + |
| 213 | +alter table `tb_district` add constraint `fk_district_pid` foreign key (`pid`) references `tb_district` (`distid`); |
| 214 | + |
| 215 | +alter table `tb_estate` add constraint `fk_estate_distid` foreign key (`distid`) references `tb_district` (`distid`); |
| 216 | + |
| 217 | +alter table `tb_house_info` add constraint `fk_house_info_agentid` foreign key (`agentid`) references tb_agent (`agentid`); |
| 218 | + |
| 219 | +alter table `tb_house_info` add constraint `fk_house_info_distid2` foreign key (`distid2`) references tb_district (`distid`); |
| 220 | + |
| 221 | +alter table `tb_house_info` add constraint `fk_house_info_distid3` foreign key (`distid3`) references tb_district (`distid`); |
| 222 | + |
| 223 | +alter table `tb_house_info` add constraint `fk_house_info_estateid` foreign key (`estateid`) references tb_estate (`estateid`); |
| 224 | + |
| 225 | +alter table `tb_house_info` add constraint `fk_house_info_typeid` foreign key (`typeid`) references tb_house_type (`typeid`); |
| 226 | + |
| 227 | +alter table `tb_house_info` add constraint `fk_house_info_userid` foreign key (`userid`) references tb_user (`userid`); |
| 228 | + |
| 229 | +alter table `tb_house_photo` add constraint `fk_house_photo_houseid` foreign key (`houseid`) references `tb_house_info` (`houseid`); |
| 230 | + |
| 231 | +alter table `tb_house_tag` add constraint `fk_house_tag_houseid` foreign key (`houseid`) references `tb_house_info` (`houseid`); |
| 232 | + |
| 233 | +alter table `tb_house_tag` add constraint `fk_house_tag_tagid` foreign key (`tagid`) references `tb_tag` (`tagid`); |
| 234 | + |
| 235 | +alter table `tb_login_log` add constraint `fk_login_log_userid` foreign key (`userid`) references `tb_user` (`userid`); |
| 236 | + |
| 237 | +alter table `tb_record` add constraint `fk_record_houseid` foreign key (`houseid`) references `tb_house_info` (`houseid`); |
| 238 | + |
| 239 | +alter table `tb_record` add constraint `fk_record_userid` foreign key (`userid`) references `tb_user` (`userid`); |
| 240 | + |
| 241 | +alter table `tb_user_token` add constraint `fk_token_userid` foreign key (`userid`) references `tb_user` (`userid`); |
| 242 | + |
| 243 | +alter table `tb_user_role` add constraint `uni_user_role` unique (`userid`, `roleid`); |
| 244 | + |
| 245 | +alter table `tb_role_privilege` add constraint `uni_role_priv` unique (`roleid`, `privid`); |
| 246 | + |
| 247 | +alter table `tb_role_privilege` add constraint `fk_role_privilege_privid` foreign key (`privid`) references `tb_privilege` (`privid`); |
| 248 | + |
| 249 | +alter table `tb_role_privilege` add constraint `fk_role_privilege_roleid` foreign key (`roleid`) references `tb_role` (`roleid`); |
| 250 | + |
| 251 | +alter table `tb_user_role` add constraint `fk_user_role_roleid` foreign key (`roleid`) references `tb_role` (`roleid`); |
| 252 | + |
| 253 | +alter table `tb_user_role` add constraint `fk_user_role_userid` foreign key (`userid`) references `tb_user` (`userid`); |
0 commit comments