-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_db.py
More file actions
46 lines (39 loc) · 904 Bytes
/
init_db.py
File metadata and controls
46 lines (39 loc) · 904 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
41
42
43
44
45
46
import os
from config import db
from src.v0.models import Widget
# Init Widget
WIDGET = [
{
"name": "SpinnerDoo",
"number_of_parts": 15,
},
{
"name": "BouncerBon",
"number_of_parts": 1,
},
{
"name": "SideSmasher",
"number_of_parts": 5,
},
{
"name": "BobNSlide",
"number_of_parts": 2,
},
]
# Delete database file if it exists currently
if os.path.exists("db/widget.db"):
os.remove("db/widget.db")
# Create the database
db.create_all()
# Populate the widget db
for widget in WIDGET:
widg = Widget(
name=widget.get("name"),
number_of_parts=widget.get("number_of_parts")
)
db.session.add(widg)
for widget in Widget.query.all():
for column in widget.__table__.columns:
print(f"{column.name} = {getattr(widget, column.name)}")
print("\n")
db.session.commit()