Postgres migration safety analyzer — catch dangerous operations before they run
Project description
LockSafe AI
LockSafe AI is a CLI tool that analyzes PostgreSQL migration files and detects operations that can cause production downtime or data loss.
It helps you catch unsafe migrations before they are applied.
Installation
pip install locksafe
Requires Python 3.12+
Usage
Analyze a migration file:
locksafe analyze migration.sql
Example
Input
CREATE INDEX idx_users_email ON users(email);
ALTER TABLE users ADD COLUMN status TEXT NOT NULL;
TRUNCATE payments;
Output
🔐 LockSafe Analysis
File: migration.sql
Statements: 3 │ Critical: 2 │ High: 0 │ Medium: 0 │ Low: 0
⚠ Migration risks detected
🔴 [CRITICAL] Statement 1
↳ CREATE INDEX without CONCURRENTLY on table 'users'
🔴 [CRITICAL] Statement 2
↳ ADD COLUMN NOT NULL without DEFAULT causes table rewrite
🔴 [CRITICAL] Statement 3
↳ TRUNCATE destroys all rows in payments
Severity Levels
| Level | Meaning |
|---|---|
| 🔴 CRITICAL | High risk of downtime or data loss |
| 🟠 HIGH | Likely to cause production issues |
| 🟡 MEDIUM | May cause performance or locking issues |
| 🔵 LOW | Informational or minor risk |
Exit Codes
LockSafe returns exit codes for CI/CD usage:
| Code | Meaning |
|---|---|
0 |
No issues found |
1 |
Issues detected |
2 |
SQL parsing error |
Debug Mode
Enable debug logs:
locksafe --debug analyze migration.sql
CI/CD Usage
Use LockSafe in your pipeline to block unsafe migrations:
locksafe analyze migrations/0042_add_user_index.sql
If risks are detected, the command exits with code 1.
Tips
- Always review CRITICAL findings before running migrations
- Use
CONCURRENTLYfor index operations on large tables - Avoid schema changes that rewrite entire tables in production
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 locksafe-0.2.0.tar.gz.
File metadata
- Download URL: locksafe-0.2.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18aa9b305d4312f54408465b0d036ff741a5016d8167ead7a4622b5c2f58bb8c
|
|
| MD5 |
c1a489735a4d4ec7465a8bdbb3fca6b3
|
|
| BLAKE2b-256 |
c63e9cdbb0b773f9f7a3b6c10f6615f085c31d6875e0d00f0347a9ad6c5d0386
|
File details
Details for the file locksafe-0.2.0-py3-none-any.whl.
File metadata
- Download URL: locksafe-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8dbf558948bc6a05a2d86f5bf6626667e0b3dcb6e3690dba0d75b787c2d1a637
|
|
| MD5 |
26234e66dfc8f27b82ac078bc81c0097
|
|
| BLAKE2b-256 |
97a70e099398ddc2b983e15e51f1eddb73c4405a4c8d92a3c9493ced7975857c
|