feat(backend): run migrations on startup
Some checks failed
Publish docker image / Publish (push) Failing after 1m6s
Some checks failed
Publish docker image / Publish (push) Failing after 1m6s
This commit is contained in:
parent
9f63a2c7d3
commit
0f592df66f
3 changed files with 14 additions and 11 deletions
12
backend/aci/migrate.py
Normal file
12
backend/aci/migrate.py
Normal file
|
@ -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()
|
|
@ -10,6 +10,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
from aci.db import get_db
|
from aci.db import get_db
|
||||||
|
from aci.migrate import run_migrations
|
||||||
from aci.models import CodeSubmission
|
from aci.models import CodeSubmission
|
||||||
from aci import utils
|
from aci import utils
|
||||||
|
|
||||||
|
@ -59,4 +60,5 @@ def current_codes(db: sqlite3.Cursor=Depends(get_db)):
|
||||||
}
|
}
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
run_migrations()
|
||||||
uvicorn.run(app)
|
uvicorn.run(app)
|
||||||
|
|
|
@ -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()
|
|
Loading…
Reference in a new issue