-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodel.py
More file actions
50 lines (40 loc) · 1.18 KB
/
Copy pathmodel.py
File metadata and controls
50 lines (40 loc) · 1.18 KB
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
from sqlalchemy import (
Table, Column, String, MetaData,
ForeignKey, Integer, Date)
from alchemy import engine
import sys
meta = MetaData()
account_table = Table(
'account', meta,
Column('id', Integer, primary_key=True),
Column('first_name', String, nullable=False),
Column('last_name', String, nullable=False),
Column('email', String, nullable=False),
Column('birth_date', Date, nullable=False),
Column('locale', String, nullable=False)
)
address_table = Table(
'address', meta,
Column('id', Integer, primary_key=True),
Column('account_id', Integer, ForeignKey('account.id')),
Column('line1', String, nullable=False),
Column('city', String, nullable=False),
Column('state', String),
Column('zip', String, nullable=False)
)
def create_all():
with engine.connect() as conn:
with conn.begin():
meta.create_all(conn)
meta.reflect(conn)
def drop_all():
with engine.connect() as conn:
with conn.begin():
meta.drop_all(conn)
meta.reflect(conn)
if __name__ == '__main__':
params = sys.argv[1:]
if 'drop' in params:
drop_all()
else:
create_all()