Skip to content

feat: add MRT rule codes and # noqa suppression syntax (v1.2.0)#28

Merged
croc100 merged 9 commits into
mainfrom
feat/default-tests-and-schema-drift
Jun 7, 2026
Merged

feat: add MRT rule codes and # noqa suppression syntax (v1.2.0)#28
croc100 merged 9 commits into
mainfrom
feat/default-tests-and-schema-drift

Conversation

@croc100

@croc100 croc100 commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • Assign stable MRTxxx codes to all 35 rules (Alembic + Django)
  • Support # noqa: MRT201 suppression syntax — follows the ruff/flake8 convention Python developers already know
  • # mrt: ignore kept for backwards compatibility
  • Code column added to CLI table output and JSON output

Rule codes

Range Category
MRT1xx Reversibility (missing/broken downgrade)
MRT2xx Destructive operations (data loss)
MRT3xx Rename / type changes
MRT4xx Nullable / constraints / indexes
MRT5xx DDL types, sequences, triggers
MRT9xx Cross-file / structural

Suppression syntax

op.drop_column("users", "email")           # noqa: MRT201
op.drop_column("users", "email")           # noqa: MRT201, MRT202
op.drop_column("users", "email")           # noqa
op.drop_column("users", "email")           # mrt: ignore  (legacy)

Test plan

  • All 360 existing tests pass
  • _is_suppressed() smoke-tested for all 6 forms (bare noqa, specific code, multiple codes, mismatch, legacy, no comment)
  • Verified w.code populated correctly on real migration fixtures

croc100 added 8 commits June 7, 2026 19:54
- Auto-collect 5 built-in tests when MRTConfig is registered (no imports needed).
  Disable with mrt_default_tests = "false" in pytest.ini.
- Add MRTFixture.assert_schema_matches() — fails on SQLAlchemy model/migration drift.
  Django mode delegates to manage.py makemigrations --check.
- Add mrt drift CLI command for schema drift reporting.
- Add MRTConfig.target_metadata field for import-path based metadata resolution.
- Fix get_versions_dir() to return actual versions/ path, not script root.
Assign MRT1xx-MRT9xx codes to all 35 rules (Alembic + Django).
Support standard # noqa: MRT201 suppression on migration lines,
matching the ruff/flake8 convention Python developers already know.

- # noqa           — suppress all MRT warnings on that line
- # noqa: MRT201   — suppress a specific rule
- # noqa: MRT201, MRT202  — suppress multiple rules
- # mrt: ignore    — legacy alias, kept for backwards compatibility

Rule code table:
  MRT101 Missing downgrade        MRT201 DROP COLUMN in upgrade
  MRT102 No-op downgrade          MRT202 DROP TABLE in upgrade
  MRT103 Data transform           MRT203 TRUNCATE
  MRT104 Raw SQL w/o reverse      MRT204 CASCADE DELETE
  MRT105 context.execute          MRT205 DROP FK w/o restore
  MRT106 bulk_insert              MRT206 DROP COLUMN in batch
  MRT107 RunPython (Django)       MRT207 DROP VIEW w/o reverse
  MRT108 RunSQL (Django)          MRT208 Multi-step destructive
  MRT209 RemoveField (Django)     MRT210 DeleteModel (Django)
  MRT211 RunSQL DROP TABLE        MRT212 RunSQL TRUNCATE
  MRT301 rename_table             MRT302 rename_column
  MRT303 Column type change       MRT304 ENUM value added
  MRT305 RenameModel (Django)     MRT401 NOT NULL w/o default
  MRT402 NOT NULL nullable        MRT403 NOT NULL raw SQL
  MRT404 ADD COLUMN volatile def  MRT405 ADD COLUMN server_default
  MRT406 UNIQUE on existing data  MRT407 INDEX w/o CONCURRENTLY
  MRT408 DROP INDEX w/o reverse   MRT409 DROP CONSTRAINT w/o reverse
  MRT410 DROP CONSTRAINT batch    MRT411 AddField NOT NULL (Django)
  MRT412 AlterField NOT NULL      MRT413 AddIndex atomic (Django)
  MRT414 Missing atomic=False     MRT501 SEQUENCE modification
  MRT502 CREATE TRIGGER           MRT503 CREATE TYPE
  MRT901 Multiple heads           MRT902 Syntax error

Code column added to CLI table output and JSON output.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 61.11111% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pytest_mrt/core/detector.py 58.33% 4 Missing and 1 partial ⚠️
pytest_mrt/default_tests.py 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@croc100 croc100 merged commit ea26d7b into main Jun 7, 2026
12 checks passed
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