Skip to content

DB Migration alembic

Falaris01 edited this page Jan 5, 2018 · 6 revisions

Creating fresh DB

Please create your DB with utf8mb4 charset ! If not, you can have some unicode errors when a name contains accents or smileys :
CREATE DATABASE monkey CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Alembic

DB migration is handled with alembic python3 scripts/create_db.py is deprecated in Monocle/Monkey

Usage

To perform DB schema migration to latest version, run

alembic upgrade head

For some reason, if you need to run raw SQL for migration, run the dry-run. It will display all the DB migration SQL.

alembic upgrade head --sql

FAQ

I am having command not found error for alembic

Make sure alembic is installed via pip3[.6] install -r requirements.txt -U.

Alembic executables is located in the same folder as python3, pip3[.6], etc commands. So if you usually run python with virtual environment, you would need to find alembic in the same directory.

E.g. If your pip3[.6] is in /opt/python/bin/pip3[.6], your alembic would also be in /opt/python/bin/alembic. Tou can then run alembic like the following

/opt/python/bin/alembic updgrade head --sql