Agent skill

DB Schema

by zhe-qi in zhe-qi/clhoria-template

创建或修改数据库 Schema。当需要创建新表、修改表结构、定义字段、设置索引约束、或涉及 Drizzle ORM / drizzle-zod 操作时使用

MITAuto-check passedDatabases

Install DB Schema

skills CLI
$ npx skills add zhe-qi/clhoria-template --skill db-schema -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install zhe-qi/clhoria-template db-schema --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/zhe-qi/clhoria-template.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/db-schema .claude/skills/db-schema && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
db-schema
GitHub stars
193
Token cost
~620 tokens
SKILL.md length
140 words
Files
3
Skills in repo
10
Repo updated
First seen
Licence
MIT

At a glance

创建或修改数据库 Schema。当需要创建新表、修改表结构、定义字段、设置索引约束、或涉及 Drizzle ORM / drizzle-zod 操作时使用

  • Works in 5 steps: 在 src/db/schema/{tier}/{category}/ 下创建文件 → 定义表结构(继承 baseColumns) → 创建 selectSchema 和 insertSchema → …
  • Tasks that involve ORMs and data access
  • SKILL.md covers 技术栈, 文件结构, 核心规则 and 模板参考, plus 2 more sections
  • Calls pnpm

What it does

DB Schema is an agent skill from zhe-qi/clhoria-template. 创建或修改数据库 Schema。当需要创建新表、修改表结构、定义字段、设置索引约束、或涉及 Drizzle ORM / drizzle-zod 操作时使用

Its SKILL.md is about 620 tokens, which your agent loads only when the skill is triggered. The skill folder holds 3 other files (for example `templates/migration.md` and `templates/postgresql-design.md`).

It sits in Databases, covering ORMs and data access and Forms and validation. It works with Zod, Drizzle ORM and PostgreSQL. The repository describes itself as: Production-ready Hono backend template that doubles as an AI agent harness — providing feedforward guides, feedback sensors, and progressive specialization to make AI coding… The licence is MIT.

When your agent uses it

  • Tasks that involve ORMs and data access
  • Tasks that involve Forms and validation

Example prompts

  • “/db-schema”

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

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

What it can do on your machine

Read from SKILL.md and the folder at commit 589f13e. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • pnpm

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pnpm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

DB Schema loads about 620 tokens when it runs. Until then it costs about 22 tokens; SKILL.md has 140 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~22
When it runs · the whole SKILL.md, loaded when a task matches
~620

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from zhe-qi/clhoria-template at commit 589f13e, republished under its MIT licence (© zhe-qi). 140 words, ~620 tokens.

Download SKILL.mdSave it as .claude/skills/db-schema/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
db-schema
description
创建或修改数据库 Schema。当需要创建新表、修改表结构、定义字段、设置索引约束、或涉及 Drizzle ORM / drizzle-zod 操作时使用
argument-hint
[tier/category/feature-name]

数据库 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 目录使用下划线前缀,存放基础设施相关的表(如审计日志、队列任务记录等),与业务表分开管理。

核心规则

导入方式
typescript
import db from "@/db";  // 数据库实例(default export)
import { users } from "@/db/schema";  // Schema 定义
命名约定
  • TS 属性名:camelCase(自动转换为 snake_case)
  • 表名:{tier}_{feature}s(如 system_users)
  • 索引名:{表名}_{字段名}_idx
  • 主键:统一命名为 id
批量插入
typescript
// 正确:批量插入
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(开发环境)
修改现有表
  1. 修改 schema 文件中的表定义
  2. 运行 pnpm push(开发环境)
  3. 如果需要迁移数据,编写迁移脚本
生产部署
bash
pnpm generate  # 生成迁移文件
pnpm migrate   # 执行迁移

重要提醒

  • 不要修改已执行的迁移文件和 meta/ 文件夹;未执行的迁移文件可以修改或删除后重新生成
  • 使用枚举时确保 TS 枚举和 DB 枚举保持同步
  • 外键选择:物理外键(需级联)vs 逻辑外键(应用层维护)
  • 索引设计:不确定时先询问,避免过度设计

© zhe-qi, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files in .agents/skills/db-schema of zhe-qi/clhoria-template.

  • SKILL.md
  • templates/migration.md
  • templates/postgresql-design.md

Open the folder on GitHubat commit 589f13e

Compare with similar skills

DB Schema next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

DB Schema compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
DB Schema this skillzhe-qi/clhoria-template193—~620Automated safety check: PassMIT
Better Drizzlealmeidazs/better-drizzle348—~1.7kAutomated safety check: PassApache-2.0
Nestjs Drizzle Crud Generatorgiuseppe-trisciuoglio/developer-kit356—~1.3kAutomated safety check: NotesMIT
Drizzle Sqlite Scaffoldpproenca/dot-skills215—~4kAutomated safety check: PassMIT
Safe SQL Executionsupabase/supabase111k—~4.2kAutomated safety check: PassApache-2.0
Drizzle DatabaseChatbotXIO/ChatbotX881—~2.1kAutomated safety check: PassCustom licence

