Select Git revision
values_installer.py
Forked from
SOFT Core / SOFT 161 and 162 / Testability Examples
Source project has a limited visibility.
-
Brady James Garvin authoredBrady James Garvin authored
values_installer.py 873 B
from sys import stderr
from sqlalchemy.exc import SQLAlchemyError
from values import ValueDatabase, Value
def add_starter_data(session):
one = Value(value=1.0)
two = Value(value=2.0)
three = Value(value=3.0)
session.add(one)
session.add(two)
session.add(three)
def main():
try:
url = ValueDatabase.construct_mysql_url('localhost', 3306, 'values', 'root', 'cse1208')
value_database = ValueDatabase(url)
value_database.ensure_tables_exist()
print('Tables created.')
session = value_database.create_session()
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)
exit(1)
if __name__ == '__main__':
main()