fastapi / full-stack-fastapi-template

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.
MIT License
26.28k stars 4.6k forks source link

[?] Migrations #237

Closed ghost closed 4 years ago

ghost commented 4 years ago

I ran the cookiecutter and pushed this project to a GitLab repository. I set up a VPS with Docker Swarm and GitLab Runner (based on the instruction from dockerswarm.rocks). I ran the pipeline and the test, build and deploy-stag completed successfully. I can access everything on stag.domain.com without issues. Then..

1) I made some change to the user model (split full name to first and last name) in the gitlab repository master branch and committed the changes. But the CI/CD job failed, because the backend container failed, because the column did not exist in the table, because there was no migration done. How do I make migrations and migrate automatically when I make changes to the GitLab repository with this set up? Why is it necessary to manually enter the container and make migrations using alembic?

2) Any time there is a new commit, I want it to make the migrations (if applicable) and migrate automatically, otherwise the backend container will fail every time. It seems unnecessary to manually connect to the backend container and make the migrations each time. How do I accomplish this?

3) How it should work:

  1. Upload repository to GitLab
  2. Run CI/CD pipeline
  3. Make changes to files in repository
  4. Commit changes
  5. Repeat steps 2-4 again and again in the same way, forever

Why are there so many extra steps?

I've been pulling my hair out for a couple days on this. Thanks in advance!

ghost commented 4 years ago

Solution can be found here: https://github.com/sqlalchemy/alembic/issues/80

tiangolo commented 3 years ago

Thanks for reporting back and closing the issue :+1: