Commit 4daf672f authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Added a guard to prevent duplicate starter data.

parent aedd03f0
......@@ -2,7 +2,11 @@ from sys import stderr
from sqlalchemy.exc import SQLAlchemyError
from diner import DinerDatabase, Menu, Item, Order, OrderItem
from diner import DinerDatabase, Persisted, Menu, Item, Order, OrderItem
def already_has_data(session):
return any(session.query(table).first() is not None for table in Persisted.metadata.sorted_tables)
def add_starter_data(session):
......@@ -27,9 +31,12 @@ def main():
diner_database.ensure_tables_exist()
print('Tables created.')
# session = diner_database.create_session()
# add_starter_data(session)
# session.commit()
# print('Records created.')
# if already_has_data(session):
# print('Not creating records because some already exist.')
# else:
# add_starter_data(session)
# session.commit()
# print('Records created.')
except SQLAlchemyError as exception:
print('Database setup failed!', file=stderr)
print(f'Cause: {exception}', file=stderr)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment