Add alembic migrations

This commit is contained in:
Jacob Windsor
2025-02-19 15:55:16 +01:00
parent ac3727065f
commit 0d1e53acdb
10 changed files with 300 additions and 3 deletions
+12
View File
@@ -11,6 +11,8 @@ from sqlalchemy.ext.asyncio import (
)
from sqlmodel import create_engine, SQLModel
from sqlalchemy.orm import Session
import os
import subprocess
from ..models.user import User
@@ -80,3 +82,13 @@ def create_db_and_tables():
engine = _get_engine()
SQLModel.metadata.create_all(engine)
_seed_db()
def startup_migrations():
print("Running Alembic migrations...")
backend_path = os.path.dirname(os.path.abspath(__file__)) + "/../.."
try:
subprocess.run(["alembic", "upgrade", "head"], check=True, cwd=backend_path)
print("Migrations applied successfully!")
except subprocess.CalledProcessError as e:
print(f"Error applying migrations: {e}")