Skip to content

Commit 020cdfd

Browse files
committed
Fix init database script
1 parent ffe6bd6 commit 020cdfd

File tree

7 files changed

+28
-21
lines changed

7 files changed

+28
-21
lines changed

build-a-rest-api-frontend/source_code_final/init_database.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
]
4747

48+
4849
def get_data_from_table(model):
4950
try:
5051
data = db.session.query(model).all()
@@ -53,6 +54,7 @@ def get_data_from_table(model):
5354
except OperationalError:
5455
return []
5556

57+
5658
def create_database(db):
5759
db.create_all()
5860
for data in PEOPLE_NOTES:
@@ -70,6 +72,7 @@ def create_database(db):
7072
db.session.commit()
7173
print("Created new database")
7274

75+
7376
def update_database(db, existing_people, existing_notes):
7477
db.drop_all()
7578
db.create_all()
@@ -80,6 +83,7 @@ def update_database(db, existing_people, existing_notes):
8083
db.session.commit()
8184
print("Updated existing database")
8285

86+
8387
with app.app_context():
8488
existing_people = get_data_from_table(Person)
8589
existing_notes = get_data_from_table(Note)
@@ -88,6 +92,3 @@ def update_database(db, existing_people, existing_notes):
8892
create_database(db)
8993
else:
9094
update_database(db, existing_people, existing_notes)
91-
92-
93-

build-a-rest-api-frontend/source_code_start/init_database.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
]
4747

48+
4849
def get_data_from_table(model):
4950
try:
5051
data = db.session.query(model).all()
@@ -53,6 +54,7 @@ def get_data_from_table(model):
5354
except OperationalError:
5455
return []
5556

57+
5658
def create_database(db):
5759
db.create_all()
5860
for data in PEOPLE_NOTES:
@@ -70,6 +72,7 @@ def create_database(db):
7072
db.session.commit()
7173
print("Created new database")
7274

75+
7376
def update_database(db, existing_people, existing_notes):
7477
db.drop_all()
7578
db.create_all()
@@ -80,6 +83,7 @@ def update_database(db, existing_people, existing_notes):
8083
db.session.commit()
8184
print("Updated existing database")
8285

86+
8387
with app.app_context():
8488
existing_people = get_data_from_table(Person)
8589
existing_notes = get_data_from_table(Note)
@@ -88,6 +92,3 @@ def update_database(db, existing_people, existing_notes):
8892
create_database(db)
8993
else:
9094
update_database(db, existing_people, existing_notes)
91-
92-
93-

build-a-rest-api-frontend/source_code_step_1/init_database.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
]
4747

48+
4849
def get_data_from_table(model):
4950
try:
5051
data = db.session.query(model).all()
@@ -53,6 +54,7 @@ def get_data_from_table(model):
5354
except OperationalError:
5455
return []
5556

57+
5658
def create_database(db):
5759
db.create_all()
5860
for data in PEOPLE_NOTES:
@@ -70,6 +72,7 @@ def create_database(db):
7072
db.session.commit()
7173
print("Created new database")
7274

75+
7376
def update_database(db, existing_people, existing_notes):
7477
db.drop_all()
7578
db.create_all()
@@ -80,6 +83,7 @@ def update_database(db, existing_people, existing_notes):
8083
db.session.commit()
8184
print("Updated existing database")
8285

86+
8387
with app.app_context():
8488
existing_people = get_data_from_table(Person)
8589
existing_notes = get_data_from_table(Note)
@@ -88,6 +92,3 @@ def update_database(db, existing_people, existing_notes):
8892
create_database(db)
8993
else:
9094
update_database(db, existing_people, existing_notes)
91-
92-
93-

build-a-rest-api-frontend/source_code_step_2/init_database.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
]
4747

48+
4849
def get_data_from_table(model):
4950
try:
5051
data = db.session.query(model).all()
@@ -53,6 +54,7 @@ def get_data_from_table(model):
5354
except OperationalError:
5455
return []
5556

57+
5658
def create_database(db):
5759
db.create_all()
5860
for data in PEOPLE_NOTES:
@@ -70,6 +72,7 @@ def create_database(db):
7072
db.session.commit()
7173
print("Created new database")
7274

