Add migration support with Alembic; implement migration scripts and configuration
This commit is contained in:
@@ -4,6 +4,7 @@ import sys
|
||||
import os
|
||||
import auth.api_security as auth
|
||||
import time
|
||||
import threading
|
||||
|
||||
try:
|
||||
os.remove("api.log")
|
||||
@@ -28,6 +29,23 @@ except Exception as e:
|
||||
env = os.environ.copy()
|
||||
env["PYTHONIOENCODING"] = "utf-8"
|
||||
|
||||
#migration
|
||||
def run_migration():
|
||||
global migration_done
|
||||
process = subprocess.Popen(
|
||||
["python", "migration/alembic_scipt.py"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
process.wait()
|
||||
migration_done = (process.returncode == 0)
|
||||
with open("migration_status.flag", "w") as f:
|
||||
f.write("done" if migration_done else "failed")
|
||||
|
||||
thread = threading.Thread(target=run_migration)
|
||||
thread.start()
|
||||
|
||||
#cli and api
|
||||
log_file = open("api_server.log", "w", encoding="utf-8")
|
||||
api_process = subprocess.Popen(
|
||||
["fastapi", "dev", "api_server.py"],
|
||||
@@ -40,6 +58,9 @@ cli_process = subprocess.Popen([sys.executable, "cli.py"])
|
||||
api_process.wait()
|
||||
cli_process.wait()
|
||||
|
||||
time.sleep(60)
|
||||
os.remove("migration_status.flag")
|
||||
|
||||
# automatic durataion validation check
|
||||
while True:
|
||||
time.sleep(300)
|
||||
|
||||
Reference in New Issue
Block a user