0

I have problem with running automated migrations with alembic library (I use raw alembic library).

So this is setup of the application:

  • I have scheduler (python script which calculates something and then stores it in database)

  • and flask REST API (which uses data stored in database by scheduler to return adequate response)

  • I then deploy the app with script which runs these three commands:

alembic revision --autogenereate
alembic upgrade head
python run_scheduler.py

After initial deployment, alembic_version table is created in PostgreSQL database with identifier value under version_num column, and migration script (lets call this script xx.py) is created in alembic/versions/

When I redeploy the app (with running migrations and scheduler): I get the

" Can't locate revision identified by 'xxxxxxx'

Why?

Because there is no xx.py script anymore (docker is built from source control repo) and xx is the value under version_num column in alembic_version table.

How to approach to and solve this problem?

Community
  • 1
  • 1
maro
  • 67
  • 6

1 Answers1

0

Quick fix of author: delete alembic_version table with code below (inside alembic/env.py script)

target_metadata = Base.metadata # for context

sql.execute('DROP TABLE IF EXISTS alembic_version', engine)
maro
  • 67
  • 6