agentleFS
roedyrustamroedyrustam/vibes-plug/skills/database-orm-expert/SKILL.md

database-orm-expert

Skill75 starsChanged 38 days agoMITView on GitHub

Updated to be the unified database skill covering ORM, migrations, edge DBs, and Supabase CLI / Keahlian database terpadu untuk ORM, migrasi, edge DB, dan Supabase CLI.

  • Reads credentials

The file

Show its rules and text

We split this skill into the rules it gives an agent

16 rules. About 0 are common, 8 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Recommendation: Use Drizzle ORM for edge-compatible apps and performance-critical systems.

    line 48
  2. Very specific:

    Use $transaction for atomic operations.

    line 51
  3. Very specific:

    Avoid N+1 queries by using select and include (with Prisma 5.7+ relationJoins preview) rather than looping over findMany.

    line 52
  4. Very specific:

    Use drizzle-kit generate for generating SQL and drizzle-kit migrate for deployment.

    line 55
  5. Distinctive:

    Connection Pooling: Use PgBouncer, Supabase's built-in pooler, or Prisma Accelerate for standard TCP to avoid exhausting connection limits.

    line 63
  6. Distinctive:

    Never make breaking changes in a single deployment.

    line 70
  7. Distinctive:

    Phase 1 (Expand): Add the new schema element (column, table) without removing the old one.

    line 71
  8. Distinctive:

    Phase 2 (Migrate): Update app to write to *both* and read from the new element (with fallback).

    line 72
  9. Distinctive:

    Phase 3 (Backfill): Run background script to backfill data to new element.

    line 73
  10. Distinctive:

    Phase 4 (Contract): Remove old application code.

    line 74
  11. Very specific:

    Write idempotent scripts (CREATE TABLE IF NOT EXISTS).

    line 83
  12. Very specific:

    HTTP/WebSocket Proxy Pooling: Use neon-http or similar when querying databases from Edge Workers/Functions.

    line 93
  13. Very specific:

    Check Environment: Ensure supabase/migrations directory exists.

    line 112
  14. Very specific:

    Write SQL script locally: npx supabase migration new [name] -> writes to supabase/migrations/<timestamp>_[name].sql.

    line 117
  15. Very specific:

    Test locally: npx supabase migration up or npx supabase db reset.

    line 118
  16. Distinctive:

    Final Step: If using RLS, explicitly add policies to new tables.

    line 120

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

Unified Database & ORM Expert

English | Bahasa Indonesia


<a name="english"></a>

English

Description

Design schemas, select ORMs, execute zero-downtime migrations, optimize queries, and implement edge serverless databases. Covers Prisma 6, Drizzle ORM, TypeORM, Supabase CLI workflows, and Edge DBs (Neon, Cloudflare D1, Turso, Upstash).

Trigger Conditions

  • Designing or migrating a production schema (blue-green, canary).
  • Choosing between Prisma, Drizzle ORM, or TypeORM.
  • Writing complex queries with joins, aggregations, or pagination.
  • Optimizing slow queries or N+1 problems.
  • Building edge-compatible serverless database connections.
  • Executing Supabase migrations and RLS patterns.
  • Managing backward-compatible massive data backfills.

Orchestration & Integration

  • js-backend-expert: For Node/Bun/Deno backend implementations integrating these ORMs.
  • ci-cd-devops-architect: For automated migration deployment steps.
  • supabase-security-expert: For Supabase RLS and security.
  • cloud-hosting-expert: For infrastructure integration.

Core ORM & Query Strategies

ORM Selection Guide

CriteriaPrisma 6Drizzle ORMTypeORM
Type SafetySchema-generated typesSQL-like, inferred typesDecorator-based
Bundle SizeHeavy (binary client)Lightweight (<35KB)Medium
Query StyleFluent ORM APISQL-first, composableActiveRecord / QueryBuilder
Edge RuntimePrisma Accelerate neededNative edge supportNo
Migrationsprisma migrate devdrizzle-kit push/migratesynchronize (dev only)

Recommendation: Use Drizzle ORM for edge-compatible apps and performance-critical systems. Use Prisma 6 for teams preferring a schema-first DX.

Prisma 6 Best Practices

  • Use $transaction for atomic operations.
  • Avoid N+1 queries by using select and include (with Prisma 5.7+ relationJoins preview) rather than looping over findMany.

Drizzle ORM Best Practices

  • Use drizzle-kit generate for generating SQL and drizzle-kit migrate for deployment.
  • Utilize native edge support and type-safe query builders with drizzle-orm.

Query Optimization Principles

  1. Always index foreign keys and columns used in WHERE, ORDER BY, and JOIN.
  2. Use EXPLAIN ANALYZE to detect sequential scans.
  3. Cursor-based pagination over offset for large datasets.
  4. Avoid SELECT *. Batch inserts where possible.
  5. Connection Pooling: Use PgBouncer, Supabase's built-in pooler, or Prisma Accelerate for standard TCP to avoid exhausting connection limits. Alternatively, use HTTP/WebSocket drivers for edge queries.

Zero-Downtime Migrations & Versioning

1. Zero-Downtime Migration Pattern (Expand and Contract)

Never make breaking changes in a single deployment.

  • Phase 1 (Expand): Add the new schema element (column, table) without removing the old one.
  • Phase 2 (Migrate): Update app to write to both and read from the new element (with fallback).
  • Phase 3 (Backfill): Run background script to backfill data to new element.
  • Phase 4 (Contract): Remove old application code.
  • Phase 5 (Cleanup): Drop old schema element in next deployment.

