Skip to content

...create migrations

MariusDanner edited this page Feb 18, 2020 · 5 revisions

When the models have been changed, make sure your database is up to date by using:

garden deploy

If you want alembic to automatically create a migration for you, you need to do the following steps: Make sure that you the required packages installed locally.

  1. Run kubectl port-forward -n ENV YOUR_POSTGRES_POD 5432:5432
  2. Set the POSTGRES_USER and POSTGRES_PASSWORD env variables to right values(using export etc)
  3. cd services/python-images
  4. export FLASK_APP=migration.py
  5. flask db migrate

If alembic does not detect your changes correctly, you can manually create an empty migration by using:

flask db revision -m "migration message"

You can then either manipulate the autogenerated commands or insert new commands in the new migration file.

When you are done, run garden deploy to apply the changes to your local cluster.

Alembic is used for the migration system. Alembic does not auto-detect the following changes correctly:

  • Table and column renames (are detected as deleted and added with another name)
  • Column type changes (are not detected at all, remember to add conversion function when adding them manually)

This list might not be complete, be sure to check the Alembic documentation for further information.

If you are having problems with merging your migrations, run flask db heads and flask db merge HEAD1 HEAD2 HEAD3.... You can find more details here