Skip to content

MPT-17670: add --check option to validate duplicate migration_id in migrat…#31

Merged
svazquezco merged 1 commit intomainfrom
MPT-17670-implement-check-option
Feb 5, 2026
Merged

MPT-17670: add --check option to validate duplicate migration_id in migrat…#31
svazquezco merged 1 commit intomainfrom
MPT-17670-implement-check-option

Conversation

@svazquezco
Copy link
Collaborator

@svazquezco svazquezco commented Feb 4, 2026

…ions

Closes MPT-17670

  • Add --check option to the migrate CLI to validate duplicate migration_id values
  • Implement CheckMigrationsUseCase to detect duplicate migration IDs and raise CheckMigrationError with affected filenames
  • Add CheckCommand CLI command and wire it into the command factory routing
  • Introduce CheckMigrationError (and clean up related use-case errors)
  • Document the new migration validation feature and CI/CD recommended usage in docs/PROJECT_DESCRIPTION.md and README
  • Add tests covering successful checks, duplicate detection, and empty migration folders

@svazquezco svazquezco requested a review from a team as a code owner February 4, 2026 18:04
@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

Adds a migrations validation flow: a CLI --check flag, a CheckCommand, a CheckMigrationsUseCase that detects duplicate migration_ids, new error classes, documentation for the check, and tests covering no-duplicates, duplicates, and empty-folder scenarios.

Changes

Cohort / File(s) Summary
CLI Command Interface
mpt_tool/cli.py
Added a --check boolean option to the migrate command signature.
Command Layer
mpt_tool/commands/check.py, mpt_tool/commands/factory.py
Added CheckCommand implementing lifecycle messages and execution; updated factory to return CheckCommand() when {"check": True}.
Use Case & Errors
mpt_tool/use_cases/check_migrations.py, mpt_tool/use_cases/errors.py, mpt_tool/use_cases/__init__.py
Introduced CheckMigrationsUseCase to find duplicate migration_ids; added CheckMigrationError (and consolidated ApplyMigrationError); exported the use case in __init__.
Tests
tests/cli/test_cli.py, tests/use_cases/test_check_migrations.py
Added CLI and unit tests for migrate --check: success/no-duplicates, duplicate-id failure, and empty-folder success.
Documentation & README
docs/PROJECT_DESCRIPTION.md, README.md
Added "Checking Migrations" documentation and expanded migration best practices; minor whitespace cleanup in README.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Jira Issue Key In Title ✅ Passed The PR title contains exactly one Jira issue key MPT-17670 in the required MPT-XXXX format at the beginning.
Test Coverage Required ✅ Passed PR modifies 6 code files and includes comprehensive test coverage with 2 test files modified/added (3 tests for --check option, 4 tests for CheckMigrationsUseCase).
Single Commit Required ✅ Passed The pull request contains exactly one commit with all changes properly squashed into a single clean commit.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • MPT-17670: Cannot read properties of undefined (reading 'map')

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@mpt_tool/commands/check.py`:
- Line 8: The module/function docstring in check.py currently says "Checks
migrations for duplicate order_id" but the command actually validates duplicate
migration_id; update the docstring text to say "Checks migrations for duplicate
migration_id" (or similar phrasing) so it matches the implemented behavior and
any references to the check command.
🧹 Nitpick comments (6)
docs/PROJECT_DESCRIPTION.md (1)

151-156: Add a language specifier to the fenced code block.

The example output code block should have a language specifier (e.g., text or console) for consistency and proper rendering.

📝 Suggested fix
 **Example output when duplicates are found:**
-```
+```text
 Checking migrations...
 Error running check command: Duplicate migration_id found in migrations: 20260113180013_duplicate_name.py, 20260114190014_duplicate_name.py
</details>

</blockquote></details>
<details>
<summary>mpt_tool/use_cases/check_migrations.py (2)</summary><blockquote>

`14-14`: **Remove unused `noqa` directive.**

The `# noqa: WPS210` directive is flagged by Ruff as unknown/unused. WPS codes are from wemake-python-styleguide, which is not in use here.


<details>
<summary>🧹 Suggested fix</summary>

```diff
-    def execute(self) -> None:  # noqa: WPS210
+    def execute(self) -> None:

29-29: Consider using a generator expression instead of a list comprehension.

A generator expression is slightly more efficient when passing to Counter since it avoids creating an intermediate list.

♻️ Suggested fix
-        migration_id_counter = Counter([migration.migration_id for migration in migration_files])
+        migration_id_counter = Counter(migration.migration_id for migration in migration_files)
mpt_tool/commands/factory.py (1)

32-32: Remove unused noqa directive.

The # noqa: WPS242 directive is flagged by Ruff as unknown/unused. WPS codes are from wemake-python-styleguide, which is not in use here.

🧹 Suggested fix
-        match param_data:  # noqa: WPS242
+        match param_data:
tests/cli/test_cli.py (1)

127-132: Use @pytest.mark.usefixtures for side-effect-only fixtures.

The migration_folder argument is used only for its side effect (creating the folder) but not referenced in the test body. Using the decorator makes the intent clearer and silences the Ruff ARG001 warning.

♻️ Suggested fix
+@pytest.mark.usefixtures("migration_folder")
-def test_migrate_check_empty_folder(runner, migration_folder):
+def test_migrate_check_empty_folder(runner):
     result = runner.invoke(app, ["migrate", "--check"])

     assert result.exit_code == 0, result.output
     assert "Checking migrations..." in result.output
     assert "Migrations check passed successfully." in result.output
tests/use_cases/test_check_migrations.py (1)

50-64: Consider verifying all duplicate IDs are reported in the error message.

The test creates two duplicate pairs (duplicate_one and duplicate_two) but only asserts the generic error message. Strengthening assertions would ensure both duplicate sets are captured.

🧪 Suggested fix
     with pytest.raises(CheckMigrationError) as exc_info:
         use_case.execute()

     assert "Duplicate migration_id found in migrations" in str(exc_info.value)
+    assert "duplicate_one" in str(exc_info.value)
+    assert "duplicate_two" in str(exc_info.value)

@svazquezco svazquezco force-pushed the MPT-17670-implement-check-option branch from 7ac1860 to f9b9233 Compare February 5, 2026 09:28
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 5, 2026

@svazquezco svazquezco merged commit 7453ebb into main Feb 5, 2026
4 checks passed
@svazquezco svazquezco deleted the MPT-17670-implement-check-option branch February 5, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants