Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make database setup and teardown idempotent #103

Closed
angela-tran opened this issue Aug 3, 2022 · 0 comments · Fixed by #104
Closed

Make database setup and teardown idempotent #103

angela-tran opened this issue Aug 3, 2022 · 0 comments · Fixed by #104
Assignees

Comments

@angela-tran
Copy link
Member

Currently, an attempt to restart a server Docker container will result in an IntegrityError:

+ python setup.py
Creating table...
Table created.
Importing users from /.devcontainer/server/data.csv
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
sqlite3.IntegrityError: UNIQUE constraint failed: user.key

image

A separate but similar issue is that an attempt to teardown the database if it has already been torn down results in an OperationalError:

+ python teardown.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1819, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such table: user

We should make the setup and teardown scripts idempotent to prevent these errors.

Additional context

#101 made it so the app container initializes the database on startup.

@angela-tran angela-tran added this to the Courtesy Cards milestone Aug 3, 2022
@angela-tran angela-tran moved this to In Progress in Digital Services Aug 3, 2022
@angela-tran angela-tran self-assigned this Aug 3, 2022
Repository owner moved this from In Progress to Done in Digital Services Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant