Data Modeling Standards
Overview
This skill defines data modeling standards for consistent, performant, and maintainable database schemas. Good data models prevent data integrity issues, enable efficient queries, and make future changes manageable.
When to Use
- When designing new database tables or collections
- When modifying existing schemas (adding/removing columns)
- When reviewing data architecture decisions
- When choosing between SQL and NoSQL for new data
- When designing data migrations
- Don't use when: Working with temporary or throwaway data with no persistence needs
Core Procedures
Step 1: Design Principles
Apply these to all data models:
- Normalized: Eliminate redundancy (3NF minimum unless justified)
- Named Clearly: Tables as nouns (plural), columns as attributes (singular)
- Typed Strictly: Use specific types (not generic text/blob where possible)
- Constrained: Define NOT NULL, UNIQUE, FOREIGN KEY where applicable
- Indexed Strategically: Index columns used in WHERE, JOIN, ORDER BY
Step 2: Naming Conventions
| Element |
Convention |
Example |
| Tables |
lowercase_plural_nouns |
users, orders, order_items |
| Columns |
lowercase_snake_case |
first_name, created_at |
| Primary Keys |
id (or {table}_id) |
id, user_id |
| Foreign Keys |
{referenced_table}_id |
company_id, agent_id |
| Indexes |
idx_{table}_{columns} |
idx_users_email |
| Constraints |
fk/pk/ck/uk_{table}_{columns} |
fk_orders_user_id |
Step 3: Column Standards
Every table should have:
id UUID PRIMARY KEY -- or SERIAL/bigint
created_at TIMESTAMP NOT NULL DEFAULT NOW()
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
Additional standards:
- Use
BOOLEAN for true/false (not integers)
- Use
TEXT for unlimited strings, VARCHAR(n) for fixed max
- Use
DECIMAL for financial amounts (not FLOAT)
- Use
JSONB for flexible/semi-structured data (PostgreSQL)
- Use
ENUM or lookup tables for fixed value sets
- Always store timestamps in UTC
Step 4: Relationship Design
- One-to-Many: Foreign key on the "many" side
- Many-to-Many: Junction table with two foreign keys, composite primary key
- Self-Referencing: Foreign key to same table (e.g., manager_id → users.id)
- Always define ON DELETE behavior (CASCADE, SET NULL, RESTRICT)
Step 5: Migration Practices
- Always write forward migrations (no backward-only)
- Each migration is atomic and reversible (with down migration)
- Test migrations on copy of production data
- Never drop columns in same migration as adding replacement
- Data migrations separate from schema migrations
- Lock strategy for concurrent deployments
Quality Checklist
Error Handling
- Error: Migration fails on production
Response: Rollback immediately using down migration, diagnose in staging
- Error: Schema change causes data loss
Response: Write data migration first, preserve data in new structure, verify before dropping old
Cross-Team Integration
Related Skills: database-schema-management, api-design-standards, secrets-handling, regression-prevention
Used By: Database agents, backend engineers, data engineers, infrastructure teams
1---2name: data-modeling-standards3description: >4 Use when designing, creating, or modifying database schemas, data structures, or5 data models. This skill provides standardized data modeling practices ensuring6 consistency, integrity, and maintainability across all data stores.7metadata:8 source: https://skillmd.com/skills/construct-ai-primary/data-modeling-standards9---1011# Data Modeling Standards1213## Overview14This skill defines data modeling standards for consistent, performant, and maintainable database schemas. Good data models prevent data integrity issues, enable efficient queries, and make future changes manageable.1516## When to Use17- When designing new database tables or collections18- When modifying existing schemas (adding/removing columns)19- When reviewing data architecture decisions20- When choosing between SQL and NoSQL for new data21- When designing data migrations22- **Don't use when:** Working with temporary or throwaway data with no persistence needs2324## Core Procedures2526### Step 1: Design Principles27Apply these to all data models:28- **Normalized:** Eliminate redundancy (3NF minimum unless justified)29- **Named Clearly:** Tables as nouns (plural), columns as attributes (singular)30- **Typed Strictly:** Use specific types (not generic text/blob where possible)31- **Constrained:** Define NOT NULL, UNIQUE, FOREIGN KEY where applicable32- **Indexed Strategically:** Index columns used in WHERE, JOIN, ORDER BY3334### Step 2: Naming Conventions35| Element | Convention | Example |36|---------|------------|---------|37| Tables | lowercase_plural_nouns | `users`, `orders`, `order_items` |38| Columns | lowercase_snake_case | `first_name`, `created_at` |39| Primary Keys | `id` (or `{table}_id`) | `id`, `user_id` |40| Foreign Keys | `{referenced_table}_id` | `company_id`, `agent_id` |41| Indexes | `idx_{table}_{columns}` | `idx_users_email` |42| Constraints | `fk/pk/ck/uk_{table}_{columns}` | `fk_orders_user_id` |4344### Step 3: Column Standards45Every table should have:46```sql47id UUID PRIMARY KEY -- or SERIAL/bigint48created_at TIMESTAMP NOT NULL DEFAULT NOW()49updated_at TIMESTAMP NOT NULL DEFAULT NOW()50```5152Additional standards:53- Use `BOOLEAN` for true/false (not integers)54- Use `TEXT` for unlimited strings, `VARCHAR(n)` for fixed max55- Use `DECIMAL` for financial amounts (not FLOAT)56- Use `JSONB` for flexible/semi-structured data (PostgreSQL)57- Use `ENUM` or lookup tables for fixed value sets58- Always store timestamps in UTC5960### Step 4: Relationship Design61- **One-to-Many:** Foreign key on the "many" side62- **Many-to-Many:** Junction table with two foreign keys, composite primary key63- **Self-Referencing:** Foreign key to same table (e.g., manager_id → users.id)64- Always define ON DELETE behavior (CASCADE, SET NULL, RESTRICT)6566### Step 5: Migration Practices67- Always write forward migrations (no backward-only)68- Each migration is atomic and reversible (with down migration)69- Test migrations on copy of production data70- Never drop columns in same migration as adding replacement71- Data migrations separate from schema migrations72- Lock strategy for concurrent deployments7374## Quality Checklist75- [ ] Tables follow naming conventions76- [ ] All tables have id, created_at, updated_at77- [ ] Foreign keys defined with ON DELETE behavior78- [ ] Indexes exist on frequently queried columns79- [ ] Data types are specific and appropriate80- [ ] Constraints prevent invalid data states81- [ ] Migration is reversible and tested82- [ ] No data loss in schema changes8384## Error Handling85- **Error:** Migration fails on production86 **Response:** Rollback immediately using down migration, diagnose in staging87- **Error:** Schema change causes data loss88 **Response:** Write data migration first, preserve data in new structure, verify before dropping old8990## Cross-Team Integration91**Related Skills:** database-schema-management, api-design-standards, secrets-handling, regression-prevention92**Used By:** Database agents, backend engineers, data engineers, infrastructure teams