-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_db.py
57 lines (44 loc) · 1.51 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
52
53
54
55
56
57
import sqlite3
from misc.config import config
import logging
logging.basicConfig(level=logging.DEBUG)
def connect_db():
return sqlite3.connect(config['DATABASE']['db_path'])
def init_table():
connection = connect_db()
cursor = connection.cursor()
try:
cursor.execute('''CREATE TABLE measurements
(msm_id int PRIMARY KEY,
monitoring_goal text,
query_type text,
target text,
ts int,
running bool);''')
connection.commit()
except sqlite3.OperationalError as e:
logging.error(e)
try:
cursor.execute('''CREATE TABLE measurement_data (
msm_id int,
monitoring_goal text,
query_type text,
target text,
ts int,
vp text,
vals text,
PRIMARY KEY (msm_id, monitoring_goal, query_type, target, ts, vp, vals)
);''')
connection.commit()
except sqlite3.OperationalError as e:
logging.error(e)
try:
cursor.execute('''CREATE TABLE excluded_vps (
vp text,
PRIMARY KEY (vp)
);''')
connection.commit()
except sqlite3.OperationalError as e:
logging.error(e)
connection.close()
init_table()