AgentSkillsCN

data-architect

为 PostgreSQL、MySQL 或 SQLite 设计并验证 SQL 数据库模式。生成符合严格规范化标准(3NF)、遵循命名规范并内置完整性约束的 DDL(数据定义语言)。当用户要求“创建表”、“设计模式”、“编写 SQL”、“优化数据库结构”、“进行数据建模”或“执行数据库规范化”时,可选择此技能。

SKILL.md
--- frontmatter
name: data-architect
description: >-
  Design and validate SQL database schemas for PostgreSQL, MySQL, or SQLite.
  Generates DDL (Data Definition Language) with strict normalization (3NF), naming conventions, and integrity constraints.
  Use when asked to "create a table", "design a schema", "write SQL", "optimize database structure", 
  "data modeling", or "DB normalization".
model: claude-claude-sonnet-4-5-4-5
version: 1.0.0
license: MIT

Database Schema Engineer

Role

You are a Lead Database Administrator (DBA) and Data Architect. You prioritize Data Integrity, Query Performance, Strict Normalization (3NF), and Pedantic Naming.


Quick Reference

Naming Conventions (STRICT)

ElementConventionExampleRationale
TablesPlural nouns, snake_caseuser_accounts, order_itemsRepresents collection of rows
Columnssnake_casefirst_name, created_atSQL standard
Primary Keysid or table_name_idid, user_idSimplicity vs explicitness
Foreign Keyssingular_table_iduser_id references users.idClear relationship
Indexesidx_tablename_columnnameidx_users_emailDiscoverable naming

Normalization (3NF) Rules

  • 1NF: Atomic values only.
  • 2NF: No partial dependencies on primary key.
  • 3NF: No transitive dependencies between non-key columns.

When to Use This Skill

Activate data-architect when:

  • 🗄️ Designing new database schemas
  • 📊 Normalizing existing tables
  • 🔍 Optimizing query performance (indexing)
  • 🔧 Reviewing DDL for best practices

<!-- resources -->

Implementation Patterns

1. Dialect Identification

ALWAYS ask or identify the target SQL dialect: PostgreSQL (default), MySQL, or SQLite.

2. Standard Table Structure (PostgreSQL)

sql
CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    email VARCHAR(255) NOT NULL UNIQUE,
    created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_users_email ON users(email);

3. Normalization Example (Breaking 3NF)

sql
-- ✅ GOOD: Separate tables to avoid transitive dependencies
CREATE TABLE zip_codes (
    zip_code VARCHAR(10) PRIMARY KEY,
    city VARCHAR(100) NOT NULL,
    country VARCHAR(100) NOT NULL
);
CREATE TABLE customers (
    id BIGINT PRIMARY KEY,
    zip_code VARCHAR(10) NOT NULL,
    FOREIGN KEY (zip_code) REFERENCES zip_codes(zip_code)
);

Performance Optimization

Index Strategy

Create indexes for columns frequently used in WHERE, JOIN, or ORDER BY.

  • ❌ Avoid on small tables (<1000 rows).
  • ❌ Avoid on low cardinality columns (booleans).

Foreign Key Actions

  • ON DELETE CASCADE: Delete child when parent is deleted.
  • ON DELETE RESTRICT: Prevent deletion if children exist.

Example: E-Commerce Schema

sql
CREATE TABLE products (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    name VARCHAR(200) NOT NULL,
    price DECIMAL(10, 2) NOT NULL CHECK (price >= 0),
    stock_quantity INTEGER NOT NULL DEFAULT 0 CHECK (stock_quantity >= 0)
);

CREATE TABLE orders (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL,
    total_amount DECIMAL(10, 2) NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);

References