PostgreSQL schema drift to a reviewed Python patch: a LangGraph workflow

A PostgreSQL column rename is easy to migrate in the database and easy to miss in application SQL. I am working on SH-PSCBS, an experimental open-source project that turns a schema change into a Python repair proposal with tests and a human review step.

Repository and Docker demo: GitHub - iago511/Self-Healing-Polyglot-Schema-Code-Bifurcation-System: SH-PSCBS - PostgreSQL schema changes shouldn’t break your app. Detect the impact, generate a fix, run tests, and review a ready-to-approve Git branch. · GitHub

Workflow demonstration

For example, changing clientes.apelido to clientes.nome can leave a query such as SELECT apelido FROM clientes broken. The goal is to connect the schema event to the affected code and produce a diff that a developer can inspect.

The workflow uses a LangGraph StateGraph with separate stages for schema analysis, impact analysis, planning, correction, validation and review. PostgreSQL snapshots and events feed the process; SQLite stores local event and proposal state. Groq handles analysis/review stages and Ollama handles correction in the current live-model setup.

Changes are prepared in an isolated repository copy. The proposal is checked with pytest in a Docker container with network isolation, then presented with the diff and validation evidence. Human approval is required before a Git commit on a repair branch, and publishing is an explicit step.

A distinction that matters here: a passing test run only covers the tests provided. It cannot prove that a schema change preserved the meaning of the application. A reviewer still needs to inspect the proposal.

Current scope is PostgreSQL and Python. The repository name describes a broader direction; general support for other languages is not implemented. The Docker Compose demo uses simulated model responses and disposable services, so it demonstrates the workflow without API keys. It does not measure live-model repair accuracy. The project is MIT licensed and experimental.

I would appreciate feedback on two specific design questions:

  1. What evidence would you want beside the diff before approving a schema-driven repair?
  2. For evaluation, which cases should come first after a simple column rename: type changes, dropped columns, dynamic SQL, or ambiguous renames?

The source, demo instructions and contribution guide are in the repository.

The passing-tests caveat you already call out is the right frame: the review packet has to help a human see whether meaning was preserved, not just whether the suite went green.

Beside the diff, I would want:

  • The exact schema event (old and new column, type, nullability, default, and any constraints or indexes that moved with it), plus the snapshot id it came from.
  • A map of every hit: file, line, and whether it was a literal identifier, a string in dynamic SQL, or a name built at runtime. “We changed 12 queries” is less useful than seeing the three string-built ones that the patch might have missed.
  • The tests that were run, and equally the ones that were not: which of the affected modules have no test covering that column. A green run over an empty or unrelated suite is the main false-confidence case.
  • A short before/after of representative queries or fixture rows (same input, old vs new column), so the reviewer can see that apelido became nome and not something else.
  • The model and prompt versions used for the proposal, so a later re-run can be compared.

On evaluation order, I would go: ambiguous renames first, then dropped columns, then type changes, then dynamic SQL.

An ambiguous rename (apelido → nome when nome already exists, or two columns that could both be the source) is the case where a confident wrong patch is most damaging, and it is still close to your current rename path. Dropped columns next, because the correct repair is often not a mechanical edit but a decision (remove the field, replace it, or fail). Type changes are mostly mechanical but they catch silent meaning changes (text to enum, timestamp tz). Dynamic SQL last: it is the hardest to detect reliably, and you will want the simpler cases solid before you measure recall on strings assembled at runtime.