-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_scheme.sql
More file actions
227 lines (173 loc) · 8.93 KB
/
create_scheme.sql
File metadata and controls
227 lines (173 loc) · 8.93 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
begin;
drop schema if exists "police" cascade;
create schema "police";
CREATE TABLE police.tcl_role
(
id_role serial,
name_role character varying(50) not null,
PRIMARY KEY (id_role)
--on delete cascade on update cascade
);
CREATE TABLE police.t_cell
(
id_cell serial,
number_of_places integer not null,
employed_places integer not null,
PRIMARY KEY (id_cell)
--on delete cascade on update cascade
);
CREATE TABLE police.t_person
(
id_person serial,
last_name character varying(50) not null,
first_name character varying(50) not null,
patronymic character varying(50),
PRIMARY KEY (id_person)
--on delete cascade on update cascade
);
CREATE TABLE police.tcl_case_name
(
id_case_name serial,
case_name character varying(50) not null,
severity_of_crime character varying(50) not null,
PRIMARY KEY (id_case_name)
--on delete cascade on update cascade
);
CREATE TABLE police.tcl_contacts_type
(
id_contacts_info serial,
type_name character varying(50) not null,
PRIMARY KEY (id_contacts_info)
--on delete cascade on update cascade
);
CREATE TABLE police.t_department
(
id_department serial,
department_name character varying(50) not null,
PRIMARY KEY (id_department)
--on delete cascade on update cascade
);
CREATE TABLE police.tcl_post
(
id_post serial,
id_parent_post integer not null,
function character varying(50) not null,
PRIMARY KEY (id_post),
FOREIGN KEY (id_parent_post) REFERENCES police.tcl_post (id_post)
--on delete cascade on update cascade
);
CREATE TABLE police.t_person_contacts
(
id_person_contacts serial,
id_person integer not null,
id_contacts_info integer not null,
value_contacts_info character varying(50) not null,
PRIMARY KEY (id_person_contacts),
FOREIGN KEY (id_person) REFERENCES police.t_person (id_person),
FOREIGN KEY (id_contacts_info) REFERENCES police.tcl_contacts_type (id_contacts_info)
--on delete cascade on update cascade
);
CREATE TABLE police.t_employee
(
id_employee serial,
id_post integer not null,
id_department integer not null,
last_name character varying(50) not null,
first_name character varying(50) not null,
patronymic character varying(50),
rank character varying(50) not null,
PRIMARY KEY (id_employee),
FOREIGN KEY (id_post) REFERENCES police.tcl_post (id_post),
FOREIGN KEY (id_department) REFERENCES police.t_department (id_department)
--on delete cascade on update cascade
);
CREATE TABLE police.t_employee_contacts
(
id_employee_contacts serial,
id_employee integer not null,
id_contacts_info integer not null,
value_contacts_info character varying(50) not null,
PRIMARY KEY (id_employee_contacts),
FOREIGN KEY (id_employee) REFERENCES police.t_employee (id_employee),
FOREIGN KEY (id_contacts_info) REFERENCES police.tcl_contacts_type (id_contacts_info)
--on delete cascade on update cascade
);
CREATE TABLE police.t_protocol
(
id_protocol serial,
id_employee integer not null,
id_case_name integer not null,
status boolean not null,
PRIMARY KEY (id_protocol),
FOREIGN KEY (id_employee) REFERENCES police.t_employee (id_employee),
FOREIGN KEY (id_case_name) REFERENCES police.tcl_case_name (id_case_name)
--on delete cascade on update cascade
);
CREATE TABLE police.t_evidence
(
id_evidence serial,
id_protocol integer not null,
object_description character varying(100) not null,
storage_box integer,
PRIMARY KEY (id_evidence),
FOREIGN KEY (id_protocol) REFERENCES police.t_protocol (id_protocol)
--on delete cascade on update cascade
);
CREATE TABLE police.t_investigation_participants
(
id_participants serial,
id_role integer not null,
id_protocol integer not null,
id_person integer not null,
id_cell integer,
PRIMARY KEY (id_participants),
FOREIGN KEY (id_role) REFERENCES police.tcl_role (id_role),
FOREIGN KEY (id_protocol) REFERENCES police.t_protocol (id_protocol),
FOREIGN KEY (id_person) REFERENCES police.t_person (id_person),
FOREIGN KEY (id_cell) REFERENCES police.t_cell (id_cell)
--on delete cascade on update cascade
);
------------------------------------------------------------------------------------------
INSERT INTO police.tcl_role (name_role) VALUES ('Подозреваемый');
INSERT INTO police.tcl_role (name_role) VALUES ('Свидетель');
INSERT INTO police.tcl_role (name_role) VALUES ('Потерпевший');
INSERT INTO police.tcl_role (name_role) VALUES ('Подсудимый');
INSERT INTO police.t_cell (number_of_places, employed_places) VALUES (5, 1);
INSERT INTO police.t_person (last_name, first_name, patronymic) VALUES ('Раскольников', 'Родион', 'Романович');
INSERT INTO police.t_person (last_name, first_name, patronymic) VALUES ('Процентщица', 'Алёна', 'Ивановна');
INSERT INTO police.t_person (last_name, first_name, patronymic) VALUES ('Свидригайлов', 'Аркадий', 'Иванович');
INSERT INTO police.t_person (last_name, first_name, patronymic) VALUES ('Сестра', 'Лизавета', 'Ивановна');
INSERT INTO police.t_person (last_name, first_name) VALUES ('Мориарти', 'Джеймс');
INSERT INTO police.tcl_case_name (case_name, severity_of_crime) VALUES ('Двойное убийство', 'Очень Тяжкое');
INSERT INTO police.tcl_case_name (case_name, severity_of_crime) VALUES ('Наполеон преступного мира', 'Загадочное');
INSERT INTO police.tcl_contacts_type (type_name) VALUES ('Адрес');
INSERT INTO police.tcl_contacts_type (type_name) VALUES ('Телефон');
INSERT INTO police.t_department (department_name) VALUES ('3-й полицейский участок Казанской части');
INSERT INTO police.t_department (department_name) VALUES ('Скотлен-ярд');
INSERT INTO police.tcl_post(id_parent_post,function) VALUES (1, 'Начальник отдела');
INSERT INTO police.tcl_post(id_parent_post,function) VALUES (1, 'Следователь');
INSERT INTO police.tcl_post(id_parent_post,function) VALUES (3, 'Сыщик');
INSERT INTO police.t_person_contacts(id_person,id_contacts_info,value_contacts_info) values (1, 2, 'Гражданская ул., д. 19');
INSERT INTO police.t_person_contacts(id_person,id_contacts_info,value_contacts_info) values (2, 2, 'Казначейская ул., д. 7, кв. 13');
INSERT INTO police.t_person_contacts(id_person,id_contacts_info,value_contacts_info) values (4, 2, 'Набережная канала Грибоедова, д. 104, кв. 13');
INSERT INTO police.t_person_contacts(id_person,id_contacts_info,value_contacts_info) values (3, 2, 'Гостинница, сосед Сони Мармеладовой');
INSERT INTO police.t_person_contacts(id_person,id_contacts_info,value_contacts_info) values (5, 2, '???');
INSERT INTO police.t_person_contacts(id_person,id_contacts_info,value_contacts_info) values (5, 1, '777');
INSERT INTO police.t_employee(id_post,id_department,last_name,first_name,rank) values (3, 2, 'Холмс', 'Шерлок', 'Независимый консультант');
INSERT INTO police.t_employee(id_post,id_department,last_name,first_name,patronymic,rank) values (2, 1, 'Следователь', 'Порфирий', 'Петрович', 'Старший сержант');
INSERT INTO police.t_employee(id_post,id_department,last_name,first_name,patronymic,rank) values (1, 1, 'НеЗнаю', 'НеПомню', 'Какой-тович', 'Допустим Майор');
INSERT INTO police.t_employee_contacts(id_employee,id_contacts_info,value_contacts_info) values (1, 2, '666');
INSERT INTO police.t_employee_contacts(id_employee,id_contacts_info,value_contacts_info) values (1, 1, 'Бэйкер-стрит, д. 221Б');
INSERT INTO police.t_employee_contacts(id_employee,id_contacts_info,value_contacts_info) values (2, 2, '11-134-2323-43-23');
INSERT INTO police.t_employee_contacts(id_employee,id_contacts_info,value_contacts_info) values (3, 1, 'Всегда в отпуске');
INSERT INTO police.t_protocol(id_employee,id_case_name,status) values (2, 1, false);
INSERT INTO police.t_protocol(id_employee,id_case_name,status) values (1, 2, true);
INSERT INTO police.t_evidence(id_protocol,object_description,storage_box) values (1, 'Топор', 1);
INSERT INTO police.t_evidence(id_protocol,object_description,storage_box) values (1, 'Старухины драгоценности под камнем', 1);
INSERT INTO police.t_evidence(id_protocol,object_description,storage_box) values (2, 'Отсутствуют, но будут найдены', 2);
INSERT INTO police.t_investigation_participants(id_role,id_protocol,id_person,id_cell) values (4, 1, 1, 1);
INSERT INTO police.t_investigation_participants(id_role,id_protocol,id_person) values (3, 1, 2);
INSERT INTO police.t_investigation_participants(id_role,id_protocol,id_person) values (3, 1, 4);
INSERT INTO police.t_investigation_participants(id_role,id_protocol,id_person) values (2, 1, 3);
INSERT INTO police.t_investigation_participants(id_role,id_protocol,id_person) values (1, 2, 5);
end;