raheesahmed/sajicode/database

Claude Code and agent skill by raheesahmed/sajicode

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Design and implement production database systems. Covers schema design, migrations, query optimization, ORMs (Prisma, Drizzle, TypeORM), PostgreSQL/SQLite/MongoDB patterns, indexing strategies, connection pooling, and multi-tenant architectures. Use when designing schemas, writing queries, or setting up data access layers.

Install

npx vskill@latest install raheesahmed/sajicode/database

SKILL.md

Database Engineering

Schema Design Principles

Naming Conventions
  • Table names: singular PascalCase (User, OrderItem)
  • Column names: camelCase (createdAt, userId)
  • Foreign keys: {referencedTable}Id (userId, orderId)
  • Indexes: idx_{table}_{column} (idx_user_email)
  • Unique constraints: uq_{table}_{column} (uq_user_email)
Required Columns (every table)
sql
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
ID Strategy
TypeUse When
UUID v4Public-facing IDs, distributed systems
CUID2URL-safe, sortable, no collision
Auto-incrementInternal-only, sequential ordering needed
ULIDSortable UUID alternative

Prisma Patterns

Schema with Relations
prisma
model User {
id String @id @default(cuid())
email String @unique
name String
role Role @default(USER)
posts Post[]
profile Profile?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([email])
@@index([createdAt])
}
model Post {
id String @id @default(cuid())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
authorId String
tags Tag[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([authorId])
@@index([published, createdAt])
}
Optimized Queries
ts
// Pagination with cursor (much faster than offset)
const posts = await prisma.post.findMany({
take: 20,
skip: 1,
cursor: { id: lastPostId },
orderBy: { createdAt: "desc" },
select: { id: true, title: true, createdAt: true, author: { select: { name: true } } },
});
// Transaction for multi-table writes
const [user, team] = await prisma.$transaction([
prisma.user.create({ data: userData }),
prisma.team.update({ where: { id: teamId }, data: { memberCount: { increment: 1 } } }),
]);
// Upsert pattern
await prisma.user.upsert({
where: { email },
update: { name, updatedAt: new Date() },
create: { email, name },
});

Drizzle ORM Patterns

Schema Definition
ts
import { pgTable, text, timestamp, boolean, uuid, index } from "drizzle-orm/pg-core";
export const users = pgTable("user", {
id: uuid("id").defaultRandom().primaryKey(),
email: text("email").notNull().unique(),
name: text("name").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
}, (table) => ({
emailIdx: index("idx_user_email").on(table.email),
}));

Migration Workflow

1. Design schema changes
2. Generate: npx prisma migrate dev --name descriptive_name
3. Review generated SQL — NEVER skip this
4. Test with staging data
5. Deploy: npx prisma migrate deploy
6. NEVER edit committed migrations — create a new one

Query Optimization

Index Strategy
sql
-- Composite index for multi-column WHERE clauses (order matters!)
CREATE INDEX idx_post_status_date ON post(published, created_at DESC);
-- Partial index for filtered queries
CREATE INDEX idx_active_users ON "user"(email) WHERE active = true;
-- Covering index (includes all queried columns)
CREATE INDEX idx_post_listing ON post(author_id, created_at DESC) INCLUDE (title);
N+1 Prevention
ts
// BAD: N+1 queries
const users = await prisma.user.findMany();
for (const user of users) {
const posts = await prisma.post.findMany({ where: { authorId: user.id } });
}
// GOOD: Eager loading
const users = await prisma.user.findMany({
include: { posts: { take: 5, orderBy: { createdAt: "desc" } } },
});

Connection Pooling

ts
// Use connection pooling in production
const prisma = new PrismaClient({
datasources: { db: { url: process.env.DATABASE_URL } },
log: process.env.NODE_ENV === "development" ? ["query", "warn", "error"] : ["error"],
});
// Graceful shutdown
process.on("beforeExit", async () => { await prisma.$disconnect(); });

Security Rules

  • ALWAYS use parameterized queries — NEVER string concatenation
  • NEVER expose internal IDs in URLs — use UUIDs
  • Encrypt sensitive fields at rest (passwords, tokens, PII)
  • Use row-level security for multi-tenant data
  • Audit log all destructive operations (DELETE, UPDATE on sensitive tables)
  • Validate all input with Zod BEFORE database operations

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Refreshed 18 Mar 2026, 7 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
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/raheesahmed/sajicode/database/badge)](https://verified-skill.com/skills/raheesahmed/sajicode/database)

Something wrong with this skill or its page? Tell us.