-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschema.py
57 lines (49 loc) · 1.97 KB
/
schema.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
from sqlite3 import connect
DBPATH = "final_project.db"
def schema(dbpath=DBPATH):
with connect(dbpath) as connection:
cursor = connection.cursor()
DROPSQL = "DROP TABLE IF EXISTS {tablename};"
cursor.execute(DROPSQL.format(tablename="np_accounts"))
SQL = """ CREATE TABLE np_accounts (
pk INTEGER PRIMARY KEY AUTOINCREMENT,
company_name VARCHAR,
ein VARCHAR,
username VARCHAR NOT NULL UNIQUE,
email VARCHAR,
password_hash VARCHAR
);"""
cursor.execute(SQL)
cursor.execute(DROPSQL.format(tablename="shipper_accounts"))
SQL = """ CREATE TABLE shipper_accounts (
pk INTEGER PRIMARY KEY AUTOINCREMENT,
company_name VARCHAR,
username VARCHAR NOT NULL UNIQUE,
email VARCHAR,
password_hash VARCHAR
);"""
cursor.execute(SQL)
cursor.execute(DROPSQL.format(tablename="routes"))
SQL = """ CREATE TABLE routes (
pk INTEGER PRIMARY KEY AUTOINCREMENT,
shipper_account_id INTEGER,
departure_location VARCHAR,
departure_date INTEGER,
arrival_location VARCHAR,
arrival_date INTEGER,
total_containers INTEGER,
available_containers INTEGER,
FOREIGN KEY( shipper_account_id) REFERENCES shipper_accounts(pk)
);"""
cursor.execute(SQL)
cursor.execute(DROPSQL.format(tablename="partnerships"))
SQL = """ CREATE TABLE partnerships (
pk INTEGER PRIMARY KEY AUTOINCREMENT,
np_account_id INTEGER,
route_id INTEGER,
containers INTEGER,
FOREIGN KEY (np_account_id) REFERENCES np_accounts(pk),
FOREIGN KEY (route_id) REFERENCES routes(pk)
);"""
cursor.execute(SQL)
schema()