-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed_db.py
More file actions
41 lines (30 loc) · 905 Bytes
/
seed_db.py
File metadata and controls
41 lines (30 loc) · 905 Bytes
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
import os
import json
import crud
import model
import server
os.system("dropdb -U postgres python-capstone-db")
os.system("createdb -U postgres python-capstone-db")
model.connect_to_db(server.app)
model.db.create_all()
for n in range(3):
email = f"user{n}@test.com"
password = "test"
user = crud.create_user(email, password)
model.db.session.add(user)
model.db.session.commit()
with open("data/goals.json") as f:
goal_data = json.loads(f.read())
goals_in_db = []
for goal in goal_data:
description, picture_path, deadline, complete, user_id = (
goal["description"],
goal["picture_path"],
goal["deadline"],
goal["complete"],
goal["user_id"]
)
db_goal = crud.create_goal(description, picture_path, deadline, complete, user_id)
goals_in_db.append(db_goal)
model.db.session.add_all(goals_in_db)
model.db.session.commit()