FastAPI + PostgreSQL Functions: Safe DB Workflow

    by Claude Workflow Lab

    1

    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.

    $6

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    What it does

    • Rules for working against a live Postgres: always roll back, read-only by default
    • Query helper that runs a query, prints a function's live source, or diffs it against the repo
    • Tests a changed SQL function as a temporary object, old versus new, with nothing committed

    FastAPI + PostgreSQL Functions: Safe DB Workflow

    Example session with this skill installed

    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.

    • Read your context and instructions
    • Compiled the fastapi + postgresql

    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.

    func_regress.py --file candidate.sql

    Connects securely to your tools. The creator never sees your data.

    About this skill

    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.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 1 day ago

    Software
    Claude Code
    ora compatible agent runtime
    Python 3PostgreSQLGitDocker Compose

    Permissions

    Terminal / Shell
    Network Access
    Read Files
    Environment Variables
    Write Files
    Listed1 day ago

    What's inside

    Frequently Asked Questions

    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.

    This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

    Connect your AI agent to Agensi through MCP, then ask it to use FastAPI + PostgreSQL Functions: Safe DB Workflow on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

    New in Data & Databases

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.