Skip to content

Commit 6eff55e

Browse files
author
Alexey Nikitenko
committed
Added alembic command, added Dockerfile
1 parent 1e5037a commit 6eff55e

5 files changed

Lines changed: 42 additions & 2 deletions

File tree

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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"]

migration_lint/extractor/alembic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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."""

migration_lint/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
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+
)
6672
def main(
6773
loader_type: str, extractor_type: str, squawk_config_path: str, **kwargs
6874
) -> None:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "migration-lint"
3-
version = "0.2.4"
3+
version = "0.2.5"
44
description = "Tool for lint operations in DB migrations SQL"
55
authors = ["Alexey Nikitenko <alexey.nikitenko@pandadoc.com>"]
66
readme = "README.md"

tests/test_alembic_extractor.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from unittest import mock
22

3+
import pytest
4+
35
from migration_lint.extractor.alembic import AlembicExtractor
46
from 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())

0 commit comments

Comments
 (0)