Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

netlify-database

БесплатноБез исполняемых скриптовНе проверен

Use this skill whenever a Netlify project needs a Postgres database. It covers Netlify Database setup, queries from Functions or Edge Functions, schema…

netlifyот netlify★ 58 звёзд на GitHub

Об этом скилле

Netlify Database

Managed Postgres built into Netlify. Netlify provisions the database, applies migrations on deploy, and creates a database branch for every deploy preview and agent run.

Use this, not that

// ✅ Modern: auto-configured, branch-aware
import { getDatabase } from "@netlify/database";
const db = getDatabase();
const users = await db.sql`SELECT * FROM users WHERE id = ${id}`;

// ✅ Drizzle: native adapter, connection configured automatically
import { drizzle } from "drizzle-orm/netlify-db";
export const db = drizzle({ schema });
// ❌ Legacy Neon extension: do not write new code with it
import { neon } from "@netlify/neon";   // reads NETLIFY_DATABASE_URL

Netlify Database reads NETLIFY_DB_URL. It does not read NETLIFY_DATABASE_URL.

Install

npm install @netlify/database                              # required: its presence triggers provisioning
npm install drizzle-orm@beta && npm install -D drizzle-kit@beta   # Drizzle: @beta is mandatory
npm install -g netlify-cli                                  # CLI 26.0.0+, Node 20.12.2+

Or run netlify database init --yes. It is non-interactive: it installs packages, scaffolds a starter migration, and verifies connectivity.

⚠️ No @netlify/database installed means no database. Automatic provisioning only happens when the package is in the project. Without it, nothing is provisioned on deploy.

⚠️ Costs credits. Netlify Database is available on Credit-based plans only. An active database consumes credits for compute and bandwidth. Storage is currently free. Every active deploy preview uses one branch toward the plan's branch limit.

File layout

netlify/database/migrations/          # auto-applied on deploy; do not move
├── 20260301143000_create_users.sql            # SQL-file format
└── 20260318091500_add_posts/migration.sql     # subdirectory format
netlify/functions/*.ts                # query from here or from edge functions
drizzle.config.ts                     # if using Drizzle
db/schema.ts, db/index.ts             # Drizzle schema and client

Migration name format is <number>_<slug>:

  • The slug may contain only [a-z0-9_-].
  • Migrations are sorted lexicographically. Use timestamp prefixes.
  • A migration's name is its filename minus the extension.

Function example

// netlify/functions/users.ts
import type { Config } from "@netlify/functions";
import { getDatabase } from "@netlify/database";

const db = getDatabase();

export default async (req: Request) => {
  if (req.method === "GET") {
    return Response.json(await db.sql`SELECT * FROM users ORDER BY id DESC`);
  }
  if (req.method === "POST") {
    const { name, email } = await req.json();
    const [user] = await db.sql`INSERT INTO users (name, email) VALUES (${name}, ${email}) RETURNING *`;
    return Response.json(user, { status: 201 });
  }
  return new Response("Method not allowed", { status: 405 });
};

export const config: Config = { path: "/api/users" };
-- netlify/database/migrations/20260301143000_create_users.sql
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT NOT NULL UNIQUE,
  created_at TIMESTAMP DEFAULT NOW()
);

Drizzle

// drizzle.config.ts
import { defineConfig } from "drizzle-kit";
export default defineConfig({
  dialect: "postgresql",
  schema: "./db/schema.ts",
  out: "netlify/database/migrations",   // REQUIRED: the default "drizzle" dir is never applied
});
// db/schema.ts
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
  id: serial().primaryKey(),
  name: text().notNull(),
  email: text().notNull().unique(),
  createdAt: timestamp().defaultNow(),
});

// db/index.ts
import { drizzle } from "drizzle-orm/netlify-db";
import * as schema from "./schema";
export const db = drizzle({ schema });

After changing the schema:

  1. Run npx drizzle-kit generate.
  2. Commit the generated files under netlify/database/migrations/.
  3. Deploy.

API: @netlify/database

Call Returns
getDatabase(options?) Client with sql and pool. Options: connectionString, debug. Picks the right connector per runtime.
getConnectionString() Postgres URL for the current branch (production or preview), for your own driver.
process.env.NETLIFY_DB_URL Same URL, available in builds, functions, edge functions, and agent runners.

db.sql

db.sql is a tagged template (Waddler). Every ${} value is a bound parameter. The result is awaitable and resolves to T[].

const rows = await db.sql<User>`SELECT * FROM users`;
for await (const row of db.sql`SELECT * FROM users`.stream()) {}
for await (const chunk of db.sql`SELECT * FROM users`.chunked(100)) {}
db.sql`...`.toSQL();                                    // SQL + params, not executed

db.sql.identifier({ table: "users" });                  // dynamic table/column na
Полный SKILL.md на GitHub

Установить netlify-database в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/cli-commands.mdreferences/legacy-extension.mdreferences/local-dev.mdreferences/migration-from-extension.mdreferences/migrations.mdreferences/operational-footguns.md

FAQ

Что делает скилл netlify-database?

Use this skill whenever a Netlify project needs a Postgres database. It covers Netlify Database setup, queries from Functions or Edge Functions, schema changes through migrations in netlify/database/migrations, Drizzle ORM wiring, local dev databases and tests, deploy-preview database branches, and moving off Neon, Supabase, RDS or the legacy @netlify/neon extension. Activate it when someone asks to add a database, store users or posts or orders, save form submissions, create or alter a table, add a column, write a migration, set up Drizzle, fix a failing migration deploy, seed or test against a local database, or switch an existing Postgres app onto Netlify. Use it even if the request never says Netlify Database explicitly.

Как установить скилл netlify-database?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл netlify-database запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить netlify-database с