-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshcema.sql
68 lines (64 loc) · 1.68 KB
/
shcema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
create table User(
id int primary key ,
name varchar(255) not null,
phone varchar(255) not null,
address varchar(255),
email varchar(255),
type enum('Landlord','Tenant','Agent')
);
create table Apartment (
id int primary key ,
number varchar(255) not null,
address varchar(255),
area int not null,
owner int references User(id)
);
create table Topic(
id int primary key ,
title varchar(255) not null,
uid int references User(id),
content text,
image1 varchar(255),
image2 varchar(255)
);
create table Reply(
id int primary key ,
uid int references User(id),
tid int references Topic(id),
content text not null,
rtime date not null,
image1 varchar(255),
image2 varchar(255)
);
create table FromUser(
id int primary key references User(id)
);
create table ToUser(
id int primary key references User(id)
);
create table Message(
id int primary key ,
mfrom int references FromUser(id),
mto int references ToUser(id),
content text not null,
mtime date not null
);
create table Schedule(
id int primary key ,
sfrom int references FromUser(id),
sto int references ToUser(id),
content text not null,
stime date not null
);
DELIMITER |
create trigger grant_access after insert on User
for each row begin
insert into FromUser set id = new.id;
insert into ToUser set id = new.id;
end
|
create trigger revoke_access after delete on User
for each row begin
delete from FromUser where FromUser.`id` = old.`id`;
delete from ToUser where ToUser.`id` = old.`id`;
end|