← 返回列表
全部 Skill›数据与AI Data & AI›db-schema-validator

db-schema-validator

作者 @findsun-vn · 语言 en
Validate and enforce production-grade MySQL schema quality for module-based backend architecture.
数据与AI Data & AI数据工程通用待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
0
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Skill: db-schema-validator

Purpose

Validate and enforce a database schema that is:

  • MySQL-compatible
  • production-ready
  • aligned with OpenAPI
  • aligned with planner business rules
  • safe for module-based backend generation

Required Table Structure

Every business table must include:

  • id BIGINT PRIMARY KEY AUTO_INCREMENT
  • created_at DATETIME NOT NULL
  • updated_at DATETIME NOT NULL
  • deleted_at DATETIME NULL

These are mandatory unless there is a clearly approved exception.


Naming Rules

Tables

  • snake_case only
  • plural preferred where appropriate

Columns

  • snake_case only

Forbidden:

  • camelCase in DB
  • mixed naming styles

Primary Key Rules

Every business table must:

  • have a primary key
  • use BIGINT for primary IDs
  • use AUTO_INCREMENT unless another strategy is explicitly justified

Forbidden:

  • missing PK
  • text-based primary keys by accident
  • inconsistent ID strategy without reason

Foreign Key Rules

All real relationships must be explicit.

Requirements:

  • define FK constraints
  • reference the correct parent table
  • index all FK columns

For many-to-many:

  • use join tables
  • index both FK sides

Forbidden:

  • implied-only relationships
  • missing FK on real ownership relations
  • FK without index

Index Rules

Must include:

  • index on FK columns
  • UNIQUE index on truly unique fields
  • search/filter indexes when implied by list/search APIs
  • optional composite indexes for common list/filter patterns

Common examples:

  • email
  • code
  • slug
  • (status, created_at)
  • (user_id, created_at)

Data Type Rules

Use clear, appropriate types:

  • id -> BIGINT
  • normal string -> VARCHAR(255)
  • long text -> TEXT
  • status -> VARCHAR(50)
  • money/price -> DECIMAL(10,2)
  • datetime -> DATETIME

Forbidden:

  • using TEXT for everything
  • oversized strings without reason
  • ambiguous numeric types for money

Business Rule Mapping

Planner/OpenAPI rules must map into DB schema:

  • required -> NOT NULL
  • unique -> UNIQUE constraint or index
  • enum/status -> controlled VARCHAR(50) or clearly defined DB enum strategy
  • soft delete -> deleted_at
  • ownership -> FK
  • list/search/filter use cases -> indexes

API Alignment Rule

Every critical API field must map to a DB column.

The schema must align with:

  • planner output
  • OpenAPI field names and types
  • backend entity mapping needs

Do not add critical hidden fields unless clearly justified as internal.


Soft Delete Rule

Soft delete must be implemented with:

  • deleted_at DATETIME NULL

Normal business reads should assume:

  • active rows -> deleted_at IS NULL

Hard delete must never be the default unless explicitly required.


Normalization Rule

The schema should be reasonably normalized.

Avoid:

  • storing repeated structured data in flat duplicated columns
  • denormalized design without clear performance reason
  • mixing unrelated business concepts into one table

Quality Checklist

Before accepting schema:

  • all business tables have PK
  • required base columns exist
  • all real relationships have FK
  • all FK columns are indexed
  • unique rules are enforced
  • search/list behavior has index support
  • OpenAPI-critical fields exist
  • MySQL syntax is valid

Forbidden Patterns

  • no primary key
  • missing foreign key
  • no index on foreign key
  • no deleted_at where soft delete is expected
  • weak alignment with API/planner
  • using DB naming that breaks clean entity mapping

Final Goal

The final schema must be:

  • safe
  • scalable
  • consistent
  • query-friendly
  • ready for backend generation
评论
Ffindsun-vn
findsun-vn
findsun-vn/E-Commerce
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@findsun-vn
所属大类数据与AI Data & AI / 数据工程
国内可用性通用
最近源活动—
风险提示无
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。