2. Backward Compatibility Rules

  • Never DROP or RENAME a column/table in active use.
  • Add DEFAULT values to new NOT NULL columns.

3. Migration Mechanics & Safe Data Backfilling

  • Never run prisma db push or synchronize: true in production. Always use immutable version-controlled scripts (e.g., 20260814_add_user_status.sql).
  • Write idempotent scripts (CREATE TABLE IF NOT EXISTS).
  • Chunking: For large tables, perform updates in batches (using LIMIT and sleep intervals) to prevent table locking. Use background jobs (BullMQ/Inngest).

Edge & Serverless Drivers

Exploit serverless DBs for ultra-low latency:

  • Neon & Cloudflare D1: Serverless autoscaling Postgres with instant branching; Distributed edge SQLite.
  • Embedded Replicas: Sync edge SQLite read-replicas with central cloud DBs.
  • HTTP/WebSocket Proxy Pooling: Use neon-http or similar when querying databases from Edge Workers/Functions.
  • Upstash Redis Edge Caching:
import { Redis } from '@upstash/redis';
const redis = new Redis({ url: process.env.UPSTASH_REDIS_REST_URL!, token: process.env.UPSTASH_REDIS_REST_TOKEN! });
export async function getCachedData(key: string) {
  let data = await redis.get(key);
  if (!data) {
    data = await fetchFromDB();
    await redis.set(key, data, { ex: 3600 });
  }
  return data;
}

Supabase CLI & MCP Workflow

  1. Check Environment: Ensure supabase/migrations directory exists.
  2. Review Available MCP Commands:
    • List existing migrations: mcp_supabase-mcp-server_list_migrations with project_id.
    • Confirm SQL before executing via server directly.
  3. Execute Command:
    • Write SQL script locally: npx supabase migration new [name] -> writes to supabase/migrations/<timestamp>_[name].sql.
    • Test locally: npx supabase migration up or npx supabase db reset.
    • Apply remote: npx supabase db push (or use remote MCP apply_migration).
  4. Final Step: If using RLS, explicitly add policies to new tables. Confirm completion with user.

<a name="bahasa-indonesia"></a>

Bahasa Indonesia

Deskripsi

Rancang skema, pilih ORM, eksekusi migrasi tanpa downtime, optimalkan query, dan implementasikan edge serverless DB. Mencakup Prisma 6, Drizzle, TypeORM, Supabase CLI, dan Edge DBs (Neon, Cloudflare D1, Turso, Upstash).

Kondisi Pemicu

  • Merancang atau memigrasikan skema produksi (blue-green, canary).
  • Memilih antara Prisma, Drizzle, atau TypeORM.
  • Mengoptimalkan query lambat atau masalah N+1.
  • Membuat koneksi serverless kompatibel dengan edge.
  • Mengeksekusi migrasi Supabase dan pola RLS.
  • Mengelola backfill data besar secara backward-compatible.

Integrasi Orkestrasi

  • js-backend-expert: Untuk implementasi Node/Bun/Deno.
  • ci-cd-devops-architect: Untuk otomatisasi langkah deployment migrasi.
  • supabase-security-expert: Untuk RLS dan keamanan Supabase.
  • cloud-hosting-expert: Untuk integrasi infrastruktur.

Strategi Inti ORM & Query

  • Drizzle ORM direkomendasikan untuk aplikasi edge, Prisma 6 untuk DX schema-first.
  • Gunakan $transaction dan batasi SELECT *.
  • Selalu indeks foreign key dan gunakan pagination berbasis cursor (Cursor-based pagination).
  • Connection Pooling: Gunakan pooler bawaan Supabase, PgBouncer, Prisma Accelerate, atau driver HTTP (seperti neon-http) untuk request edge.

Migrasi Tanpa Downtime & Versioning

  • Pola Expand and Contract: Jangan pernah melakukan breaking change dalam satu rilis. Tambah kolom baru, update kode untuk memakai keduanya, backfill data, hapus kode lama, lalu drop kolom lama.
  • Jangan gunakan DROP atau RENAME pada kolom aktif. Kolom NOT NULL baru harus memiliki nilai DEFAULT.
  • Jangan jalankan prisma db push atau synchronize: true di produksi. Gunakan skrip migrasi bertahap (idempoten).
  • Backfill Aman: Gunakan pemrosesan batch/chunking dengan background job untuk tabel raksasa agar tidak menyebabkan table lock.

Driver Edge & Serverless

  • Manfaatkan Neon Serverless Postgres, Cloudflare D1, Turso, atau Upstash Redis (caching).
  • Gunakan driver berbasis HTTP/WebSocket di lingkungan Edge Workers untuk mencegah habisnya batas koneksi TCP.

Alur Kerja Supabase CLI & MCP

  1. Pastikan folder supabase/migrations ada.
  2. Periksa migrasi dengan mcp_supabase-mcp-server_list_migrations.
  3. Buat file migrasi lokal dengan npx supabase migration new [nama].
  4. Uji lokal dengan npx supabase migration up.
  5. Deploy remote dengan npx supabase db push atau melalui MCP.
  6. Tambahkan kebijakan RLS jika diperlukan. Konfirmasikan sukses ke pengguna.

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.