Skip to content
Snippets Groups Projects
  • Jakob Moser's avatar
    d4ec0448
    Add basic Flask app structure · d4ec0448
    Jakob Moser authored
    - Python code (app __init__.py, main.py, config model)
    - Alembic migrations
    - Docker config (Dockerfile, entrypoint, Docker Compose file)
    - Requirements (alembic, Flask, SQLAlchemy)
    - Ignore files (Git, docker)
    Verified
    d4ec0448
    History
    Add basic Flask app structure
    Jakob Moser authored
    - Python code (app __init__.py, main.py, config model)
    - Alembic migrations
    - Docker config (Dockerfile, entrypoint, Docker Compose file)
    - Requirements (alembic, Flask, SQLAlchemy)
    - Ignore files (Git, docker)
README.md 1.38 KiB

Alembic

This project uses Alembic for database migrations, i.e. creating, updating and deleting table schemas in the database.

The migrations are run automatically when starting the application (e.g. at the first start ever, a migration is run that “migrates” from an empty database to the way it should currently be; similarly, if you've pulled in an update of the code that requests e.g. a new table or a new column, the database is updated by creating the new table or column, respectively).

However, you need to create the migrations semi-automatically. This always becomes necessary when you code and change something about the model. After you are satisfied with the changes, you need to run:

alembic revision --autogenerate -m "<A description of the model changes>"

This will automatically generate a new Python file in versions/, which will include an upgrade and a downgrade method for the database. Ideally, you can use this file without further changes, however, please check it first (depending on the current layout of your database, it might very well be possible that Alembic generates more commands than needed).

After having modified the file, you commit everything (i.e. your model changes and the generated migrations).

Further reading