Add alembic migrations
This commit is contained in:
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user