fastapi-sqlmodel-alembic icon indicating copy to clipboard operation
fastapi-sqlmodel-alembic copied to clipboard

This is really awful

Open vishIGOR opened this issue 2 years ago • 3 comments

I don't know how to repair this but I didn't find any way to do "alembic upgrade head" in docker-compose. But the fact that it's useless is really disgusting. Usually people use docker for simple work on servers and it's main idea to unite a big amount of commads instead of exexcuting it by hands. So, you didn't find how to fix it and just said "do a docker-compose exec web alembic upgrade head every time you need to up docker-compose". I hate myself that i didn't find how to fix it but more I hate for this subquality work

vishIGOR avatar Apr 08 '22 13:04 vishIGOR

I have no idea about what people thinking when they star this

vishIGOR avatar Apr 08 '22 13:04 vishIGOR

Chill dawg

Ramko9999 avatar Apr 09 '22 22:04 Ramko9999

Well, actually you can tell alembic to migrate your database schema before running your application, hope that is actually the solution you're looking for. Change your service definition inside docker-compose into this:

version: "3"
services:
  app:
    build: .
    command: bash -c "alembic upgrade head && uvicorn main:app"
    volumes:
      - "./:/app"
    ports:
      - "8000:8000"
    depends_on:
      - db

Here is for the Dockerfile (pretty standard):

FROM python:3.8

# Set environment varibles
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /app

COPY . /app

RUN pip install -r /app/requirements.txt

EXPOSE 8000

agusrichard avatar Apr 10 '22 15:04 agusrichard

@vishIGOR thanks for being so constructive :roll_eyes: If you see things you don't like on a small project like this, you should implement solutions for it yourself.

bazylhorsey avatar Oct 26 '22 18:10 bazylhorsey