Catch dangerous database migrations before they hit production
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
migratecheck-0.2.0.tar.gz
(4.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file migratecheck-0.2.0.tar.gz.
File metadata
- Download URL: migratecheck-0.2.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed508de26e1e9dc29346b96f9f54b139979dcd98530abe671cb83fb514a965e8
|
|
| MD5 |
6a053dace9a05b87307f38afc507b90d
|
|
| BLAKE2b-256 |
77438404258011b8e99da6d99de3ec1f48287cf38454bdb127f3ff95f04d49ab
|
File details
Details for the file migratecheck-0.2.0-py3-none-any.whl.
File metadata
- Download URL: migratecheck-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
131b04f98fb4efa86fb53937d983cfc7a10b51ff6d8504337562c6ae1c36bf4d
|
|
| MD5 |
85d4179afb299979beb1b2c4b86f1171
|
|
| BLAKE2b-256 |
e45e5af5c71147cfb2a9aaed6921f677da13c44573a029f1f60c4cfaab0df714
|