r/PostgreSQL • • 19h ago

Projects I built a free, read-only CLI that audits legacy Postgres/SQLite schemas before migration and compiles dbt staging + diagnostic SQL (zero PII in outputs)

1 Upvotes

Most legacy migration blowups happen in week one because nobody knew a source table lacked a primary key for AWS DMS CDC, had NUL bytes (`0x00`) that crash Postgres UTF-8 imports, carried CP1252 mojibake, or had free-text notes full of undeclared PII.

I open-sourced `crucible-audit` (MIT), a read-only Python CLI that profiles a source database locally with no outbound network calls. It outputs a static HTML audit page, a `profile.json` evidence file, dbt staging models, and read-only diagnostic SQL.

What it checks right now:

- AWS DMS CDC blockers: missing primary keys, wide LOB columns, NUL-byte poison, CP1252 encoding ghosts, and legacy proprietary types.

- Shadow FKs and orphan keys: infers undeclared foreign keys by column naming and key overlap, then reports both total orphaned rows and distinct orphan keys (`COUNT(*)` vs `COUNT(DISTINCT)`).

- UK shadow PII (Zero-PII output): detects UK NINOs, Modulus-11 validated NHS numbers, and legacy redaction markers inside free-text columns. Outputs record counts, rates, column metadata, and rule IDs only, so no raw cell values or partial masks ever land in JSON, HTML, or SQL files.

- PostgreSQL-valid diagnostic SQL: generated regex queries use POSIX word boundaries (`\y`) instead of PCRE `\b`, so the compiled `diagnostics/*.sql` files run directly in `psql`.

- External `rules.yaml`: toggle rule packs or add custom regex rules without editing Python.

Live sample audit (generated from a synthetic dirty UK council SQLite DB): https://schemafirst.parkanore.com

GitHub (MIT): https://github.com/oranmcclintock/schemafirst.git

Curious what migration failure modes you hit most often on legacy Postgres, SQL Server, or Oracle estates that a pre-flight profiler should catch.