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}")
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.1.0.tar.gz
(4.2 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.1.0.tar.gz.
File metadata
- Download URL: migratecheck-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3be1a4dd6e14f9b61d2c5073d94ed0ba8b0ddee0d373f4df3bb0ee0c47a99c3b
|
|
| MD5 |
b40bd70b2bca9a0d96b29f38c2f88826
|
|
| BLAKE2b-256 |
c19651852fb48fa160f4bfbc87cf61b8543d52f8b70c1989c01d511cbc5e3d96
|
File details
Details for the file migratecheck-0.1.0-py3-none-any.whl.
File metadata
- Download URL: migratecheck-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 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 |
6f527f780db5f649f0b8909c1551683ba9cd13f56ca267e3d76d1963afbcad36
|
|
| MD5 |
18cbb043f25c94e728e49c9c7dccbbeb
|
|
| BLAKE2b-256 |
0b850fc19a15c0c65b42235b5c280bdd458f2b2ea818ef3763ec2bd886cf64c4
|