AgentSkillsCN

Backend Models

定义数据库模型、模式与ORM映射,具备恰当的关系、约束与数据完整性规则。当创建或修改ORM模型类、数据库模式定义、模型关系、验证器,或处理models.py、schema.prisma、实体类,或Sequelize/TypeORM/ActiveRecord模型定义文件时,使用此技能。在定义主键、外键、索引、唯一约束、时间戳,或实现模型验证逻辑、序列化器与数据类型映射时,应用此技能。此技能确保模型遵循命名规范,包含恰当的数据库约束,定义清晰的关系与级联行为,平衡规范化与性能需求,同时在模型与数据库层面保持数据完整性。

SKILL.md
--- frontmatter
name: Backend Models
description: Define database models, schemas, and ORM mappings with proper relationships, constraints, and data integrity rules. Use this skill when creating or modifying ORM model classes, database schema definitions, model relationships, validators, or working with files like models.py, schema.prisma, entity classes, or Sequelize/TypeORM/ActiveRecord model definitions. Apply this skill when defining primary keys, foreign keys, indexes, unique constraints, timestamps, or when implementing model validation logic, serializers, and data type mappings. This skill ensures models follow naming conventions, include appropriate database constraints, define clear relationships with cascade behaviors, balance normalization with performance needs, and maintain data integrity at both the model and database levels.

Backend Models

This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle backend models.

When to use this skill

  • When creating or modifying ORM model classes (Django models, SQLAlchemy, Prisma, TypeORM, ActiveRecord)
  • When defining database schemas, entity classes, or data models
  • When establishing relationships between models (one-to-many, many-to-many, foreign keys)
  • When adding database constraints (NOT NULL, UNIQUE, CHECK constraints)
  • When defining model validators, custom fields, or data type mappings
  • When working with files like models.py, schema.prisma, entities/, or model definition files
  • When implementing model-level business logic, computed properties, or hooks
  • When adding timestamps (created_at, updated_at) or soft delete functionality
  • When defining cascade behaviors for relationships (CASCADE, SET NULL, RESTRICT)
  • When optimizing model queries with select_related, prefetch_related, or eager loading
  • When creating model serializers, schemas, or data transfer objects (DTOs)
  • When balancing normalization with denormalization for performance

Instructions

For details, refer to the information provided in this file: backend models