-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.sql
139 lines (116 loc) · 2.92 KB
/
init.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
create database batshu_db;
use batshu_db;
CREATE TABLE `user` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`uid` varchar(255) NOT NULL,
`real_name` varchar(255) NULL,
`bank_name` varchar(255) NULL,
`account_number` varchar(255) NULL
);
CREATE TABLE `accident` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`content_title` varchar(255) NOT NULL,
`content_description` varchar(255) NOT NULL,
`accident_start_time` datetime NOT NULL,
`accident_end_time` datetime NOT NULL,
`created_at` datetime NOT NULL,
`accident_location` point NOT NULL,
`place_name` varchar(255) NOT NULL,
`car_model_name` varchar(255),
`license_plate` varchar(255),
`bounty` int NULL,
`uid` varchar(255) NOT NULL
);
CREATE TABLE `observe` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`content_title` varchar(255) NOT NULL,
`content_description` varchar(255) NOT NULL,
`observe_start_time` datetime NOT NULL,
`observe_end_time` datetime NOT NULL,
`created_at` datetime NOT NULL,
`observe_location` point NOT NULL,
`place_name` varchar(255) NOT NULL,
`car_model_name` varchar(255),
`license_plate` varchar(255),
`uid` varchar(255) NOT NULL,
`video_id` int NOT NULL
);
CREATE TABLE `video` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`status` varchar(255) NOT NULL,
`video_url` varchar(255) NOT NULL,
`thumbnail_url` varchar(255)
);
CREATE TABLE `accident_photo` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`photo_url` varchar(255) NOT NULL,
`accident_id` int NOT NULL
);
CREATE TABLE `room` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`report_uid` varchar(255) NOT NULL,
`uid` varchar(255) NOT NULL,
`accident_id` int,
`observe_id` int
);
CREATE TABLE `message` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`uid` varchar(255) NOT NULL,
`room_id` int NOT NULL,
`message_text` varchar(255) NOT NULL,
`created_at` datetime NOT NULL,
`message_type` varchar(255) NOT NULL
);
ALTER TABLE `user` ADD INDEX `idx_uid` (`uid`);
ALTER TABLE `accident` ADD CONSTRAINT `FK_user_TO_accident_1` FOREIGN KEY (
`uid`
)
REFERENCES `user` (
`uid`
);
ALTER TABLE `observe` ADD CONSTRAINT `FK_video_TO_observe_1` FOREIGN KEY (
`video_id`
)
REFERENCES `video` (
`id`
);
ALTER TABLE `observe` ADD CONSTRAINT `FK_user_TO_observe_1` FOREIGN KEY (
`uid`
)
REFERENCES `user` (
`uid`
);
ALTER TABLE `accident_photo` ADD CONSTRAINT `FK_accident_TO_accident_photo_1` FOREIGN KEY (
`accident_id`
)
REFERENCES `accident` (
`id`
);
ALTER TABLE `room` ADD CONSTRAINT `FK_user_TO_room_1` FOREIGN KEY (
`report_uid`
)
REFERENCES `user` (
`uid`
);
ALTER TABLE `room` ADD CONSTRAINT `FK_user_TO_room_2` FOREIGN KEY (
`uid`
)
REFERENCES `user` (
`uid`
);
ALTER TABLE `message` ADD CONSTRAINT `FK_user_TO_message_1` FOREIGN KEY (
`uid`
)
REFERENCES `user` (
`uid`
);
ALTER TABLE `message` ADD CONSTRAINT `FK_room_TO_message_1` FOREIGN KEY (
`room_id`
)
REFERENCES `room` (
`id`
);
GRANT ALL PRIVILEGES ON batshu_db.* TO 'root'@'%';
flush privileges;
use mysql;
select user, host from user;