Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Best Practices for Source Controlled Migrations #1552

Answered by YuriiMotov
rissem asked this question in Questions
Discussion options

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

You must be logged in to vote

You are right, docs are incorrect now.
There is a PR #1431 that attempts to make it working

Replies: 3 comments 1 reply

Comment options

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.

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
1 reply
Comment options

You are right, docs are incorrect now.
There is a PR #1431 that attempts to make it working

Answer selected by YuriiMotov
Comment options

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?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested

AltStyle によって変換されたページ (->オリジナル) /