Hello, I'm Maneshwar. I'm working on git-lrc: a Git hook for Checking AI generated code.
AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
When you're working with multiple PostgreSQL environments — dev, staging, prod — you often need to sync schema without touching the data.
This post shows how to use a pure Python script to dump an entire schema, including tables, views, triggers, sequences, constraints, and stored procedures.
No external dependencies. No ORM. No pg_dump black box.
What This Script Does
- Connects to any PostgreSQL database.
-
Extracts complete schema info:
- Tables, Columns, Indexes
- Views, Sequences, Triggers
- Functions & Procedures
- Constraints (PK, FK, etc.)
-
Outputs schema as:
- Pretty terminal dump
- JSON file (
schema_dump.json) - Raw SQL DDL file (
schema_dump.sql)
Setup
Install the dependency:
pip install psycopg2
Set your connection config at the top:
engine = "postgresql"
name = "your_db"
user = "your_user"
password = "your_pass"
host = "your_host"
port = "5432"
How to Use
Just run the script:
python dump_schema.py
This will:
- Print a human-readable breakdown of your entire schema
-
Write two files in the current directory:
schema_dump.jsonschema_dump.sql
JSON Output
You’ll get structured JSON that looks like this:
{
"database_info": {
"name": "liveapi",
"host": "34.57.96.60",
"port": "5432",
"engine": "postgresql",
"dump_date": "2025-07-18 18:00:00"
},
"schemas": {
"public": {
"tables": {
"users": {
"columns": [...],
"primary_keys": [...],
"foreign_keys": [...],
"indexes": [...],
"triggers": [...]
}
},
"views": [...],
"functions": [...],
"triggers": [...],
"sequences": [...],
"constraints": [...]
}
}
}
Use it for:
- Schema diffs between environments
- Version control on schema metadata
- Visual schema documentation
SQL Output
The schema_dump.sql file contains raw SQL:
CREATE TABLE public.users (
id uuid NOT NULL DEFAULT gen_random_uuid(),
email text NOT NULL,
PRIMARY KEY (id)
);
ALTER TABLE public.users ADD CONSTRAINT fk_users_org FOREIGN KEY (org_id) REFERENCES public.org(id);
CREATE UNIQUE INDEX idx_users_email ON public.users(email);
You can pipe this into psql on another server:
psql -h target_host -U target_user -d target_db -f schema_dump.sql
This lets you sync schema from one DB to another in a controlled way — no data, just structure.
Why Use This Over pg_dump
| Feature | pg_dump --schema-only |
This Script |
|---|---|---|
| JSON Output | ❌ | ✅ |
| Selective Extraction | ❌ (manual) | ✅ |
| Programmatic Access | ❌ | ✅ |
| Easy to Extend | ❌ | ✅ |
| Custom Logic | ❌ | ✅ |
| Triggers, Views, FKs, Indexes | ✅ | ✅ |
If you're building tooling, dashboards, or want to integrate schema dumping into your CI/CD, this Python approach is flexible and extendable.
Final Thoughts
You can use this Python script to:
- Mirror your schema across environments
- Export schema snapshots for backup or review
- Debug schema issues with a visual/textual snapshot
- Generate schema migration plans manually
Bonus: Want to Sync Schema Automatically?
Take the schema_dump.sql generated here and write an Ansible task or a Flyway/Liquibase wrapper to apply it to staging/prod in your pipeline.
👉 Check out: git-lrc
Any feedback or contributors are welcome! It’s online, open-source, and ready for anyone to use.
⭐ Star it on GitHub:
HexmosTech
/
git-lrc
Check AI generated code with Git Hooks
git-lrc
Check AI-Generated Code With Git Hooks
AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
See It In Action
See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements
git-lrc-intro-60s.mp4
Why
- 🤖 AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
- 🔍 Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
- 🔁 Build a habit, ship better code. Regular review → fewer bugs → more robust code → better results in your team.
- 🔗 Why git? Git is universal. Every editor, every IDE, every AI toolkit uses it…

Top comments (4)
insightful for sync schema
Thanks
Where is the script?
I dont remember why, but I switched to bash script.