Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
added some comments and moved to scripts/reset_db.py
  • Loading branch information
0dm committed Jun 1, 2023
1 parent f6fba8a commit b728c98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Empty file added openadapt/scripts/__init__.py
Empty file.
10 changes: 8 additions & 2 deletions openadapt/renew.py → openadapt/scripts/reset_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
from openadapt.config import getenv_fallback


def clear_db():
def reset_db():
"""
The function clears the database by removing the database file and running a
database migration using Alembic.
"""
db = getenv_fallback("DB_FNAME")
if os.path.exists(db):
os.remove(db)

# Prevents duplicate logging of config values by piping stderr and filtering the output.
result = run(["alembic", "upgrade", "head"], stderr=PIPE, text=True)
print(result.stderr[result.stderr.find("INFO [alembic") :])
if result.returncode != 0:
Expand All @@ -16,4 +22,4 @@ def clear_db():


if __name__ == "__main__":
clear_db()
reset_db()

0 comments on commit b728c98

Please sign in to comment.