netlify/context-and-tools/netlify-database
Claude Code and agent skill by netlify/context-and-tools
- community
Checking that the SKILL.md file is still in the repository.
Zero-config Postgres for Netlify apps via @netlify/database — querying data from Functions/Edge Functions, writing schema migrations, setting up Drizzle ORM, local dev with netlify dev, database branches for deploy previews, and migrating an existing Postgres project onto Netlify. Use when adding a database, building a contact form or CRUD API, writing SQL migrations, wiring up Drizzle, running netlify database commands, testing with a local Postgres, or switching from Neon/Supabase/RDS to Netlify Database.
Install
npx vskill@latest install netlify/context-and-tools/netlify-databaseSKILL.md
Netlify Database
Zero-config managed Postgres. Install @netlify/database, write migrations under netlify/database/migrations/, deploy — Netlify provisions the DB and applies migrations automatically. Queryable from Functions, Edge Functions, Builds, and Agent Runners.
Modern client (reach for this)
Own driver / ORM instead:
Legacy — do NOT use for new code: import { neon } from "@netlify/neon". Superseded by @netlify/database. Replace neon() calls with the Drizzle netlify-db adapter or a Postgres driver via getConnectionString(). The legacy env var NETLIFY_DATABASE_URL is replaced by NETLIFY_DB_URL.
Where things go
| What | Location | |
|---|---|---|
| Migrations | netlify/database/migrations/ (SQL files or subdirs with migration.sql) | |
| Query code | Functions (netlify/functions/), Edge Functions | |
| Drizzle schema | db/schema.ts (convention) | |
| Drizzle client | db/index.ts (convention) | |
| Connection string | NETLIFY_DB_URL env var, or getConnectionString() |
Querying
getDatabase(options?) returns a client with sql and pool. options.connectionString overrides the auto-provisioned one; options.debug enables logging.
SQLTemplate methods: execute() → Promise<T[]>, stream() → AsyncGenerator<T>, chunked(n) → AsyncGenerator<T[]>, toSQL() → raw SQL + params without executing.
sql helpers:
sql.identifier(value)— safe table/column name. String, string[], or{ schema, table, column, as }.sql.values(rows)— bulk-insert values list from a 2D array.sql.default— the SQLDEFAULTkeyword.sql.raw(value)— injects unparameterized SQL; bypasses injection protection. Only for trusted constants (e.g. `"DESC"`), never user input.sql.unsafe(query, params?, { rowMode })— raw query string with$1params;rowModeis"array"or"object".
Transactions — use pool
db.pool is a `pg.Pool`. BEGIN/queries/COMMIT must run on the same connection:
Own drivers:
Drizzle ORM
Install both packages from `@beta` — required. latest lacks the drizzle-orm/netlify-db adapter and will fail.
drizzle.config.ts — you MUST set out to the Netlify migrations directory or Netlify won't apply generated migrations:
Generate migrations after editing the schema: npx drizzle-kit generate.
Never run `drizzle-kit push` against a Netlify-hosted database, and never run `drizzle-kit migrate` against `NETLIFY_DB_URL`. Schema reaches hosted DBs only as committed migration files applied by the deploy. generate writes files; the deploy applies them.
Migrations
Files live in netlify/database/migrations/. Two formats:
Naming: <number>_<slug> — number is digits (timestamp or 0001…) defining order; slug is lowercase letters/numbers/hyphens/underscores. Sorted lexicographically, applied in order. Use timestamp prefixes (netlify database migrations new handles this) to avoid out-of-order rejection.
When applied:
- Production deploy: applied immediately before publish; a failure blocks publish. With auto-publish off, Netlify waits for manual publish before applying.
- Deploy preview: applied on every deploy before it goes live; a failure fails the deploy.
- Local: not automatic — run
netlify database migrations applyyourself.
Migration footguns (all detected as drift / rejected):
- Never edit an applied migration — checksum drift:
migration "<name>" has been modified after being applied. Write a new corrective migration. - Never remove an applied migration —
... has been removed after being applied. Restore it. - Out-of-order: a prefix ≤ the highest applied version is rejected. Timestamps avoid this.
- Prefer backwards-compatible migrations. Breaking changes (rename/drop column) → expand-and-contract across multiple deploys. New table / nullable column → single migration is fine.
Bring-your-own migration system: pick a directory other than netlify/database/migrations to avoid automatic detection, and you own applying to preview branches and production.
See references/migrations.md.
Local development
Local is one database that all code targets — branches are a deploy-time concept and don't exist locally. It's a real Postgres-compatible engine mirroring production, but single-process (not for load testing); auto-scale/sleep settings don't apply.
Start it — either path, state is interchangeable:
Or the Vite plugin:
Common commands (while local DB is running):
External tools (works while netlify dev runs):
See references/local-dev.md.
Setup
New project: describe your app to Agent Runners at https://app.netlify.com/start, or netlify create "<description>" locally.
Existing project:
Manual: npm install @netlify/database, write a migration under netlify/database/migrations/, write a function, netlify dev, deploy.
If `@netlify/database` is NOT installed, Netlify will NOT auto-provision a database — you'd have to create one manually from the UI Data & Storage > Database menu. Install the package.
CLI reference (netlify database)
Prereqs: Node ≥ 20.12.2, Netlify CLI ≥ 26.0.0 (npm install -g netlify-cli). All commands support --json.
| Command | Purpose | Key flags | ||
|---|---|---|---|---|
init | Set up DB in project | -y, --yes | ||
status | State: enabled, installed, connection string, applied/pending migrations | -b, --branch, --show-credentials | ||
connect | SQL REPL, or --query one-shot | -q, --query, --json | ||
migrations apply | Apply pending to local DB | --to <name> | ||
migrations new | Scaffold a migration | -d, --description, `-s, --scheme sequential\ | timestamp` | |
migrations pull | Overwrite local files from a branch | -b, --branch, --force | ||
migrations reset | Delete unapplied local migration files | -b, --branch | ||
reset | Drop all data/tables — local only | — |
See references/cli-commands.md.
REST API
Scoped to a site, rooted at https://api.netlify.com/api/v1, OAuth 2. Full reference: https://open-api.netlify.com.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/netlify-database/SKILL.md
Popularity
- Repository stars
- 34
- Repository forks
- 7
- 7-day trend score
- 18
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 12 Aug 2026, 2 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/netlify/context-and-tools/netlify-database)