This is a template created to develop fastapi applications that connect to a postgres database. The intention of local development is a devcontainer, using vscode; But you it should work with any editor/environment. In order to allow other IDEs to use it without vscode, the configuration happens in a specific docker-compose.yml file, and the image built is in the Dockerfile at root level.
NOTE: Some modification may be necessary to work with different setups
In this project you will see 3 containers running:
Create a new project using this as a template. Then, change the project name in pyproject.toml file. Rebuild the container, and everything should work fine.
NOTE: If something goes wrong when running this initial setup, try to update poetry packages and rebuild the container.
If you already are familiar with the structure, feel free to skip this section
Let's separate the content of this project in two: code and infrastructure.
Everything related to code is what you would expect in any python project:
Then you have infrastructure. Those files are needed to make everything work in codespaces, vscode, etc:
Alembic is installed, and it runs the initial migration, already prepared. In a new project, you should delete the existing migration, and create a new one based on your configuration.
In alembic's env.py the target metadata was set based on user model. Change this, according to your needs. Alembic.ini was also modified, but you don't need to change it.
NOTE: alembic configuration is based in the user model. If you remove this moodel, you have to change it in env.py as well
before migration, you need to create a new revision:
alembic revision -m "migration description" --autogenerated
This will create a new revision, based on your changes in the models.
To apply update the database to the latest migrations, use the following command:
alembic upgrade head
For more information about alembic, check the official documentation