Skip to content

Commit

Permalink
feat(CodeMigrations): Adding migrations in command at dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
gabszs committed Oct 5, 2024
1 parent 690c46d commit 6266b6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ COPY migrations ./migrations
COPY entrypoint.sh ./

EXPOSE 80

# CMD ["alembic", "upgrade", "head"]
CMD ["sh", "-c", "alembic upgrade head && uvicorn --host 0.0.0.0 --port 80 app.main:app"]
# CMD ["uvicorn", "--host", "0.0.0.0", "--port", "80", "app.main:app"]
8 changes: 5 additions & 3 deletions app/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import declarative_base
from alembic.config import Config
from alembic import command

from app.core.settings import settings
from app.models import Base
Expand Down Expand Up @@ -77,9 +79,9 @@ async def create_all_from_base(self, connection: AsyncConnection, base_model: de
async def drop_all_from_base(self, connection: AsyncConnection, base_model: declarative_base):
await connection.run_sync(base_model.metadata.drop_all)

# def run_migrations(self):
# alembic_cfg = Config("alembic.ini")
# command.upgrade(alembic_cfg, "head")
def run_migrations(self):
alembic_cfg = Config("alembic.ini")
command.upgrade(alembic_cfg, "head")


sessionmanager = DatabaseSessionManager()
Expand Down

0 comments on commit 6266b6a

Please sign in to comment.