-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.py
34 lines (30 loc) · 957 Bytes
/
database.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
import scraperwiki
def create_db():
# main table
# automatic, without foreign keys set :(
# section table
scraperwiki.sqlite.execute('''
CREATE TABLE IF NOT EXISTS sections(
id INTEGER PRIMARY KEY,
name TEXT,
parent_section_id INTEGER,
FOREIGN KEY (parent_section_id) REFERENCES sections(id))
''')
# people table
scraperwiki.sqlite.execute('''
CREATE TABLE IF NOT EXISTS people(
id INTEGER PRIMARY KEY,
name TEXT,
email TEXT,
other TEXT,
section_id INTEGER,
FOREIGN KEY (section_id) REFERENCES sections(id))
''')
# categories table
scraperwiki.sqlite.execute('''
CREATE TABLE IF NOT EXISTS categories(
id INTEGER PRIMARY KEY,
name TEXT,
parent_category INTEGER,
FOREIGN KEY (parent_category) REFERENCES categories(id))
''')