File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FROM python:3.11-slim
2+
3+ WORKDIR /app/
4+
5+ RUN apt-get update -y \
6+ && apt-get install -y git curl \
7+ && rm -rf /var/lib/apt/lists/*
8+
9+ RUN pip install migration-lint
10+
11+ ENTRYPOINT ["migration-lint" ]
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ class AlembicExtractor(BaseExtractor):
1414
1515 def __init__ (self , ** kwargs ):
1616 super ().__init__ (** kwargs )
17- self .command = "make sqlmigrate"
17+ self .command = kwargs . get ( "alembic_command" ) or "make sqlmigrate"
1818
1919 def is_migration (self , path : str ) -> bool :
2020 """Check if the specified file is a migration."""
Original file line number Diff line number Diff line change 6363 help = "squawk config path" ,
6464 default = os .getenv ("MIGRATION_LINTER_SQUAWK_CONFIG_PATH" ),
6565)
66+ @click .option (
67+ "--alembic-command" ,
68+ "alembic_command" ,
69+ help = "command to get Alembic migrations sql" ,
70+ default = os .getenv ("MIGRATION_LINTER_ALEMBIC_COMMAND" ),
71+ )
6672def main (
6773 loader_type : str , extractor_type : str , squawk_config_path : str , ** kwargs
6874) -> None :
Original file line number Diff line number Diff line change 11[tool .poetry ]
22name = " migration-lint"
3- version = " 0.2.4 "
3+ version = " 0.2.5 "
44description = " Tool for lint operations in DB migrations SQL"
55authors = [" Alexey Nikitenko <alexey.nikitenko@pandadoc.com>" ]
66readme = " README.md"
Original file line number Diff line number Diff line change 11from unittest import mock
22
3+ import pytest
4+
35from migration_lint .extractor .alembic import AlembicExtractor
46from migration_lint .source_loader .model import SourceDiff
57
@@ -30,3 +32,24 @@ def test_alembic_extractor__ok():
3032 assert metadata .changed_files [0 ].allowed_with_backward_incompatible is True
3133 assert metadata .changed_files [1 ].allowed_with_backward_incompatible is True
3234 assert metadata .changed_files [2 ].allowed_with_backward_incompatible is False
35+
36+
37+ @pytest .mark .parametrize (
38+ "command,expected_command" ,
39+ [
40+ (None , "make sqlmigrate" ),
41+ ("alembic upgrade head --sql" , "alembic upgrade head --sql" ),
42+ ],
43+ )
44+ def test_alembic_extractor_command__ok (command , expected_command ):
45+ extractor = AlembicExtractor (alembic_command = command )
46+ changed_files = [
47+ SourceDiff (path = "src/db/migrations/versions/202202151945_fbea801d4464_auto.py" ),
48+ ]
49+
50+ with mock .patch (
51+ "migration_lint.extractor.alembic.subprocess.check_output"
52+ ) as subprocess_mock :
53+ subprocess_mock .return_value = "" .encode ("utf-8" )
54+ extractor .create_metadata (changed_files )
55+ subprocess_mock .assert_called_once_with (expected_command .split ())
You can’t perform that action at this time.
0 commit comments