forked from PyAr/PyCamp_Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_schemma.py
67 lines (54 loc) · 1.93 KB
/
db_schemma.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
import sqlite3
def tables_maker(cursor):
'''creates all tables schema if they don't exist'''
c = cursor
# projects table
c.execute('''CREATE TABLE IF NOT EXISTS projects (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
difficult_level INTEGER,
theme TEXT
);''')
# pycampistas table
c.execute('''CREATE TABLE IF NOT EXISTS pycampistas (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
arrive DATETIME,
leave DATETIME
);''')
# slots table
c.execute('''CREATE TABLE IF NOT EXISTS slots (
id INTEGER PRIMARY KEY AUTOINCREMENT,
code TEXT,
when DATETIME
);''')
# available_slots table
c.execute('''CREATE TABLE IF NOT EXISTS available_slots (
id INTEGER PRIMARY KEY AUTOINCREMENT,
pycampista_id INTEGER REFERENCES pycampistas(id) ON UPDATE CASCADE,
slot_id INTEGER REFERENCES slots(id) ON UPDATE CASCADE
);''')
# project_owner table
c.execute('''CREATE TABLE IF NOT EXISTS project_owner (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER REFERENCES projects(id) ON UPDATE CASCADE,
pycampista_id INTEGER REFERENCES pycampistas(id) ON UPDATE CASCADE
);''')
# votes table
c.execute('''CREATE TABLE IF NOT EXISTS votes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER REFERENCES projects(id) ON UPDATE CASCADE,
pycampista_id INTEGER REFERENCES pycampistas(id) ON UPDATE CASCADE,
interest INTEGER
);''')
# schedule_slots table
c.execute('''CREATE TABLE IF NOT EXISTS schedule_slots (
id INTEGER PRIMARY KEY AUTOINCREMENT,
slot_id INTEGER REFERENCES slots(id) ON UPDATE CASCADE,
project_id INTEGER REFERENCES projects(id) ON UPDATE CASCADE
);''')
def database():
conn = sqlite3.connect('pycamp_projects.db')
c = conn.cursor()
tables_maker(c)
return conn, c