add-database-development
Database layer: entities, repos, migrations, multi-tenancy. Stack-agnostic. Consult CLAUDE.md for ORM.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Database layer: entities, repos, migrations, multi-tenancy. Stack-agnostic. Consult CLAUDE.md for ORM.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | add-database-development |
| description | Database layer: entities, repos, migrations, multi-tenancy. Stack-agnostic. Consult CLAUDE.md for ORM. |
Skill for implementing the database layer following universal data architecture principles.
Use for: Entities, Migrations, Repositories, Enums, Database types
Do not use for: Controllers/DTOs (backend-development), Frontend (ux-design), API contracts, query optimization tuning
Stack orientation: Consult CLAUDE.md ## Architecture Contract for the ORM and database in use. Apply these principles using the project's ORM API.
TypeScript interfaces representing domain objects.
export interface User {
id: string;
accountId: string; // multi-tenant
email: string;
role: UserRole;
status: EntityStatus;
createdAt: Date;
updatedAt: Date;
}
Rules:
id, createdAt, updatedAtaccountId for multi-tenantMANDATORY: Export in barrel file (entities/index.ts).
export enum UserRole {
OWNER = 'owner',
ADMIN = 'admin',
MEMBER = 'member',
}
Rules:
index.ts| Layer | Casing | Example |
|---|---|---|
| Database | snake_case | user_id, created_at, account_id |
| Application | camelCase | userId, createdAt, accountId |
The repository layer converts between the two via mapper functions (toEntity / toPersistence).
Use appropriate database types for each column:
Naming: YYYYMMDDNNN_description_snake_case.[ext] — e.g. 20251221001_create_invites_table.
Principles — apply using your project's migration tool syntax:
up and down — every migration must be reversibleCASCADE for child records that cannot exist without parent (e.g., invites → account), RESTRICT or SET NULL when child has independent value; document WHERE and WHY cascade is usedaccount_id, lookup fields, composite indexes for multi-column queries)id (UUID generation), created_at, updated_atStandard columns (lookup):
| Column | Definition |
|---|---|
id | UUID, primary key, auto-generated |
account_id | UUID, NOT NULL, FK to accounts, CASCADE delete |
created_at | timestamp, default now() |
updated_at | timestamp, default now() |
export interface IInviteRepository {
findById(id: string): Promise<Invite | null>;
findByAccountId(accountId: string): Promise<Invite[]>;
create(data: Omit<Invite, 'id' | 'createdAt' | 'updatedAt'>): Promise<Invite>;
update(id: string, data: Partial<Invite>): Promise<Invite>;
delete(id: string): Promise<void>;
}
The implementation uses the project's ORM. Key rules:
// Mapper: snake_case (database) → camelCase (domain)
private toEntity(row: any): Invite {
return {
id: row.id,
accountId: row.account_id,
email: row.email,
// ...
};
}
Rules:
toEntity() mapper for snake → camel conversionaccount_id/tenant_idMaintain organized exports for every new entity, enum, repository, and interface:
// One barrel per directory: entities/, enums/, repositories/, interfaces/
export * from './User';
export * from './Invite';
// ...add every new file
EVERY query MUST filter by account_id/tenant_id. No exceptions.
async findAll(): Promise<User[]> { /* WRONG — leaks data across tenants */ }
async findByAccountId(accountId: string): Promise<User[]> { /* CORRECT — scoped */ }
Rules:
account_id FK with CASCADE deleteaccount_id columninterface (not class)index.ts)id, createdAt, updatedAt fieldsaccountId field (if multi-tenant)index.ts)OWNER = 'owner')YYYYMMDDNNN_description_snake_case patternup and down (reversible)account_id, lookup fields)account_id FK has CASCADE deleteaccount_id / tenant_idtoEntity) for snake_case → camelCase conversionConsolidated view of the add-pro ecosystem - commands, skills, relationships and dependencies. Loaded by /add as source of truth.
Source of truth for ADD doc rules, depth floors, IDs, refs, validation gate. Load before any doc write.
Use when running agent-judged QA validation (read-PNG by default; the playwright plugin adds live driving) — the Level C judge rubric, severity taxonomy, dual-judge (@ux-agent review ∥ @qa-agent) method, report schema/template, and the config.json/screens.json formats. Consumed by /add.qa and both judges.
Use when a state-materializing command starts or is asked to upgrade — reads the setup receipt, compares the recorded contract against the shipped one, executes the declared upgrade deltas sequentially, and rewrites the receipt even on a verified-current no-op. Consumed by /add.qa-setup STEP 1.5 and STEP 11.
Internal skill for developing ADD framework artefacts (commands, skills, agents, scripts). Use when add-framework--plan analyzes viability of new framework features, when add-framework--build implements framework artefacts, or when creating/modifying commands, skills, or agents. Always use this skill before proposing or implementing changes to the framework itself.
Use when building, styling, or theming UI components, pages, layouts, dashboards, charts, tables, or forms for SaaS products.