agentleFS
chenson42chenson42/stackkeel/.claude/skills/neon-postgres/SKILL.md

neon-postgres

Skill1 starsChanged 51 days agoMITView on GitHub

Patterns for working with Neon Postgres in this workspace — branching for schema work, pooled vs direct connections, the dual-driver createDb() factory, and the Neon docs as source of truth

  • Reads credentials

29 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use neon-ai-gateway, neon-functions and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • jaaklaSkill

    neon-ai-gateway

    One API and one credential for frontier and open-source LLMs, built into your Neon branch and powered by Databricks. Use when a user wants to call an LLM, add AI/chat/an agent to their app, route between model providers (OpenAI, Anthropic, Google/Gemini, Meta, Alibaba, and more), or avoid juggling separate provider API keys and accounts — especially when they already use Neon and want AI requests to branch with their project. Works with the OpenAI SDK, Anthropic SDK, google-genai, the Vercel AI SDK, and Mastra by changing only the base URL. Triggers include "call an LLM", "add AI to my app", "chat completion", "model routing", "LLM proxy/gateway", "one API for all models", "use Claude/GPT/Gemini", "AI SDK", "Mastra agent", "Neon AI Gateway", and "log/rate-limit AI calls".

    Also in 4 projects that use this

  • jaaklaSkill

    neon-functions

    Long-running, serverless Node.js HTTP functions deployed onto your Neon branch, with DATABASE_URL injected automatically and compute that runs next to your data. Use when a user wants to host an API, an AI agent with long streaming responses, a WebSocket or server-sent-events (SSE) server, a webhook handler, a Discord bot, an MCP server, or any request/response workload that risks timing out on short, lambda-style serverless functions — and wants it to branch with their database. Also use for Function Triggers: a cron or an object-storage event that POSTs to a function. Triggers include "serverless function", "deploy an API", "long-running function", "streaming agent", "SSE server", "WebSocket server", "webhook handler", "MCP server", "cron", "function trigger", "scheduled function", "cron job", "object storage trigger", "on upload", "run code next to my database", "function that won't time out", "function logs", "Neon Functions", "Neon Compute", "DDoS protection", "rate limiting", and "production hardening".

    Also in 4 projects that use this

  • xAISkill

    neon-postgres-branches

    Choose and create the right Neon branch type for testing and development. Use when users ask about Neon branching, migration testing with real data, isolated test environments, schema-only branch workflows for sensitive data, or branch creation via Neon CLI or Neon MCP. Triggers include "Neon branch", "test migrations safely", "branch production data", "schema-only branch", "reset branch" and "sensitive data testing".

    Also in 4 projects that use this

  • sayuru-akashSkill

    neon-postgres-egress-optimizer

    Diagnose and fix excessive Postgres egress (network data transfer) in a codebase. Use when a user mentions high database bills, unexpected data transfer costs, network transfer charges, egress spikes, "why is my Neon bill so high", "database costs jumped", SELECT * optimization, query overfetching, reduce Neon costs, optimize database usage, or wants to reduce data sent from their database to their application. Also use when reviewing query patterns for cost efficiency, even if the user doesn't explicitly mention egress or data transfer.

    Also in 4 projects that use this

  • VercelSkill

    next-cache-components

    Next.js 16 Cache Components - PPR, use cache directive, cacheLife, cacheTag, updateTag

    Also in 3 projects that use this

  • SentrySkill

    next-best-practices

    Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling

    Also in 4 projects that use this

  • +2 more from jaakla

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 29 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Delete the branch: when the feature ships.

    line 44
  2. Very specific:

    Use the pooled host (-pooler suffix) for app code — Neon's PgBouncer multiplexes connections so a bursty serverless workload doesn't …

    line 50

“Common” is measured: kept by at least 6 in 10 of the 29 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Neon Postgres in This Workspace

Both web apps use one shared Postgres — Neon in staging/production (serverless Postgres with autoscaling, branching, instant restore, scale-to-zero), Docker or native Postgres locally. All DB access goes through the shared createDb() factory in packages/db: a localhost/127.0.0.1/0.0.0.0 hostname in DATABASE_URL selects drizzle-orm/node-postgres (a real pg.Pool); any other hostname selects the Neon serverless driver. The check-driver-capability tripwire refuses a build whose code calls APIs the selected driver can't run (e.g. .transaction() on neon-http).

This skill captures the patterns most relevant to this codebase. For broader Neon questions, fall back to the official docs.

Environment Variables

