-
Notifications
You must be signed in to change notification settings - Fork 12
/
HRMSDatabase.sql
386 lines (312 loc) · 11.1 KB
/
HRMSDatabase.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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
-- This script was generated by a beta version of the ERD tool in pgAdmin 4.
-- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.
BEGIN;
CREATE TABLE IF NOT EXISTS public.cities
(
id smallint NOT NULL,
name character varying(50) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.company_staff_verifications
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
user_id integer NOT NULL,
is_approved boolean NOT NULL,
created_at timestamp with time zone NOT NULL,
approval_date time with time zone,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.company_staffs
(
user_id integer NOT NULL,
first_name character varying(50) NOT NULL,
last_name character varying(50) NOT NULL,
PRIMARY KEY (user_id)
);
CREATE TABLE IF NOT EXISTS public.email_activations
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
user_id integer NOT NULL,
activation_code character varying(200) NOT NULL,
email character varying(100) NOT NULL,
is_activated boolean NOT NULL,
created_at timestamp with time zone NOT NULL,
expiration_date timestamp with time zone NOT NULL,
activation_date timestamp with time zone,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.employer_updates
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
user_id integer NOT NULL,
company_staff_id integer,
company_name character varying(100) NOT NULL,
website character varying(100) NOT NULL,
corporate_email character varying(100) NOT NULL,
phone character varying(15) NOT NULL,
updated_at timestamp with time zone NOT NULL,
is_approved boolean NOT NULL,
is_deleted boolean NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.employers
(
user_id integer NOT NULL,
company_name character varying(100) NOT NULL,
website character varying(100) NOT NULL,
corporate_email character varying(100) NOT NULL,
phone character varying(15) NOT NULL,
PRIMARY KEY (user_id)
);
CREATE TABLE IF NOT EXISTS public.job_adverts
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
employer_id integer NOT NULL,
job_position_id integer NOT NULL,
city_id integer NOT NULL,
description character varying NOT NULL,
min_salary integer,
max_salary integer,
number_of_open_positions integer NOT NULL,
created_at timestamp with time zone NOT NULL,
application_deadline timestamp with time zone,
is_active boolean NOT NULL,
is_deleted boolean NOT NULL,
working_type_id smallint,
working_time_id smallint,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_positions
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
title character varying(50) NOT NULL,
created_at timestamp with time zone NOT NULL,
is_active boolean NOT NULL,
is_deleted boolean NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_seeker_cv_educations
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
job_seeker_cv_id integer NOT NULL,
school_name character varying(100) NOT NULL,
department_name character varying(100) NOT NULL,
start_date date NOT NULL,
graduation_date date,
created_at timestamp with time zone NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_seeker_cv_experiences
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
job_seeker_cv_id integer NOT NULL,
job_position_id integer NOT NULL,
workplace_name character varying(100) NOT NULL,
start_date date NOT NULL,
quit_date date,
created_at timestamp with time zone NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_seeker_cv_images
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
job_seeker_cv_id integer NOT NULL,
url character varying NOT NULL,
created_at timestamp with time zone NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_seeker_cv_languages
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
job_seeker_cv_id integer NOT NULL,
language_id character(2) NOT NULL,
level smallint NOT NULL,
created_at timestamp with time zone NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_seeker_cv_skills
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
job_seeker_cv_id integer NOT NULL,
name character varying(100) NOT NULL,
created_at timestamp with time zone NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_seeker_cv_web_sites
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
job_seeker_cv_id integer NOT NULL,
web_site_id smallint NOT NULL,
address character varying(200) NOT NULL,
created_at timestamp with time zone NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_seeker_cvs
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
job_seeker_id integer NOT NULL,
cover_letter character varying(300) NOT NULL,
created_at timestamp with time zone NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.job_seekers
(
user_id integer NOT NULL,
first_name character varying(50) NOT NULL,
last_name character varying(50) NOT NULL,
identity_number character(11) NOT NULL,
birth_date date NOT NULL,
cv_id integer,
PRIMARY KEY (user_id)
);
CREATE TABLE IF NOT EXISTS public.job_seekers_favorite_job_adverts
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
job_seeker_id integer NOT NULL,
job_advert_id integer NOT NULL
);
CREATE TABLE IF NOT EXISTS public.languages
(
id character(2) NOT NULL,
name character varying(50) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.mernis_activations
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
user_id integer NOT NULL,
is_approved boolean NOT NULL,
created_at timestamp with time zone NOT NULL,
approval_date time with time zone,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.users
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
email character varying(100) NOT NULL,
password character varying(100) NOT NULL,
created_at timestamp with time zone NOT NULL,
is_active boolean NOT NULL,
is_deleted boolean NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.web_sites
(
id smallint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 32767 CACHE 1 ),
name character varying(50) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.working_times
(
id smallint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 32767 CACHE 1 ),
name character varying(50) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS public.working_types
(
id smallint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
id smallint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 32767 CACHE 1 ),
name character varying(50) NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE public.company_staff_verifications
ADD FOREIGN KEY (user_id)
REFERENCES public.users (id)
NOT VALID;
ALTER TABLE public.company_staffs
ADD FOREIGN KEY (user_id)
REFERENCES public.users (id)
NOT VALID;
ALTER TABLE public.email_activations
ADD FOREIGN KEY (user_id)
REFERENCES public.users (id)
NOT VALID;
ALTER TABLE public.employer_updates
ADD FOREIGN KEY (user_id)
REFERENCES public.employers (user_id)
NOT VALID;
ALTER TABLE public.employers
ADD FOREIGN KEY (user_id)
REFERENCES public.users (id)
NOT VALID;
ALTER TABLE public.job_adverts
ADD FOREIGN KEY (city_id)
REFERENCES public.cities (id)
NOT VALID;
ALTER TABLE public.job_adverts
ADD FOREIGN KEY (employer_id)
REFERENCES public.employers (user_id)
NOT VALID;
ALTER TABLE public.job_adverts
ADD FOREIGN KEY (job_position_id)
REFERENCES public.job_positions (id)
NOT VALID;
ALTER TABLE public.job_adverts
ADD FOREIGN KEY (working_time_id)
REFERENCES public.working_times (id)
NOT VALID;
ALTER TABLE public.job_adverts
ADD FOREIGN KEY (working_type_id)
REFERENCES public.working_types (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_educations
ADD FOREIGN KEY (job_seeker_cv_id)
REFERENCES public.job_seeker_cvs (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_experiences
ADD FOREIGN KEY (job_position_id)
REFERENCES public.job_positions (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_experiences
ADD FOREIGN KEY (job_seeker_cv_id)
REFERENCES public.job_seeker_cvs (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_images
ADD FOREIGN KEY (job_seeker_cv_id)
REFERENCES public.job_seeker_cvs (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_languages
ADD FOREIGN KEY (job_seeker_cv_id)
REFERENCES public.job_seeker_cvs (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_languages
ADD FOREIGN KEY (language_id)
REFERENCES public.languages (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_skills
ADD FOREIGN KEY (job_seeker_cv_id)
REFERENCES public.job_seeker_cvs (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_web_sites
ADD FOREIGN KEY (job_seeker_cv_id)
REFERENCES public.job_seeker_cvs (id)
NOT VALID;
ALTER TABLE public.job_seeker_cv_web_sites
ADD FOREIGN KEY (web_site_id)
REFERENCES public.web_sites (id)
NOT VALID;
ALTER TABLE public.job_seeker_cvs
ADD FOREIGN KEY (job_seeker_id)
REFERENCES public.job_seekers (user_id)
NOT VALID;
ALTER TABLE public.job_seekers
ADD FOREIGN KEY (cv_id)
REFERENCES public.job_seeker_cvs (id)
NOT VALID;
ALTER TABLE public.job_seekers
ADD FOREIGN KEY (user_id)
REFERENCES public.users (id)
NOT VALID;
ALTER TABLE public.job_seekers_favorite_job_adverts
ADD FOREIGN KEY (job_advert_id)
REFERENCES public.job_adverts (id)
NOT VALID;
ALTER TABLE public.job_seekers_favorite_job_adverts
ADD FOREIGN KEY (job_seeker_id)
REFERENCES public.job_seekers (user_id)
NOT VALID;
ALTER TABLE public.mernis_activations
ADD FOREIGN KEY (user_id)
REFERENCES public.users (id)
NOT VALID;
END;