75+
7376
def update_database(db, existing_people, existing_notes):
7477
db.drop_all()
7578
db.create_all()
@@ -80,6 +83,7 @@ def update_database(db, existing_people, existing_notes):
8083
db.session.commit()
8184
print("Updated existing database")
8285

86+
8387
with app.app_context():
8488
existing_people = get_data_from_table(Person)
8589
existing_notes = get_data_from_table(Note)
@@ -88,6 +92,3 @@ def update_database(db, existing_people, existing_notes):
8892
create_database(db)
8993
else:
9094
update_database(db, existing_people, existing_notes)
91-
92-
93-

build-a-rest-api-frontend/source_code_step_3/init_database.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
]
4747

48+
4849
def get_data_from_table(model):
4950
try:
5051
data = db.session.query(model).all()
@@ -53,6 +54,7 @@ def get_data_from_table(model):
5354
except OperationalError:
5455
return []
5556

57+
5658
def create_database(db):
5759
db.create_all()
5860
for data in PEOPLE_NOTES:
@@ -70,6 +72,7 @@ def create_database(db):
7072
db.session.commit()
7173
print("Created new database")
7274

75+
7376
def update_database(db, existing_people, existing_notes):
7477
db.drop_all()
7578
db.create_all()
@@ -80,6 +83,7 @@ def update_database(db, existing_people, existing_notes):
8083
db.session.commit()
8184
print("Updated existing database")
8285

86+
8387
with app.app_context():
8488
existing_people = get_data_from_table(Person)
8589
existing_notes = get_data_from_table(Note)
@@ -88,6 +92,3 @@ def update_database(db, existing_people, existing_notes):
8892
create_database(db)
8993
else:
9094
update_database(db, existing_people, existing_notes)
91-
92-
93-

build-a-rest-api-frontend/source_code_step_4/init_database.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
]
4747

48+
4849
def get_data_from_table(model):
4950
try:
5051
data = db.session.query(model).all()
@@ -53,6 +54,7 @@ def get_data_from_table(model):
5354
except OperationalError:
5455
return []
5556

57+
5658
def create_database(db):
5759
db.create_all()
5860
for data in PEOPLE_NOTES:
@@ -70,6 +72,7 @@ def create_database(db):
7072
db.session.commit()
7173
print("Created new database")
7274

75+
7376
def update_database(db, existing_people, existing_notes):
7477
db.drop_all()
7578
db.create_all()
@@ -80,6 +83,7 @@ def update_database(db, existing_people, existing_notes):
8083
db.session.commit()
8184
print("Updated existing database")
8285

86+
8387
with app.app_context():
8488
existing_people = get_data_from_table(Person)
8589
existing_notes = get_data_from_table(Note)
@@ -88,6 +92,3 @@ def update_database(db, existing_people, existing_notes):
8892
create_database(db)
8993
else:
9094
update_database(db, existing_people, existing_notes)
91-
92-
93-

build-a-rest-api-frontend/source_code_step_5/init_database.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
},
4646
]
4747

48+
4849
def get_data_from_table(model):
4950
try:
5051
data = db.session.query(model).all()
@@ -53,6 +54,7 @@ def get_data_from_table(model):
5354
except OperationalError:
5455
return []
5556

57+
5658
def create_database(db):
5759
db.create_all()
5860
for data in PEOPLE_NOTES:
@@ -70,6 +72,7 @@ def create_database(db):
7072
db.session.commit()
7173
print("Created new database")
7274

75+
7376
def update_database(db, existing_people, existing_notes):
7477
db.drop_all()
7578
db.create_all()
@@ -80,6 +83,7 @@ def update_database(db, existing_people, existing_notes):
8083
db.session.commit()
8184
print("Updated existing database")
8285

86+
8387
with app.app_context():
8488
existing_people = get_data_from_table(Person)
8589
existing_notes = get_data_from_table(Note)
@@ -88,6 +92,3 @@ def update_database(db, existing_people, existing_notes):
8892
create_database(db)
8993
else:
9094
update_database(db, existing_people, existing_notes)
91-
92-
93-

0 commit comments

Comments
 (0)