redash/tests/test_migrations.py
Arik Fraimovich e71ccf5de5
Fix: add a merge migration to solve multi head issue (#5364)
* Add unit test to test for multi-head migrations issue

* Add merge migration
2021-01-21 10:55:52 -08:00

20 lines
774 B
Python

import os
from alembic.config import Config
from alembic.script import ScriptDirectory
def test_only_single_head_revision_in_migrations():
"""
If multiple developers are working on migrations and one of them is merged before the
other you might end up with multiple heads (multiple revisions with the same down_revision).
This makes sure that there is only a single head revision in the migrations directory.
Adopted from https://blog.jerrycodes.com/multiple-heads-in-alembic-migrations/.
"""
config = Config(os.path.join("migrations", 'alembic.ini'))
config.set_main_option('script_location', "migrations")
script = ScriptDirectory.from_config(config)
# This will raise if there are multiple heads
script.get_current_head()