-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit_db.py
51 lines (46 loc) · 1.34 KB
/
init_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
#!/bin/python3.6
import sqlite3
from settings import DB_NAME
# Open DB
conn = sqlite3.connect(DB_NAME)
c = conn.cursor()
# Create tables
try:
query = ('CREATE TABLE team('
'chat_id integer primary key,'
'team_name text,'
'leader_name text);')
c.execute(query)
query = ('CREATE TABLE riddle('
'ridd_id text primary key,'
'kind text,'
'question text,'
'answer1 text,'
'answer2 text,'
'answer3 text,'
'answer4 text,'
'answer5 text,'
'answer6 text,'
'solution char,'
'latitude int,'
'longitude int,'
'help_img text,'
'msg_success text,'
'msg_error text,'
'sorting integer)');
c.execute(query)
query = ('CREATE TABLE solved_riddle('
'team integer,'
'riddle integer,'
'timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,'
'foreign key(team) references team(chat_id),'
'foreign key(riddle) references riddle(ridd_id),'
'primary key(team, riddle));')
c.execute(query)
query = ('CREATE TABLE admin(chat_id integer primary_key);')
c.execute(query)
conn.commit()
except Exception as e:
print(e)
finally:
conn.close()