forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: add a merge migration to solve multi head issue (getredash#5364)
* Add unit test to test for multi-head migrations issue * Add merge migration
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""fix_multiple_heads | ||
Revision ID: 89bc7873a3e0 | ||
Revises: 0ec979123ba4, d7d747033183 | ||
Create Date: 2021-01-21 18:11:04.312259 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '89bc7873a3e0' | ||
down_revision = ('0ec979123ba4', 'd7d747033183') | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
pass | ||
|
||
|
||
def downgrade(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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() |