Skip to main content

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 CONCURRENTLY for 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

locksafe-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

locksafe-0.1.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file locksafe-0.1.0.tar.gz.

File metadata

  • Download URL: locksafe-0.1.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

Hashes for locksafe-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e88b6593c03cc995ff1f5d08b4c225c7d806fec605fb6d140107617a951e9dff
MD5 22b337ecc3bea832ece3ac8322e6d99f
BLAKE2b-256 2c80f0b134a5137d4d30bbbaa70e6a559be2728ff3ef3003f59a3f04f9ba3522

See more details on using hashes here.

File details

Details for the file locksafe-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: locksafe-0.1.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

Hashes for locksafe-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efeb7f3aaa9bf25eb93fcdbdfe010badf01b9444240d0d6757ce09e037c568fd
MD5 6be0870f4ed5fca8c04d543e034d1451
BLAKE2b-256 5181c56bd39009482cb97f1a8e0621d3fd8d04ea896372dc2ce128c20300c9b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page