|
| 1 | +# Plugin API — Stability Guarantee |
| 2 | + |
| 3 | +This page documents which parts of pytest-mrt are **stable public API** vs **internal implementation details**. |
| 4 | + |
| 5 | +Starting from v0.8, we follow [Semantic Versioning](https://semver.org/). Any breaking change to a stable API increments the major version. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Stable public API (guaranteed no breaking changes in 0.x) |
| 10 | + |
| 11 | +### `MRTConfig` |
| 12 | + |
| 13 | +```python |
| 14 | +from pytest_mrt import MRTConfig |
| 15 | +``` |
| 16 | + |
| 17 | +All constructor parameters are stable: |
| 18 | + |
| 19 | +| Parameter | Type | Stable since | |
| 20 | +|---|---|---| |
| 21 | +| `alembic_ini` | `str` | v0.4 | |
| 22 | +| `db_url` | `str` | v0.4 | |
| 23 | +| `seed_rows` | `int` | v0.5 | |
| 24 | +| `skip` | `dict[str, str]` | v0.5 | |
| 25 | +| `severity_overrides` | `dict[str, str]` | v0.7 | |
| 26 | +| `custom_seeds` | `dict[str, Callable]` | v0.6 | |
| 27 | +| `custom_checks` | `list[Callable]` | v0.7 | |
| 28 | +| `migration_timeout` | `int \| None` | v0.8 | |
| 29 | + |
| 30 | +### `MRTFixture` methods (via `mrt` fixture) |
| 31 | + |
| 32 | +```python |
| 33 | +def test_example(mrt): |
| 34 | + mrt.upgrade("001") |
| 35 | + mrt.downgrade() |
| 36 | + mrt.assert_all_reversible() |
| 37 | +``` |
| 38 | + |
| 39 | +| Method | Stable since | |
| 40 | +|---|---| |
| 41 | +| `upgrade(revision)` | v0.4 | |
| 42 | +| `downgrade(revision)` | v0.4 | |
| 43 | +| `seed(table, rows, pk_col)` | v0.5 | |
| 44 | +| `check_static(versions_dir)` | v0.7 | |
| 45 | +| `assert_no_static_errors(versions_dir)` | v0.7 | |
| 46 | +| `check_revision(revision)` | v0.5 | |
| 47 | +| `check_all()` | v0.5 | |
| 48 | +| `assert_reversible(revision)` | v0.5 | |
| 49 | +| `assert_all_reversible()` | v0.4 | |
| 50 | +| `assert_data_intact()` | v0.5 | |
| 51 | +| `reset()` | v0.5 | |
| 52 | + |
| 53 | +### `RevisionResult` attributes |
| 54 | + |
| 55 | +| Attribute | Type | Stable since | |
| 56 | +|---|---|---| |
| 57 | +| `revision` | `str` | v0.5 | |
| 58 | +| `passed` | `bool` | v0.5 | |
| 59 | +| `skipped` | `bool` | v0.5 | |
| 60 | +| `skip_reason` | `str` | v0.5 | |
| 61 | +| `failures` | `list[str]` | v0.5 | |
| 62 | +| `risk_score` | `int` | v0.6 | |
| 63 | +| `failure_summary()` | `str` | v0.5 | |
| 64 | + |
| 65 | +### `RiskWarning` attributes |
| 66 | + |
| 67 | +| Attribute | Type | Stable since | |
| 68 | +|---|---|---| |
| 69 | +| `revision` | `str` | v0.5 | |
| 70 | +| `file` | `str` | v0.5 | |
| 71 | +| `pattern` | `str` | v0.5 | |
| 72 | +| `message` | `str` | v0.5 | |
| 73 | +| `severity` | `str` | v0.5 | |
| 74 | +| `line` | `int \| None` | v0.6 | |
| 75 | + |
| 76 | +### `MigrationAST` (custom checks API) |
| 77 | + |
| 78 | +Functions registered via `MRTConfig(custom_checks=[fn])` receive a `MigrationAST`: |
| 79 | + |
| 80 | +```python |
| 81 | +from pytest_mrt.core.ast_analyzer import MigrationAST |
| 82 | +from pytest_mrt.core.detector import RiskWarning |
| 83 | + |
| 84 | +def my_check(m: MigrationAST) -> list[RiskWarning]: |
| 85 | + ... |
| 86 | +``` |
| 87 | + |
| 88 | +Stable attributes and methods: |
| 89 | + |
| 90 | +| Member | Type | Stable since | |
| 91 | +|---|---|---| |
| 92 | +| `m.revision` | `str` | v0.7 | |
| 93 | +| `m.filename` | `str` | v0.7 | |
| 94 | +| `m.source` | `str` | v0.7 | |
| 95 | +| `m._parse_error` | `Exception \| None` | v0.7 | |
| 96 | +| `m.upgrade_calls()` | `list[CallInfo]` | v0.7 | |
| 97 | +| `m.downgrade_calls()` | `list[CallInfo]` | v0.7 | |
| 98 | +| `m.upgrade_methods()` | `set[str]` | v0.7 | |
| 99 | +| `m.downgrade_methods()` | `set[str]` | v0.7 | |
| 100 | +| `m.str_arg(call, index)` | `str \| None` | v0.7 | |
| 101 | + |
| 102 | +`CallInfo` stable attributes: |
| 103 | + |
| 104 | +| Attribute | Type | |
| 105 | +|---|---| |
| 106 | +| `method` | `str` — the `op.*` method name | |
| 107 | +| `kw` | `dict[str, Any]` — keyword arguments | |
| 108 | +| `node` | `ast.Call` — AST node (has `.lineno`) | |
| 109 | + |
| 110 | +### `__version__` |
| 111 | + |
| 112 | +```python |
| 113 | +from pytest_mrt import __version__ |
| 114 | +``` |
| 115 | + |
| 116 | +Always a PEP 440 version string. Stable since v0.4. |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## CLI exit codes (stable since v0.8) |
| 121 | + |
| 122 | +``` |
| 123 | +mrt check <versions_dir> |
| 124 | +``` |
| 125 | + |
| 126 | +| Exit code | Meaning | |
| 127 | +|---|---| |
| 128 | +| `0` | No issues detected | |
| 129 | +| `1` | Warnings found (review before next release) | |
| 130 | +| `2` | Errors found — migrations have rollback risks | |
| 131 | +| `2` | Warnings found with `--strict` | |
| 132 | + |
| 133 | +These exit codes are stable and will not change. |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## Not stable (internal, may change) |
| 138 | + |
| 139 | +The following are implementation details. Do not import or depend on them: |
| 140 | + |
| 141 | +| Module / symbol | Reason | |
| 142 | +|---|---| |
| 143 | +| `pytest_mrt.core.runner.MigrationRunner` | Internal adapter for Alembic | |
| 144 | +| `pytest_mrt.core.seeder.SmartSeeder` | Internal test data layer | |
| 145 | +| `pytest_mrt.core.schema.*` | Internal schema diffing | |
| 146 | +| `pytest_mrt.core.verifier.RollbackVerifier` | Internal verification engine | |
| 147 | +| `pytest_mrt.core.detector._*` | All private check functions | |
| 148 | +| `pytest_mrt.adapters.django_detector.*` | Internal Django adapter | |
| 149 | +| `pytest_mrt.reporter.*` | Internal Rich console output | |
| 150 | + |
| 151 | +If you find yourself needing to import from these modules, [open an issue](https://github.com/croc100/pytest-mrt/issues/new/choose) — we may promote it to the stable API. |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## Version policy |
| 156 | + |
| 157 | +| Version bump | What it means | |
| 158 | +|---|---| |
| 159 | +| `0.x.y` patch | Bug fixes, no API changes | |
| 160 | +| `0.x+1.0` minor | New features, fully backwards-compatible | |
| 161 | +| `1.0.0` | Stable API declaration, SemVer from here | |
| 162 | +| `2.0.0` | Breaking API change (will have deprecation warnings first) | |
| 163 | + |
| 164 | +Deprecations are announced at least **one minor version** before removal. |
0 commit comments