An example for project using flask and postgres stack.
Prerequisites:
- Docker
- Docker Compose
Build images,
$ docker compose buildRun containers
$ docker compose upVisit http://127.0.0.1:5000 for development.
Here are some aspects that require attention, including potential tricks or pitfalls.
- Include
initdb.sqlto create the database. - Set
PGUSER=postgresto use userpostgres, instead ofroot. - Set
FLASK_APPto let Flask-Migrate to find the app. - Import models in
__init__.pyfile so that Flask-Migrate could detect them.
Get into the container
$ docker compose exec web bashUse the following commands to migrate your database
Init database (Already inited, you could skip this step)
$ flask db initMigrate to create versions,
$ flask db migrateThen upgrade new versions,
$ flask db upgradeHappy Coding!