VariablePurposeConnection shape
DATABASE_URLRuntime app connection for both apps.On Vercel: pooled Neon host (-pooler). Locally: local Postgres.
DIRECT_DATABASE_URLDrizzle Kit, migrations, scripts.Direct (no -pooler suffix).

Migration tools need a direct connection because they run DDL and inspect the schema; the app at runtime uses the pooled connection because serverless functions burst.

Migration Commands (run from the repo root)

pnpm db:generate   # Diff packages/db/src/schema/ against packages/db/migrations/ and write a new migration. File-based only, never dials a DB.
pnpm db:migrate    # Apply committed migrations in order (tracked in drizzle.__drizzle_migrations)
pnpm db:push       # Apply the live diff directly — early iteration on a disposable branch only. Interactive terminal only (see below).
pnpm db:seed       # Seed roles, features, bindings, off-by-default flags. Idempotent.

The schema files are the source of truth; packages/db/migrations/ is what gets replayed. Every migration carries a -- MODULE: <name> header (personalization strips by module) and a -- VERIFY: <sql> predicate (the schema-prerequisite gate runs it against the deploy target).

db:push hard-refuses outside a real TTY — drizzle-kit push's destructive-statement confirmation has been directly observed to silently auto-apply (no prompt, no error) when stdin/stdout isn't a terminal. Never pipe, script, or run it from a non-interactive agent shell. DB-touching commands also refuse a non-local DATABASE_URL unless explicitly overridden — schema mistakes belong on disposable branches, not shared environments.

Branching Pattern for Schema Work

Neon's killer feature is branches — instant, copy-on-write clones of your database with their own compute endpoint. Use them for any non-trivial schema change you want to test against production-shaped data:

  1. Create a Neon branch off main (Neon console, or neonctl branches create --name feature/<name>).
  2. Grab the branch's connection strings (pooled + direct).
  3. Point .env.local at the branch (DATABASE_URL + DIRECT_DATABASE_URL).
  4. Iterate: pnpm db:push repeatedly while shaping the schema (interactive terminal only), then pnpm db:seed to confirm the seed still applies.
  5. When the schema is right, commit a migration: pnpm db:generate, add the -- MODULE: header and -- VERIFY: predicate, review, commit.
  6. Apply to production via the db-sync workflow after merge (expand-only migrations).
  7. Delete the branch when the feature ships.

The point is that schema mistakes never touch production data. CI's e2e workflow uses the same mechanism — an ephemeral branch created and deleted per run.

Pooled vs Direct Connections

Use the pooled host (-pooler suffix) for app code — Neon's PgBouncer multiplexes connections so a bursty serverless workload doesn't exhaust the Postgres connection limit. Use the direct host for migrations.

The Edge runtime cannot import @repo/db regardless of which host is configured — it pulls in a Postgres driver. Each app's src/proxy.ts runs on Edge and must never import it; the server-only guard turns that mistake into a build failure rather than a runtime one.

Scale-to-Zero and Cold Starts

By default, Neon's compute suspends after a few minutes of inactivity and resumes on the next query. The first query after suspend has a noticeable cold-start penalty (hundreds of milliseconds). Storage stays active, so data is never paged out.

Useful Patterns

Querying

import { db } from "@repo/db";
import { users } from "@repo/db/schema";
import { eq } from "drizzle-orm";
const row = await db.query.users.findFirst({ where: eq(users.email, email) });

Raw SQL escape hatch

db.execute(sql\SELECT count(*) FROM audit_events`)viadrizzle-orm's sqltag. Use sparingly — almost everything is expressible through the query builder — and neversql<Date>(thecheck:sql-date` tripwire bans it: the Neon serverless driver returns computed-expression timestamps as strings at runtime, so the type lies).

Two traps that have both cost real time:

  • Alias every computed column. SELECT to_regclass(a) IS NOT NULL, to_regclass(b) IS NOT NULL returns two columns BOTH named ?column?; node-postgres keys each row by column name, so they collapse into one and the second value is lost.
  • Never round-trip a timestamp through JavaScript for a keyset cursor. Postgres stores timestamptz at microsecond precision; a JS Date holds milliseconds, so a row at .123456 is neither < .123 nor = .123 and vanishes from later pages. Compare row values inside Postgres instead.

Neon Documentation

The Neon docs are the source of truth for platform behavior. Always verify against the docs before relying on a feature claim — Neon evolves.

Any Neon doc page is available as Markdown by appending .md to the URL.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.