database-guide

Configure PostgreSQL connections and schema setup for FastAPI projects.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/databio/ai-sandbox --skill database-guide
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: database-guide
Source: https://github.com/databio/ai-sandbox/tree/main/workspaces/.claude/skills/database-guide
Command: npx skills add https://github.com/databio/ai-sandbox --skill database-guide

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Set up and manage PostgreSQL databases for FastAPI projects with a Docker-based local development workflow (single-command, no docker-compose) and production-ready configurations using environment variables. It follows a no-migrations philosophy, dropping and recreating the schema on changes, and provides guidance for setup_postgres.sh scripts, environment files that must be sourced manually, pydantic-settings configuration, SQLModel connections, lifespan handlers, session management, and Pytest-based tests using in-memory SQLite.

Core Features & Use Cases

  • Docker-based local PostgreSQL setup with setup_postgres.sh
  • Environment-based production configuration (must source deployment/*.env)
  • No migrations policy with drop-and-recreate on schema changes
  • SQLModel integration, lifespan management, and session handling
  • Pytest with in-memory SQLite for fast tests
  • Use Case: Configure a FastAPI app to connect to PostgreSQL, handle migrations via drop/recreate, and test endpoints locally.

Quick Start

Source deployment/demo.env to load local Postgres credentials and start the FastAPI app to create tables on startup.

Frequently Asked Questions about database-guide

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up PostgreSQL with FastAPI and Docker for local development?▼

PostgreSQL setup for FastAPI with Docker is automated using a setup_postgres.sh script, enabling a single-command local development workflow without needing docker-compose. You must source your environment file to load credentials before starting the application to create tables on startup.

How do I handle database schema changes in FastAPI without using migrations?▼

Database schema changes in FastAPI are handled using a no-migrations policy that drops and recreates the schema on changes. This approach is paired with a startup lifespan handler that automatically creates tables when the application launches.

Can I use in-memory SQLite for FastAPI testing instead of PostgreSQL?▼

FastAPI testing uses in-memory SQLite for fast Pytest-based tests in CI environments. This allows you to test endpoints locally without the overhead of a running PostgreSQL instance, while production uses environment-based configuration.

Do I need to manually source environment files to configure a FastAPI PostgreSQL connection?▼

Environment files must be sourced manually to configure the FastAPI PostgreSQL connection in production. The setup relies on pydantic-settings configuration, meaning you source deployment/*.env files to load local Postgres credentials before running the application.

What is the best way to integrate SQLModel for session management in a FastAPI app?▼

SQLModel integration in a FastAPI app involves configuring database connections and handling session management within startup lifespan handlers. This approach manages schema creation and sessions seamlessly alongside the no-migrations drop-and-recreate policy.

Why does my FastAPI PostgreSQL database setup script fail to connect?▼

FastAPI PostgreSQL database setup scripts fail to connect if environment files are not sourced manually before running. You must source deployment/demo.env to load local Postgres credentials into the environment for the application to establish a valid connection.