-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Best Practices for Source Controlled Migrations #1552
-
First Check
- I added a very descriptive title here.
- I used the GitHub search to find a similar question and didn't find it.
- I searched in the documentation/README.
- I already searched in Google "How to do X" and didn't find any information.
- I already read and followed all the tutorial in the docs/README and didn't find an answer.
Commit to Help
- I commit to help with one of those options 👆
Example Code
root@b16001d44233:/app# alembic revision --autogenerate -m 'Generate alternate description'
Description
It is unclear how migrations are meant to be created and source-controlled in this project. The docs seem to suggest that the migration can be created in the container and that the migration file can be committed because of a volume mount
As during local development your app directory is mounted as a volume inside the container, you can also run the migrations with alembic commands inside the container and the migration code will be in your app directory (instead of being only inside the container). So you can add it to your git repository.
But looking at https://github.com/fastapi/full-stack-fastapi-template/blob/master/docker-compose.override.yml we see that it's a one way sync, not a volume mount. A hack around this could be a script to copy the alembic migrations from the container back to the host machine, and I'd be happy to write that script and make a PR if that direction makes sense.
Operating System
macOS
Operating System Details
Pretty standard Mac/Docker setup
Python Version
Python 3.10.17
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions
-
😄 1
You are right, docs are incorrect now.
There is a PR #1431 that attempts to make it working
Replies: 3 comments 1 reply
-
I just run it manually. Versioning is too much of a pain on this.
I make sure to run all the commands from generate-client.sh one by one and that tells me if everything is setup correctly and then loads the Api into the frontend locally. If all goes well and it works i just migrate manually.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
I have the same problem, it seems the documentation was not updated since watch sync is indeed a one way sync from host to container acdording to docker compose official docs.
Beta Was this translation helpful? Give feedback.
All reactions
-
😄 1
-
You are right, docs are incorrect now.
There is a PR #1431 that attempts to make it working
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm having the same issue when I run this in the docker container alembic revision --autogenerate -m "Add column last_name to User model"
this doesn't copy the migration files into the folder, it only remains inside the container. Is there a way around this?
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 1