-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateNewDB.py
130 lines (105 loc) · 3.9 KB
/
CreateNewDB.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# CreateNewDB.py
# 2015/12/10 Marcello Barisonzi
# Create an empty DB file from scratch
import pymysql, json
organization_table = """CREATE TABLE organization (
id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL ,
name TEXT,
category_id INTEGER);
"""
# INSERT INTO organization VALUES (NULL,"Hacking Health", NULL);
# INSERT INTO organization VALUES (NULL,"CHU Sainte-Justine", 1);
# INSERT INTO organization VALUES (NULL,"CUSM/MUHC", 1);
# INSERT INTO organization VALUES (NULL,"CHUM", 1);
# INSERT INTO organization VALUES (NULL,"McGill", 7);
# INSERT INTO organization VALUES (NULL,"Concordia", 7);
# INSERT INTO organization VALUES (NULL,"Universit\u00e9 de Montr\u00e9al", 7);
# INSERT INTO organization VALUES (NULL,"UQ\u00c0M", 7);
# INSERT INTO organization VALUES (NULL,"ETS Montr\u00e9al", 7);
# INSERT INTO organization VALUES (NULL,"Ecole Polytechnique de Montr\u00e9al", 7);
# INSERT INTO organization VALUES (NULL,"Desjardins", 4);
# INSERT INTO organization VALUES (NULL,"IBM", 2);
# """
category_table = """CREATE TABLE category (
id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL ,
type TEXT)"""
attendee_table = """CREATE TABLE attendee (
id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL ,
contact_id INTEGER check(typeof("contact_id") = 'integer'),
event_id INTEGER check(typeof("event_id") = 'integer')
)"""
responsible_table = """CREATE TABLE responsible (
id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL ,
contact_id INTEGER check(typeof("contact_id") = 'integer'),
contactHH_id INTEGER check(typeof("contactHH_id") = 'integer')
)"""
contact_table = """CREATE TABLE contact (
id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL ,
last_name TEXT,
first_name TEXT,
email TEXT,
title TEXT,
responsible_id BOOL,
organization_id BOOL,
role TEXT,
category_id BOOL,
home_phone TEXT,
work_phone TEXT,
mobile_phone TEXT,
notes TEXT,
is_volunteer BOOL,
is_active BOOL,
is_vip BOOL
)"""
event_table = """CREATE TABLE event (
id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL ,
eventbrite_id INTEGER,
date DATETIME,
event_title TEXT,
volunteer_call BOOL)"""
interaction_table = """CREATE TABLE interaction (
id INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL ,
contact_id INTEGER,
responsible_id INTEGER,
event_id INTEGER,
date DATETIME,
notes TEXT)"""
# volunteer_table = """CREATE TABLE volunteer(
# id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
# last_name TEXT,
# first_name TEXT,
# title TEXT,
# hh_responsible INT,
# role TEXT,
# category_id INT,
# notes TEXT,
# organization_id INT
# , email TEXT)"""
def main():
f=open("pwd.json")
db_params = json.load(f)
f.close()
conn = pymysql.connect(database = db_params["database"],
user = db_params["user"],
password = db_params["password"],
host = db_params["server"]) #,
#ssl = db_params["ssl"])
c = conn.cursor()
# c.executemany("""DROP TABLE organization;
# DROP TABLE attendee;
# DROP TABLE category;
# DROP TABLE contact;
# DROP TABLE event;
# DROP TABLE responsible;
# DROP TABLE interaction""",[])
c.executemany(organization_table, [])
c.executemany(attendee_table, [])
c.execute(category_table)
c.execute(contact_table)
c.execute(event_table)
c.execute(responsible_table)
c.execute(interaction_table)
conn.commit()
return
if __name__ == "__main__":
main()