Similar skills

  • Better Drizzle

    almeidazs/better-drizzle

    Write, review, and debug code that uses better-drizzle, the typed repository layer over Drizzle ORM 1.x (better(db), client.users.findMany, paginate, cursor, upsertMany, relation include/connect…

    348 GitHub stars~1.7k tokensUpdated yesterday
    DatabasesAuto-check passed
  • Nestjs Drizzle Crud Generator

    giuseppe-trisciuoglio/developer-kit

    Generates complete CRUD modules for NestJS applications with Drizzle ORM.

    356 GitHub stars~1.3k tokensUpdated 29 days ago
    DatabasesAuto-check: notes
  • Drizzle Sqlite Scaffold

    pproenca/dot-skills

    Scaffolds Drizzle ORM + SQLite boilerplate — a new drizzle.config.ts, a singleton client with the right pragmas, per-table schema files with explicit primary keys/indexed foreign…

    215 GitHub stars~4k tokensUpdated 1 mo ago
    DatabasesAuto-check passed
  • Safe SQL Execution

    supabase/supabase

    Official

    A skill your agent uses whenever code will build, return, fetch, or execute SQL that runs against a user's real Postgres database — even when the request reads like an ordinary feature or bug fix…

    111k GitHub stars~4.2k tokensUpdated today
    DatabasesAuto-check passed
  • Drizzle Database

    ChatbotXIO/ChatbotX

    Work with Drizzle ORM database schema, migrations, relations, and queries in PostgreSQL.

    881 GitHub stars~2.1k tokensUpdated today
    DatabasesAuto-check passed
  • Style guide for Drizzle ORM schemas and queries in LobeHub: file layout, naming, timestamp helpers, primary keys, indexes, relations and inferred types.

    83k GitHub stars~4.1k tokensUpdated today
    DatabasesAuto-check passed

More from zhe-qi/clhoria-template

All 10 skills in this repo
  • Effect V4

    zhe-qi/clhoria-template

    Effect v4 模式指南。当需要创建 Effect 服务、定义错误类型、编写 Effect 程序、管理 Layer 组合、或使用 Effect 封装异步操作时使用

    193 GitHub stars~887 tokensUpdated 2 mo ago
    Auto-check passed
  • Bullmq

    zhe-qi/clhoria-template

    创建或修改 BullMQ 队列任务。当需要创建新队列、添加任务类型、注册 Worker、设置定时任务、或用户请求"添加后台任务/队列处理"时使用

    193 GitHub stars~1.6k tokensUpdated 2 mo ago
    Auto-check passed
  • Create Tier

    zhe-qi/clhoria-template

    创建或修改一个新的 API tier。当用户请求“新增 tier / 创建 partner tier / 新增 merchant 端 / 新增 tenant 端 / 新增 API 端 / 新增一套路由层”时使用。目标是在不修改框架核心的前提下,为新 tier 补齐配置、中间件、类型别名、路由入口和测试。

    193 GitHub stars~1.7k tokensUpdated 2 mo ago
    Auto-check: notes
  • Crud

    zhe-qi/clhoria-template

    创建或修改 CRUD 模块。当需要创建新的增删改查 API、修改现有路由模块、添加新字段、新增接口、或用户请求"创建/修改 XX 管理"时使用

    193 GitHub stars~552 tokensUpdated 2 mo ago
    Auto-check passed
  • Drizzle V1

    zhe-qi/clhoria-template

    Drizzle ORM v1 关系查询指南。当需要定义 Relations v2、编写关系查询、使用 through 多对多、预定义过滤器、或从旧版 Drizzle 迁移时使用

    193 GitHub stars~3k tokensUpdated 2 mo ago
    Auto-check passed
  • Source Command Opsx Explore

    zhe-qi/clhoria-template

    Enter explore mode - think through ideas, investigate problems, clarify requirements

    193 GitHub stars~1.6k tokensUpdated 2 mo ago
    Auto-check passed

Categories

Questions about DB Schema

What does DB Schema do?

创建或修改数据库 Schema。当需要创建新表、修改表结构、定义字段、设置索引约束、或涉及 Drizzle ORM / drizzle-zod 操作时使用. DB Schema is an agent skill from zhe-qi/clhoria-template.

When should I use DB Schema?

DB Schema fits situations like: tasks that involve ORMs and data access; tasks that involve Forms and validation.

How do I install DB Schema in Claude Code?

Run `npx skills add zhe-qi/clhoria-template --skill db-schema -a claude-code`. Or copy the skill folder (.agents/skills/db-schema in zhe-qi/clhoria-template) into .claude/skills/db-schema in your project. Claude Code loads it when a task matches its description.

How do I install DB Schema in Codex?

Run `npx skills add zhe-qi/clhoria-template --skill db-schema -a codex`. Or copy the skill folder (.agents/skills/db-schema in zhe-qi/clhoria-template) into .agents/skills/db-schema in your project. Codex loads it when a task matches its description.

Can I use DB Schema in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add zhe-qi/clhoria-template --skill db-schema -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/db-schema, .gemini/skills/db-schema, .github/skills/db-schema and .opencode/skills/db-schema in your project.

What does DB Schema need to run?

Going by SKILL.md and its folder, DB Schema needs the command-line tools its instructions call (pnpm).

Does DB Schema access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is DB Schema safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does DB Schema use?

DB Schema is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does DB Schema use?

About 620 tokens (SKILL.md is roughly 2.5k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to DB Schema?

Skills that share tags, products or a category with DB Schema: Better Drizzle (almeidazs/better-drizzle, 348 stars), Nestjs Drizzle Crud Generator (giuseppe-trisciuoglio/developer-kit, 356 stars), Drizzle Sqlite Scaffold (pproenca/dot-skills, 215 stars) and Safe SQL Execution (supabase/supabase, 111k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains DB Schema?

zhe-qi (a GitHub user) maintains it in zhe-qi/clhoria-template, which has 193 GitHub stars. The repository holds 10 skills in this directory. The repository was last updated on July 30, 2026.

Source: zhe-qi/clhoria-template on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.