Skip to content

Commit

Permalink
added openadapt.renew
Browse files Browse the repository at this point in the history
  • Loading branch information
0dm committed May 30, 2023
1 parent 2bbe036 commit f6fba8a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ cache
performance

# Generated when adding editable dependencies in requirements.txt (-e)
src
src
.DS_Store
3 changes: 2 additions & 1 deletion openadapt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"DB_ECHO": False,
"DB_FNAME": "openadapt.db",
"OPENAI_API_KEY": "<set your api key in .env>",
#"OPENAI_MODEL_NAME": "gpt-4",
# "OPENAI_MODEL_NAME": "gpt-4",
"OPENAI_MODEL_NAME": "gpt-3.5-turbo",
# may incur significant performance penalty
"RECORD_READ_ACTIVE_ELEMENT_STATE": False,
Expand All @@ -36,6 +36,7 @@ def getenv_fallback(var_name):
locals()[key] = val

ROOT_DIRPATH = pathlib.Path(__file__).parent.parent.resolve()
DB_FNAME = getenv_fallback("DB_FNAME")
DB_FPATH = ROOT_DIRPATH / DB_FNAME
DB_URL = f"sqlite:///{DB_FPATH}"

Expand Down
19 changes: 19 additions & 0 deletions openadapt/renew.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
from subprocess import run, PIPE
from openadapt.config import getenv_fallback


def clear_db():
db = getenv_fallback("DB_FNAME")
if os.path.exists(db):
os.remove(db)
result = run(["alembic", "upgrade", "head"], stderr=PIPE, text=True)
print(result.stderr[result.stderr.find("INFO [alembic") :])
if result.returncode != 0:
raise RuntimeError("Database migration failed.")
else:
print("Database cleared successfully.")


if __name__ == "__main__":
clear_db()

0 comments on commit f6fba8a

Please sign in to comment.