-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.sql
143 lines (128 loc) · 6.41 KB
/
db.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
drop database if exists tech_award_2024;
create database tech_award_2024;
use tech_award_2024;
drop table if exists channels;
create table channels (
id int auto_increment primary key, -- Auto-incrementing primary key
chat_id varchar(255) not null unique, -- Equivalent to MongoDB String, with UNIQUE constraint
group_id varchar(255) not null unique, -- Equivalent to MongoDB String, with UNIQUE constraint
username varchar(255) not null, -- Equivalent to MongoDB String
title varchar(255) not null, -- Equivalent to MongoDB String
description text, -- Equivalent to MongoDB String, optional
member_count int not null default 0, -- Equivalent to MongoDB Number with a default value of 0
is_active boolean default true, -- Equivalent to MongoDB Boolean with a default value of true
created_at datetime default current_timestamp, -- MongoDB timestamps: createdAt
updated_at datetime default current_timestamp on update current_timestamp -- MongoDB timestamps: updatedAt
);
drop table if exists messages;
create table messages (
id int auto_increment primary key, -- Auto-incrementing primary key
msg_id varchar(255) not null unique, -- Equivalent to MongoDB String with unique constraint
chat_id varchar(255) not null, -- Equivalent to MongoDB String
group_id varchar(255) not null, -- Equivalent to MongoDB String
content text not null, -- Equivalent to MongoDB String (for longer text)
is_active boolean default false, -- Equivalent to MongoDB Boolean with default value
created_at timestamp default current_timestamp, -- MongoDB timestamps: createdAt
updated_at timestamp default current_timestamp on update current_timestamp -- MongoDB timestamps: updatedAt
);
-- Ensure that both `chat_id` and `group_id` are unique together
create unique index unique_chat_supergroup on channels (chat_id, group_id);
drop table if exists jobs;
create table jobs (
id int auto_increment primary key, -- Auto-incrementing primary key
is_job_vacancy boolean, -- Equivalent to MongoDB Boolean
message_id varchar(255) unique, -- Reference to a Message table
job_name varchar(255), -- Equivalent to MongoDB String
company_name varchar(255), -- Equivalent to MongoDB String
job_type varchar(255), -- Equivalent to MongoDB String
job_salary varchar(255), -- Equivalent to MongoDB String
job_descriptions text, -- Equivalent to MongoDB String for longer text
input_language varchar(50), -- Equivalent to MongoDB String
job_date date, -- MongoDB timestamps: createdAt
created_at datetime default current_timestamp, -- today
updated_at datetime default current_timestamp on update current_timestamp -- MongoDB timestamps: updatedAt
);
drop table if exists job_locations;
create table job_locations (
id int auto_increment primary key, -- Auto-incrementing primary key
job_id int, -- Foreign key referencing jobs table
country_code varchar(10), -- Equivalent to MongoDB String
country varchar(255), -- Equivalent to MongoDB String
city varchar(255), -- Equivalent to MongoDB String
full_address text, -- Longer text for the full address
is_remote_work boolean, -- Equivalent to MongoDB Boolean
foreign key (job_id) references jobs(id) on delete cascade -- Establishing foreign key relationship
);
drop table if exists contact_informations;
create table contact_informations (
id int auto_increment primary key, -- Auto-incrementing primary key
job_id int, -- Foreign key referencing jobs table
type varchar(255) not null, -- Equivalent to MongoDB String
value varchar(255) not null, -- Equivalent to MongoDB String
foreign key (job_id) references jobs(id) on delete cascade -- Establishing foreign key relationship
);
drop table if exists job_responsibilities;
create table job_responsibilities (
id int auto_increment primary key, -- Auto-incrementing primary key
job_id int, -- Foreign key referencing jobs table
responsibility text, -- Equivalent to MongoDB String (for longer text)
foreign key (job_id) references jobs(id) on delete cascade -- Establishing foreign key relationship
);
drop table if exists requirement_skills;
create table requirement_skills (
id int auto_increment primary key, -- Auto-incrementing primary key
job_id int, -- Foreign key referencing jobs table
skill varchar(255), -- Equivalent to MongoDB String
foreign key (job_id) references jobs(id) on delete cascade -- Establishing foreign key relationship
);
drop table if exists occupations;
create table occupations (
id int auto_increment primary key, -- Auto-incrementing primary key
job_id int, -- Foreign key referencing jobs table
occupation varchar(255), -- Equivalent to MongoDB String
foreign key (job_id) references jobs(id) on delete cascade -- Establishing foreign key relationship
);
drop table if exists additional_comments;
create table additional_comments (
id int auto_increment primary key, -- Auto-incrementing primary key
job_id int, -- Foreign key referencing jobs table
comment text, -- Equivalent to MongoDB String (for longer text)
foreign key (job_id) references jobs(id) on delete cascade -- Establishing foreign key relationship
);
drop table if exists search_keywords;
create table search_keywords (
id int auto_increment primary key, -- Auto-incrementing primary key
job_id int, -- Foreign key referencing jobs table
keyword varchar(255), -- Equivalent to MongoDB String
foreign key (job_id) references jobs(id) on delete cascade -- Establishing foreign key relationship
);
drop view if exists vw_jobs;
create view vw_jobs as (
select jobs.*, jl.city, jl.country, jl.country_code from jobs
inner join job_locations jl on jobs.id = jl.job_id
);
drop view if exists vw_by_country;
create view vw_by_country as
select city, count(*) as count from job_locations
group by city
order by count desc
limit 10;
# YANGI ERA ...
drop table if exists users;
create table users (
id int unsigned auto_increment primary key,
phone_num varchar(255) unique null,
first_name varchar(255) null,
last_name varchar(255) null,
birth_date date,
created_at timestamp default current_timestamp,
updated_at timestamp default current_timestamp on update current_timestamp
);
drop table if exists sms_code;
create table sms_code (
id int unsigned auto_increment primary key,
user_id int,
code int,
status int default 0,
foreign key (id) references users(id) on delete cascade
);