db
PostgreSQL database with Drizzle ORM — Docker for local dev, connection pooling for production. Type-safe schema, migrations, and query patterns. Use this skill when the user says "setup database", "add db", "setup drizzle", "setup postgres", or "database setup".
What this skill does
# Database Setup with Drizzle ORM
Sets up a type-safe PostgreSQL database layer using Drizzle ORM with the `postgres` driver. Uses Docker for local development with a production-ready migration workflow.
## Prerequisites
- Next.js app with `src/` directory and App Router
- Docker setup (for local PostgreSQL -- see docker-compose section)
- Environment configuration (dependency: `env-config` skill)
## Installation
```bash
bun add drizzle-orm postgres
bun add -D drizzle-kit
```
## Environment Variables
Add to `.env.local`:
```env
DATABASE_URL=postgresql://app:password@localhost:5432/appdb
```
If using the `env-config` skill, add to your `env.ts`:
```typescript
// In env.ts, add to server object:
server: {
// ... existing variables
DATABASE_URL: z.string().url(),
},
// Add to runtimeEnv:
runtimeEnv: {
// ... existing variables
DATABASE_URL: process.env.DATABASE_URL,
},
```
## Docker Setup
Add the PostgreSQL service to `docker-compose.yml`. Uses `pgvector/pgvector:pg16` for vector search support (compatible with standard Postgres usage):
```yaml
services:
postgres:
image: pgvector/pgvector:pg16
ports:
- "5432:5432"
environment:
POSTGRES_USER: ${POSTGRES_USER:-app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password}
POSTGRES_DB: ${POSTGRES_DB:-appdb}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER:-app}"]
interval: 5s
timeout: 5s
retries: 5
start_period: 60s
restart: unless-stopped
volumes:
postgres_data:
```
> **Note:** Credentials here match the `docker` skill defaults (`app/password/appdb`). If your `docker-compose.yml` already defines a `postgres` service (from the `docker` skill), skip this section — the database is already configured.
Start the database:
```bash
docker compose up -d db
```
## What Gets Created
```
src/
├── lib/
│ └── db/
│ ├── index.ts # Database client factory
│ └── schema/
│ └── index.ts # Schema barrel export (add tables here)
├── lib/
│ └── db/
│ └── migrate.ts # Migration runner
drizzle.config.ts # Drizzle Kit config (project root)
```
## Setup Steps
### Step 1: Create Database Client (`src/lib/db/index.ts`)
This is the main database client factory. It uses the `postgres` package (NOT `pg`) with `drizzle-orm/postgres-js`.
```typescript
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
throw new Error("DATABASE_URL is not set");
}
const client = postgres(connectionString);
export const db = drizzle(client, { schema });
export type Database = typeof db;
```
### Step 2: Create Schema Barrel Export (`src/lib/db/schema/index.ts`)
This is the barrel export for all schema tables. Add your own tables here as you build features.
```typescript
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
// Example table -- replace with your schema
export const example = pgTable("example", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.notNull()
.defaultNow(),
});
```
### Step 3: Create Migration Runner (`src/lib/db/migrate.ts`)
A standalone script that runs migrations against the database. Uses a single connection (`max: 1`) and exits cleanly after completion.
```typescript
import { drizzle } from "drizzle-orm/postgres-js";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import postgres from "postgres";
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
throw new Error("DATABASE_URL is not set");
}
const client = postgres(connectionString, { max: 1 });
const db = drizzle(client);
async function main() {
console.log("Running migrations...");
await migrate(db, { migrationsFolder: "./drizzle" });
console.log("Migrations complete!");
await client.end();
}
main().catch((err) => {
console.error("Migration failed:", err);
process.exit(1);
});
```
### Step 4: Create Drizzle Kit Config (`drizzle.config.ts`)
Create this file at the project root. It tells Drizzle Kit where to find the schema and where to output migration files.
```typescript
import { defineConfig } from "drizzle-kit";
const url = process.env.DATABASE_URL;
if (!url) throw new Error("DATABASE_URL is required");
export default defineConfig({
schema: "./src/lib/db/schema/index.ts",
out: "./drizzle",
dialect: "postgresql",
dbCredentials: {
url,
},
});
```
### Step 5: Add Package Scripts
Add these scripts to `package.json`:
```json
{
"scripts": {
"db:generate": "drizzle-kit generate",
"db:migrate": "bun src/lib/db/migrate.ts",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio"
}
}
```
### Step 6: Initialize the Database
```bash
# Start PostgreSQL (if not already running)
docker compose up -d db
# Push the schema directly (development)
bun run db:push
# Or generate and run migrations (production workflow)
bun run db:generate
bun run db:migrate
```
## Usage
### Importing the Database Client
```typescript
import { db } from "@/lib/db";
```
> **Path convention:** The canonical import path is `@/lib/db` (not `@/db`). All downstream skills that depend on this skill should use `@/lib/db` and `@/lib/db/schema` for imports.
### Insert Records
```typescript
import { db } from "@/lib/db";
import { example } from "@/lib/db/schema";
const newRecord = await db
.insert(example)
.values({
name: "My Item",
})
.returning();
```
### Select Records
```typescript
import { db } from "@/lib/db";
import { example } from "@/lib/db/schema";
import { eq } from "drizzle-orm";
// Select all
const allRecords = await db.select().from(example);
// Select with filter
const filtered = await db
.select()
.from(example)
.where(eq(example.name, "My Item"));
// Select single record by ID
const record = await db.query.example.findFirst({
where: eq(example.id, "some-uuid"),
});
```
### Update Records
```typescript
import { db } from "@/lib/db";
import { example } from "@/lib/db/schema";
import { eq } from "drizzle-orm";
const updated = await db
.update(example)
.set({
name: "Updated Name",
updatedAt: new Date(),
})
.where(eq(example.id, "some-uuid"))
.returning();
```
### Delete Records
```typescript
import { db } from "@/lib/db";
import { example } from "@/lib/db/schema";
import { eq } from "drizzle-orm";
await db.delete(example).where(eq(example.id, "some-uuid"));
```
### Transactions
```typescript
import { db } from "@/lib/db";
import { example } from "@/lib/db/schema";
await db.transaction(async (tx) => {
const inserted = await tx
.insert(example)
.values({ name: "First" })
.returning();
await tx
.update(example)
.set({ name: "Updated" })
.where(eq(example.id, inserted[0].id));
});
```
### Relations Example
When adding related tables, define relations for the query API:
```typescript
import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
import { relations } from "drizzle-orm";
export const posts = pgTable("posts", {
id: uuid("id").primaryKey().defaultRandom(),
title: text("title").notNull(),
content: text("content"),
authorId: uuid("author_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.notNull()
.defaultNow(),
});
export const users = pgTable("users", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
createdAt: timestamRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.