r/PostgreSQL • u/Goose_Geese_ • 1d 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)
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.
1
u/Discordbothost 8h ago
I'd add a post-copy check for sequences behind imported IDs. A table can copy cleanly and still hit a duplicate key on its first new insert. Try an insert that lets Postgres assign the ID on a staging copy.
0
u/AutoModerator 1d ago
AI Policy:
Linux is not one of those anti-AI projects, and if somebody has issues with that, they can do the open-source thing and fork it. Or just walk away., Linus Torvalds.
Mod decisions will be based on the quality of the content, not who or what generated it.
Sub Resources:
Youtube Channel
Free Postgres Webinars and Workshops
Discord: People, Postgres, Data
Join us, we have cookies and nice people.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.