Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

designing-database-schemas设计数据库模式

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

659

周安装

28

GitHub Stars

2,062

下载量

231
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:designing-database-schemas(设计数据库模式)
来源仓库:https://github.com/jeremylongshore/claude-code-plugins-plus-skills
仓库路径:skills/designing-database-schemas
安装命令:
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill designing-database-schemas
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill designing-database-schemas

简介

该技能根据业务需求或现有代码生成规范化数据库 schema,支持 PostgreSQL 与 MySQL。

  • 输出包含数据类型、约束、索引与关系定义的 DDL,默认遵循第三范式原则。
  • 适用于表结构设计、查询优化与迁移脚本生成,需明确目标数据库引擎与版本。
  • 涉及数据变更时应优先 dry-run 或备份,避免误删误改,建议事务保护关键操作。
  • designing-database-schemas 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Database Schema Designer

Overview

Design normalized relational database schemas from business requirements, entity-relationship diagrams, or existing application code. This skill produces PostgreSQL or MySQL DDL with proper data types, constraints, indexes, and relationships following normalization principles (3NF by default) with strategic denormalization where performance requires it.

Prerequisites

  • Business domain requirements or existing application models/classes to derive schema from
  • psql or mysql CLI for testing schema DDL
  • Target database engine and version (determines available data types and features)
  • Expected data volumes and query patterns for sizing and index decisions
  • Multi-tenancy requirements (shared schema, schema-per-tenant, or database-per-tenant)

Instructions

  1. Identify all entities (nouns) from the business requirements. Each entity becomes a table. List every attribute (property) of each entity and classify as required or optional.
  2. Define primary keys for each table. Prefer BIGSERIAL (PostgreSQL) or BIGINT AUTO_INCREMENT (MySQL) for surrogate keys. Use UUID (via gen_random_uuid()) for distributed systems or when IDs are exposed in URLs. Natural keys are acceptable when truly immutable and unique (ISO country codes, IATA airport codes).
  3. Normalize the schema to Third Normal Form (3NF):

- 1NF: Eliminate repeating groups. Each column holds a single atomic value. No arrays in columns (unless using PostgreSQL array types intentionally). - 2NF: Remove partial dependencies. Every non-key column depends on the entire primary key. - 3NF: Remove transitive dependencies. Non-key columns depend only on the primary key, not on other non-key columns. Extract lookup tables for values that change independently.

  1. Define relationships between tables:

- One-to-many: Add a foreign key column on the "many" side referencing the "one" side. Example: orders.customer_id REFERENCES customers(id). - Many-to-many: Create a junction table with two foreign keys. Example: product_categories(product_id, category_id) with a composite primary key. - One-to-one: Add a foreign key with a UNIQUE constraint, or merge into a single table if entities are always accessed together.

  1. Choose appropriate data types with precision:

- Money: NUMERIC(12,2) or INTEGER storing cents (never FLOAT/DOUBLE) - Timestamps: TIMESTAMPTZ (PostgreSQL) with time zone for events; DATE for calendar dates - Status fields: VARCHAR(20) with CHECK constraint, or create an ENUM type - Email: CITEXT (PostgreSQL) or VARCHAR(254) with CHECK constraint for format validation - JSON: JSONB (PostgreSQL) for flexible schema attributes; avoid for core relational data

  1. Add standard columns to every table:

- created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() - updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() (with trigger for auto-update) - deleted_at TIMESTAMPTZ for soft delete (add partial index WHERE deleted_at IS NULL)

  1. Define constraints: NOT NULL on required fields, UNIQUE on natural keys and email addresses, CHECK constraints for value validation (CHECK (price >= 0), CHECK (status IN ('active', 'inactive'))), and foreign keys with appropriate ON DELETE behavior (CASCADE, SET NULL, or RESTRICT).
  2. Design indexes based on expected query patterns:

- Primary key index is automatic - Foreign key columns: always index these for JOIN performance - Columns in WHERE clauses with high selectivity: B-tree index - Full-text search columns: GIN index on tsvector - Composite indexes: match the most common multi-column filter patterns, leftmost column first

  1. Apply strategic denormalization where 3NF causes unacceptable query complexity:

- Materialized views for expensive aggregate queries - Denormalized counter columns (with trigger-based updates) for counts displayed on every page load - JSON columns for flexible metadata that varies by record type

  1. Generate the complete DDL script with CREATE TABLE statements in dependency order (referenced tables first), followed by indexes, triggers, and any seed data for lookup tables.

Output

  • Complete DDL script with CREATE TABLE, constraints, indexes, and triggers in executable order
  • Entity-relationship description listing all tables, columns, types, and relationships
  • Index strategy document explaining which indexes support which query patterns
  • Seed data scripts for lookup/reference tables (countries, statuses, categories)
  • Migration file compatible with the project's migration framework

Error Handling

ErrorCauseSolution
Circular foreign key dependencyTables reference each other, preventing creation in any orderUse ALTER TABLE ADD CONSTRAINT after both tables are created; or redesign to eliminate the cycle with a junction table
Over-normalization causing excessive JOINsEvery lookup value in its own table, queries require 8+ JOINsDenormalize low-cardinality, rarely-changing lookup values; use ENUM types for status fields instead of separate tables
NUMERIC precision overflowMonetary values exceed NUMERIC(10,2) maximumIncrease precision to NUMERIC(15,2) or NUMERIC(19,4) for currencies requiring sub-cent precision
Schema too rigid for evolving requirementsFrequent ALTER TABLE needed as business rules changeUse JSONB columns for flexible attributes; implement the EAV (Entity-Attribute-Value) pattern for truly dynamic schemas; plan for schema evolution from the start
Missing index on foreign key columnJOINs on foreign key columns cause sequential scansAlways create indexes on foreign key columns; PostgreSQL does not auto-index foreign keys (unlike MySQL InnoDB)

Examples

E-commerce schema design: Tables: customers, addresses (one-to-many from customers), products, categories (many-to-many via product_categories), orders, order_items (one-to-many from orders), payments. Money stored as NUMERIC(12,2). Soft delete on customers and products. GIN index on products.search_vector for full-text search. Composite index (customer_id, created_at DESC) on orders for order history pages.

Multi-tenant SaaS schema with row-level security: Every table includes tenant_id BIGINT NOT NULL with a foreign key to tenants. Row-level security policies enforce tenant isolation: CREATE POLICY tenant_isolation ON orders USING (tenant_id = current_setting('app.tenant_id')::bigint). Composite indexes start with tenant_id for partition-like query performance.

Event sourcing schema: An events table with (aggregate_id, sequence_number) as composite primary key, event_type VARCHAR(100), payload JSONB, created_at TIMESTAMPTZ. A snapshots table stores materialized state at periodic intervals. Append-only design with no UPDATE or DELETE operations.

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.16%
按下载量换算79

Claude

31.06%
按下载量换算72

Cursor

17.91%
按下载量换算41

Gemini CLI

9.08%
按下载量换算21

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills