forked from mohamed20o03/Voting_system
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserSchema.sql
More file actions
59 lines (52 loc) · 1.85 KB
/
UserSchema.sql
File metadata and controls
59 lines (52 loc) · 1.85 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
USE voting_system;
-- Geographic hierarchy tables
CREATE TABLE Countries (
code VARCHAR(3) PRIMARY KEY COMMENT 'Country code (ISO)',
name VARCHAR(100) NOT NULL UNIQUE
);
CREATE TABLE States_Governorates (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
country_code VARCHAR(3) NOT NULL,
FOREIGN KEY (country_code) REFERENCES Countries(code) ON DELETE CASCADE,
UNIQUE KEY (country_code, name)
);
CREATE TABLE Cities (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
states_governorates_id INT NOT NULL,
FOREIGN KEY (states_governorates_id) REFERENCES States_Governorates(id) ON DELETE CASCADE,
UNIQUE KEY (states_governorates_id, name)
);
CREATE TABLE Districts (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
city_id INT NOT NULL,
FOREIGN KEY (city_id) REFERENCES Cities(id) ON DELETE CASCADE,
UNIQUE KEY (city_id, name)
);
CREATE TABLE Users (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
middle_name VARCHAR(50),
last_name VARCHAR(50) NOT NULL,
gender ENUM('male', 'female') NOT NULL,
birth_date DATE NOT NULL,
email VARCHAR(100) UNIQUE,
password VARCHAR(255) NOT NULL,
phone VARCHAR(20),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
current_address VARCHAR(255),
account_verified BOOLEAN DEFAULT FALSE,
profile_image VARCHAR(255)
);
-- The address listed below is the permanent address as registered on the national ID card of each nationality held by the individual.
CREATE TABLE locates (
user_id INT NOT NULL,
district_id INT NOT NULL,
national_id VARCHAR(20) NOT NULL,
FOREIGN KEY (user_id) REFERENCES Users(id) ON DELETE CASCADE,
FOREIGN KEY (district_id) REFERENCES Districts(id) ON DELETE CASCADE,
PRIMARY KEY (district_id, national_id)
);
select 'user ok';