Skip to main content

Command menu

Jump to a page or search the catalog

AI Tools & Scripts

FastAPI + PostgreSQL Functions: Safe DB Workflow

Safe loop for FastAPI apps whose business logic sits in PostgreSQL functions: query the live DB with rollback, diff repo versus deployed functions, regression-test a recursive function rewrite, then deploy and audit security.

$6.00

What you get: 1 file · 8.5 KB · ZIP

See purchase options

Product description

When business logic lives in PostgreSQL functions, the question "is the function in git the one that is live?" matters, and a rewritten recursive function can quietly change totals. This skill is a work loop for that architecture: thin FastAPI routers calling SELECT * FROM function(...), SQL files in the repo, Jinja templates on top.

What is inside: - SKILL.md - live database rules (always roll back, read-only by default); changing a recursive function such as a bill-of-materials or category tree, including the rule that a pure regrouping may change rows but must keep leaf totals; running the app locally only when a page check is needed; commit, push and deploy, with a prod-parity check before risky dependency or Dockerfile changes; a security audit checklist for cookie-session apps; a finish list; and an Adapt-to-your-setup section. - scripts/db.py - a query helper: q runs a query and always rolls back, fn prints the live source of a function, diff compares the live function with the file in your repo, token-normalised. Configured by DATABASE_URL or PG variables. - scripts/func_regress.py - loads a candidate function as a temporary object (no lock on the live one, nothing committed), runs old and new for every root id, and reports changed rows, changed leaf totals, slow roots and errors.

Who it is for: solo developers and small teams with a FastAPI plus PostgreSQL stack. Needs psycopg2-binary and database access. It is also part of the Production Ops: DB, Scrapers, Trading Bot pack at a lower per-skill price.

Example request

I rewrote bom_tree() to add a nested level. Check it against every real root before I apply it, and tell me if the repo version matches what is live.

Example result

Example on a fictional setup (DB: shop, function: public.bom_tree, SQL files in sql/).

  1. Repo versus live: db.py diff bom_tree reports the token-normalised bodies differ. The live function has an extra DISTINCT that is not in sql/bom_tree.sql, so someone patched production by hand. Decision needed from you: which version is the baseline. I used the live one as baseline.
  2. Regression, nothing applied: func_regress.py --file candidate.sql --func bom_tree --roots-sql "select distinct id from items" --timeout 8s loads the candidate as pg_temp.bom_tree_new, so no lock on the live function and nothing committed.
  3. Result over 2,140 roots: 312 roots changed rows (expected, the new nested level), 0 roots changed per-leaf totals, 3 roots slow (new more than 3x live and over 1 s), 0 errors or timeouts.
  4. Reading: a pure regrouping may change rows but must keep totals, and totals held. The 3 slow roots are the deepest trees; add an index on the parent column before applying and re-run just those 3.

Next: apply in a transaction after the index, re-run db.py diff to confirm repo and live match, then commit the SQL file. Nothing has been changed on the live DB.

Requirements

  • Claude Code or a compatible agent runtime
  • Python 3 with psycopg2-binary for the helper scripts
  • Access to a PostgreSQL database (a read-only role is enough for most steps)
  • Git, and a deploy path such as ssh or docker compose

How to install

Unzip into your Claude Code skills folder (~/.claude/skills/ or .claude/skills/ in a project) and start a new session; the skill loads by its description.

What you get

1 file · 8.5 KB

  • fastapi-postgres-workflow.zipZIP · 8.5 KB
LicenseCommercial use allowed
PublishedDec 3, 2026
File size8.5 KB
File formatZIP
Versionv1.0

Tags

claude codeclaude skillai agentpostgresql
C
Claude Workflow Lab

Frequently asked questions

Do I get access instantly?

Yes. This is a digital product - you can download it right after checkout, straight from your library.

Can I use it for commercial projects?

Yes. Commercial use is allowed: use it in your own business and in things you sell. You may not resell or redistribute the file itself.

What's your refund policy?

You can request a refund within 30 days. If something isn't right, request it from your order and the Getly team reviews it.

What file formats and sizes will I get?

You'll download 1 file - ZIP - 8.5 KB in total.

Do I get free updates?

Yes - when the seller ships a new version, you can re-download the latest files from your library at no extra cost. Check the changelog for recent updates.

Price

$6.00