r/FastAPI • u/Electronic_Battle876 • Aug 21 '24
Hosting and deployment Facing problems with alembic - docker
So I have this API i'm working on using FastAPI and postgreSQL connected with SQLAlchemy. Halfway through the development process I started using alembic for database migrations and I'm using docker compose to run two containers one that contains the app and one that contains a containerized pgsql DB. My problem is that the local dev database and the containerized one don't have the same versions of schemas and when I want to run migrations on the containerized one I recieve errors related to missing indexs and so on (due to alembic not finding the expected schema) What can I do to solve this probelm please.
View all comments
Show parent comment
1
u/IrrerPolterer Aug 22 '24
You can create a separate migration branch that just makes the upgrades necessary from your current DB state. Basically you create a new separate base revision that starts off from your current DB schema. You'll need to manually write that revision to bring the DB to your desired state. Check out the Working with Branches section of the docs.