Skip to content

Commit

Permalink
🆙 update(create_db): Add error handling. Print messages
Browse files Browse the repository at this point in the history
Fix #34
  • Loading branch information
anselal committed Dec 8, 2017
1 parent 51f7490 commit 9786249
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions create_db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from app.models import MinerModel, Settings
from app import db
from sqlalchemy.exc import IntegrityError

db.create_all()
models = []
Expand All @@ -11,10 +12,16 @@
settings.append(Settings(name="temperature_alert", value="80", description=""))
settings.append(Settings(name="email_alert", value="True", description="Whether to send an email on alert"))

for model in models:
db.session.add(model)
db.session.commit()
try:
for model in models:
db.session.add(model)
db.session.commit()

for setting in settings:
db.session.add(setting)
db.session.commit()
except IntegrityError:
print("Database already exists.")
else:
print("Database successfully created.")

for setting in settings:
db.session.add(setting)
db.session.commit()

0 comments on commit 9786249

Please sign in to comment.