Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LLSC-53] Replace alembic migrate on startup with SQLAchemy create table #15

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backend/app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from alembic import command
from alembic.config import Config
import os

from sqlalchemy import create_engine

# Make sure all models are here to reflect all current models
# when autogenerating new migration
Expand All @@ -11,7 +12,6 @@
__all__ = ["Base", "User", "Role"]


def run_migrations():
alembic_cfg = Config("alembic.ini")
# Emulates `alembic upgrade head` to migrate up to latest revision
command.upgrade(alembic_cfg, "head")
def create_tables():
engine = create_engine(os.getenv("POSTGRES_DATABASE_URL"))
Base.metadata.create_all(bind=engine)
4 changes: 2 additions & 2 deletions backend/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from dotenv import load_dotenv
from fastapi import FastAPI

from app.models import create_tables
from app.routes import email

load_dotenv()

# we need to load env variables before initialization code runs
from . import models # noqa: E402
from .routes import user # noqa: E402
from .utilities.firebase_init import initialize_firebase # noqa: E402

Expand All @@ -20,7 +20,7 @@
@asynccontextmanager
async def lifespan(_: FastAPI):
log.info("Starting up...")
models.run_migrations()
create_tables()
initialize_firebase()
yield
log.info("Shutting down...")
Expand Down
Loading