forked from learn-co-curriculum/python-p3-freebie-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.py
More file actions
44 lines (31 loc) · 1.05 KB
/
Copy pathseed.py
File metadata and controls
44 lines (31 loc) · 1.05 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
#!/usr/bin/env python3
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Base, Company, Dev
DB_URL = 'sqlite:///freebies.db'
def run_seed():
engine = create_engine(DB_URL, echo=False)
Session = sessionmaker(bind=engine)
session = Session()
Base.metadata.create_all(engine)
session.query(Company).delete()
session.query(Dev).delete()
session.commit()
c1 = Company(name='Stripe', founding_year=2010)
c2 = Company(name='GitHub', founding_year=2008)
c3 = Company(name='HashiCorp', founding_year=2012)
d1 = Dev(name='Ada')
d2 = Dev(name='Linus')
d3 = Dev(name='Grace')
session.add_all([c1, c2, c3, d1, d2, d3])
session.commit()
f1 = c1.give_freebie(d1, 'T-shirt', 20)
f2 = c1.give_freebie(d1, 'Sticker pack', 2)
f3 = c2.give_freebie(d2, 'Laptop sticker', 1)
f4 = c3.give_freebie(d3, 'Beanie', 15)
session.add_all([f1, f2, f3, f4])
session.commit()
print("Seed complete.")
session.close()
if __name__ == '__main__':
run_seed()