From 0f592df66f9a9f5bb61b70a130035ec01f280389 Mon Sep 17 00:00:00 2001 From: Ashhhleyyy Date: Sun, 18 Feb 2024 12:26:07 +0000 Subject: [PATCH] feat(backend): run migrations on startup --- backend/aci/migrate.py | 12 ++++++++++++ backend/app.py | 2 ++ backend/migrate.py | 11 ----------- 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 backend/aci/migrate.py delete mode 100644 backend/migrate.py diff --git a/backend/aci/migrate.py b/backend/aci/migrate.py new file mode 100644 index 0000000..8187b31 --- /dev/null +++ b/backend/aci/migrate.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +import sqlite3 + +def run_migrations(): + conn = sqlite3.connect('./checkin.db') + db = conn.cursor() + + try: + db.execute("CREATE TABLE IF NOT EXISTS code_results (date text, time text, space text, activity text, code text, result boolean)") + finally: + db.close() + conn.close() diff --git a/backend/app.py b/backend/app.py index 599ea54..050a1ef 100644 --- a/backend/app.py +++ b/backend/app.py @@ -10,6 +10,7 @@ from fastapi.middleware.cors import CORSMiddleware import uvicorn from aci.db import get_db +from aci.migrate import run_migrations from aci.models import CodeSubmission from aci import utils @@ -59,4 +60,5 @@ def current_codes(db: sqlite3.Cursor=Depends(get_db)): } if __name__ == '__main__': + run_migrations() uvicorn.run(app) diff --git a/backend/migrate.py b/backend/migrate.py deleted file mode 100644 index bb9da73..0000000 --- a/backend/migrate.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python3 -import sqlite3 - -conn = sqlite3.connect('./checkin.db') -db = conn.cursor() - -try: - db.execute("CREATE TABLE IF NOT EXISTS code_results (date text, time text, space text, activity text, code text, result boolean)") -finally: - db.close() - conn.close()