migratecheck
Catch dangerous database migrations before they hit production
Install
pip install migratecheck
Usage
from migratecheck import analyze_sql
sql = open("alembic/versions/0042_add_column.py").read()
risks = analyze_sql(sql)
for risk in risks:
print(f"[{risk.level.value}] {risk.message}")
print(f" Line {risk.line_number}: {risk.statement}")
print(f" Fix: {risk.suggestion}")
What It Detects
| Risk | Level | Why |
|---|---|---|
ADD COLUMN NOT NULL without default |
Critical | Rewrites entire table, holds lock |
DROP TABLE |
Critical | Permanent data loss |
TRUNCATE |
Critical | Deletes all rows |
ALTER COLUMN TYPE |
Critical | Full table rewrite + exclusive lock |
LOCK TABLE |
Critical | Blocks all access |
DROP COLUMN |
Danger | Irreversible, may break app |
CREATE INDEX (not concurrent) |
Danger | Locks writes |
RENAME TABLE/COLUMN |
Danger | Breaks references |
ADD FOREIGN KEY |
Warning | Full table scan |
DROP INDEX |
Warning | May slow queries |
Use in CI
- name: Check migrations
run: python -c "
from migratecheck import analyze_sql
import sys, glob
for f in glob.glob('alembic/versions/*.py'):
risks = analyze_sql(open(f).read())
for r in risks:
if r.level.value in ('critical', 'danger'):
print(f'BLOCKED: {r.message}')
sys.exit(1)
"
License
MIT
Release files for migratecheck 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| migratecheck-0.2.0.tar.gz | 4.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| migratecheck-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / migratecheck-0.2.0.tar.gz
| Download URL | migratecheck-0.2.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ed508de26e1e9dc29346b96f9f54b139979dcd98530abe671cb83fb514a965e8
|
|
BLAKE2b-256 checksum How to use checksums |
77438404258011b8e99da6d99de3ec1f48287cf38454bdb127f3ff95f04d49ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / migratecheck-0.2.0-py3-none-any.whl
| Download URL | migratecheck-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
131b04f98fb4efa86fb53937d983cfc7a10b51ff6d8504337562c6ae1c36bf4d
|
|
BLAKE2b-256 checksum How to use checksums |
e45e5af5c71147cfb2a9aaed6921f677da13c44573a029f1f60c4cfaab0df714
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|