-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'clear-data' into add-GUI
- Loading branch information
Showing
4 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ cache | |
performance | ||
|
||
# Generated when adding editable dependencies in requirements.txt (-e) | ||
src | ||
src | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
from subprocess import run, PIPE | ||
from openadapt.config import getenv_fallback | ||
|
||
|
||
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: | ||
raise RuntimeError("Database migration failed.") | ||
else: | ||
print("Database cleared successfully.") | ||
|
||
|
||
if __name__ == "__main__": | ||
reset_db() |