db-schema

db-schema is a skill for Claude Code from zhe-qi/clhoria-template. It costs 40 tokens per session (1,096 once invoked), scanned A, original, MIT.

A set of rules for creating and changing PostgreSQL database structures with Drizzle ORM and Zod validation. A database schema defines tables, fields, relationships, indexes, and rules for stored data.

In plain words
What is it for?
Use it to define or modify tables, fields, enums, relationships, indexes, constraints, JSON data, and validated schemas in a Drizzle-based TypeScript project.
Why use it?
It keeps database changes consistent across a codebase and helps prevent naming, validation, indexing, and insertion mistakes. It also separates infrastructure tables from business data.

Skill for Claude Code

Written for Claude Code: argument-hint in frontmatter. Also seen: installed under .agents/ (shared by several agents).

Good fit Use it to define or modify tables, fields, enums, relationships, indexes, constraints, JSON data, and validated schemas in a Drizzle-based TypeScript project.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/zhe-qi/clhoria-template/db-schema
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add zhe-qi/clhoria-template --skill db-schema
Clone the repo
git clone --depth 1 https://github.com/zhe-qi/clhoria-template

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for db-schema

README.md
[![agentmods](https://agentmods.dev/badge/skills/zhe-qi/clhoria-template/db-schema/github.svg)](https://agentmods.dev/skills/zhe-qi/clhoria-template/db-schema)
Your own site
<a href="https://agentmods.dev/skills/zhe-qi/clhoria-template/db-schema"><img src="https://agentmods.dev/badge/skills/zhe-qi/clhoria-template/db-schema/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for db-schema

Your own site · 80×15
<a href="https://agentmods.dev/skills/zhe-qi/clhoria-template/db-schema"><img src="https://agentmods.dev/badge/skills/zhe-qi/clhoria-template/db-schema.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 40 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,096 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00040 $0.01096
Opus 5.5 $0.00016 $0.00438
Sonnet 5.5 $0.00008 $0.00219
Haiku 4.5 $0.00004 $0.00110

Measured 3mo ago against content hash 4f2862d1446a, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

db-schema scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/db-schema/SKILL.md · 143 lines

How it starts

The opening of the file, as written. The whole thing — 143 lines — stays where its author put it; the contents beside it link to each section on GitHub.

数据库 Schema 开发指南

技术栈

  • ORM: Drizzle ORM (postgres.js driver)
  • Schema 验证: drizzle-zod + Zod v4
  • 数据库: PostgreSQL

文件结构

src/db/schema/
├── _shard/              # 共享定义
│   ├── base-columns.ts  # 基础列(id/createdAt/updatedAt/createdBy/updatedBy)
│   ├── enums.ts         # 数据库枚举定义
│   └── types/           # 共享类型
├── _infra/              # 基础设施表(非业务表)
│   └── queue/           # 队列任务
├── admin/               # 管理端表
│   ├── system/          # 系统管理
│   └── auth/            # 认证相关
├── client/              # 客户端表
└── index.ts             # 统一导出

注意: _infra 目录使用下划线前缀,存放基础设施相关的表(如审计日志、队列任务记录等),与业务表分开管理。

核心规则

导入方式

import db from "@/db";  // 数据库实例(default export)
import { users } from "@/db/schema";  // Schema 定义

命名约定

  • TS 属性名:camelCase(自动转换为 snake_case)
  • 表名:{tier}_{feature}s(如 system_users)
  • 索引名:{表名}_{字段名}_idx
  • 主键:统一命名为 id

批量插入

// 正确:批量插入
db.insert(table).values([...items])

// 错误:循环单条插入
for (const item of items) {
  db.insert(table).values(item)  // 不要这样做
}

模板参考

数据库 Schema

参考 db-schema.md

包含:

  • 标准表定义
  • 字段类型参考
  • 约束定义语法
  • 主键设计规则
  • 索引设计原则
  • 枚举定义流程
  • Relations 定义
  • JSONB 使用规范
  • Drizzle-kit 工作流程

Zod Schema

参考 zod-schema.md

包含:

  • 标准 Schema 文件结构
  • Schema 派生规则
  • 最佳实践
  • Zod v4 注意事项

PostgreSQL 表设计最佳实践

参考 postgresql-design.md

包含:

  • 数据类型选择(避免使用的类型、推荐类型)
  • 约束设计(PK、FK、UNIQUE、CHECK、EXCLUDE)
  • 索引类型(B-tree、GIN、GiST、BRIN)
  • 分区策略(RANGE、LIST、HASH)
  • 特殊场景优化(更新密集、插入密集、Upsert)
  • 安全 Schema 演进
  • JSONB 使用指南
  • 常用扩展(pgcrypto、pg_trgm、timescaledb、postgis、pgvector)

数据库迁移指南

参考 migration.md

包含:

  • Drizzle 工作流程(push vs generate vs migrate)
  • 迁移最佳实践(小单位迁移、安全添加/删除列)
  • 生产检查清单(迁移前/中/后)
  • 回滚策略
  • 常见问题解答

开发流程

创建新表

  1. 在 src/db/schema/{tier}/{category}/ 下创建文件
  2. 定义表结构(继承 baseColumns)
  3. 创建 selectSchema 和 insertSchema
  4. 在 src/db/schema/index.ts 中导出
  5. 运行 pnpm push(开发环境)

Read the full file on GitHub · 143 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 143 lines · 40 tokens per session scan A 4f2862d1446a

Subscribe to this mod's changes

db-schema is a skill published in the GitHub repository zhe-qi/clhoria-template (193 stars, last pushed 2d ago), licensed MIT. It adds 40 tokens to every session and 1,096 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

db-schema compared with skills from other repositories

db-schema next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
db-schemazhe-qi/clhoria-templateSkill1932d agoMITA40Claude Code
alloydb-basicsgoogle/skillsSkill25ktodayApache-2.0A72Claude Code, Codex
postgresql-table-designwshobson/agentsSkill43k6d agoMITA37Claude Code
db-repairgarrytan/gbrainSkill34ktodayMITA96Claude Code
volcengine-rds-postgresqlbytedance/agentkit-samplesSkill4965d agoApache-2.0A63Claude Code, Codex
postgresdbericrisco/rsc-harnessSkill6825d agoMITA91Claude Code, Codex
analyzing-insights-across-teamsPostHog/posthog-fossSkill733todayMITA115Claude Code, Codex