-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_db.py
99 lines (84 loc) · 3.18 KB
/
create_db.py
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
import sqlite3
connection = sqlite3.connect('db/database.db')
cur = connection.cursor()
cur.execute('''
CREATE TABLE IF NOT EXISTS client (
client_id INTEGER PRIMARY KEY AUTOINCREMENT,
telegram_id VARCHAR(50) NOT NULL,
user_name_id INT,
first_name VARCHAR (50),
last_name VARCHAR (50),
more_info TEXT,
mobile_number VARCHAR (17),
client_enabled BOOLEAN DEFAULT 1
)
''')
cur.execute('''
CREATE TABLE IF NOT EXISTS admin (
admin_id INTEGER PRIMARY KEY AUTOINCREMENT,
telegram_id VARCHAR(50) NOT NULL,
user_name_id INT,
first_name VARCHAR (50),
last_name VARCHAR (50),
more_info TEXT,
mobile_number VARCHAR (17),
admin_enabled BOOLEAN DEFAULT 1,
level_add_client BOOLEAN DEFAULT 0,
level_add_region BOOLEAN DEFAULT 0,
level_add_data BOOLEAN DEFAULT 0,
level_add_admin BOOLEAN DEFAULT 0,
level_send BOOLEAN DEFAULT 0,
date_registered TEXT NOT NULL
);
''')
cur.execute('''
CREATE TABLE IF NOT EXISTS region (
region_id INTEGER PRIMARY KEY AUTOINCREMENT,
blame_admin INTEGER NOT NULL,
region_name VARCHAR (50) NOT NULL,
more_info TEXT,
date_added TEXT NOT NULL,
region_enabled BOOLEAN DEFAULT 1,
FOREIGN KEY (blame_admin) REFERENCES admin (admin_id)
);
''')
cur.execute('''
CREATE TABLE IF NOT EXISTS data_file (
data_id INTEGER PRIMARY KEY AUTOINCREMENT,
data_name VARCHAR(50),
type VAHCHAR(80),
data_file_path TEXT,
more_info TEXT,
data_enabled BOOLEAN DEFAULT 1
);
''')
# LINK TABLE
cur.execute('''
CREATE TABLE IF NOT EXISTS enrollment_lt (
client_id INT NOT NULL,
region_id INT NOT NULL,
blame_admin INT NOT NULL,
date_enrollment TEXT NOT NULL,
client_region_enabled BOOLEAN DEFAULT 1,
PRIMARY KEY (client_id, region_id),
FOREIGN KEY (client_id) REFERENCES client (client_id),
FOREIGN KEY (region_id) REFERENCES region (region_id),
FOREIGN KEY (blame_admin) REFERENCES admin (admin_id)
);
''')
cur.execute('''
CREATE TABLE IF NOT EXISTS reg_data_lt (
region_id INT NOT NULL,
data_id INT NOT NULL,
blame_admin INT NOT NULL,
date_added TEXT NOT NULL,
region_data_enabled BOOLEAN DEFAULT 1,
PRIMARY KEY (region_id, data_id),
FOREIGN KEY (region_id) REFERENCES region (region_id),
FOREIGN KEY (data_id) REFERENCES data_file (data_id),
FOREIGN KEY (blame_admin) REFERENCES admin (admin_id)
);
''')
print('database created')
cur.close()
connection.close()