$npx -y skills add wrtnlabs/autobe --skill validate-dbValidate Prisma schema against requirements specification (read-only)
| 1 | # Validate Database Schema |
| 2 | |
| 3 | Validate that Prisma schema matches the requirements specification. This skill only checks for discrepancies - it does NOT modify any files. |
| 4 | |
| 5 | ## Purpose |
| 6 | |
| 7 | Compare requirements documents with Prisma schema and report: |
| 8 | - ✅ Matching items |
| 9 | - ❌ Mismatching items (needs fix) |
| 10 | - ⚠️ Items requiring review |
| 11 | |
| 12 | ## Workflow |
| 13 | |
| 14 | ``` |
| 15 | ┌─────────────────────────────────────┐ |
| 16 | │ Step 1: Read Requirements │ |
| 17 | │ /docs/analysis/*.md │ |
| 18 | └───────────────┬─────────────────────┘ |
| 19 | │ |
| 20 | ▼ |
| 21 | ┌─────────────────────────────────────┐ |
| 22 | │ Step 2: Read Prisma Schema │ |
| 23 | │ /prisma/schema/*.prisma │ |
| 24 | └───────────────┬─────────────────────┘ |
| 25 | │ |
| 26 | ▼ |
| 27 | ┌─────────────────────────────────────┐ |
| 28 | │ Step 3: Compare & Report │ |
| 29 | │ - Missing tables │ |
| 30 | │ - Missing columns │ |
| 31 | │ - Type mismatches │ |
| 32 | │ - Relationship issues │ |
| 33 | └─────────────────────────────────────┘ |
| 34 | ``` |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## Step 1: Read Requirements |
| 39 | |
| 40 | ```bash |
| 41 | find docs/analysis -name "*.md" -type f |
| 42 | ``` |
| 43 | |
| 44 | Extract from each document: |
| 45 | - Entity definitions |
| 46 | - Field requirements (name, type, nullable, constraints) |
| 47 | - Relationship descriptions |
| 48 | - Business rules |
| 49 | |
| 50 | --- |
| 51 | |
| 52 | ## Step 2: Read Prisma Schema |
| 53 | |
| 54 | ```bash |
| 55 | find prisma/schema -name "*.prisma" -type f |
| 56 | ``` |
| 57 | |
| 58 | Extract from schema: |
| 59 | - Model definitions |
| 60 | - Field types and attributes |
| 61 | - Relations and foreign keys |
| 62 | - Indexes |
| 63 | |
| 64 | --- |
| 65 | |
| 66 | ## Step 3: Validation Checks |
| 67 | |
| 68 | ### 3.1 Entity Coverage |
| 69 | For each entity in requirements: |
| 70 | - ✅ Model exists in schema |
| 71 | - ❌ Model missing from schema |
| 72 | |
| 73 | ### 3.2 Field Coverage |
| 74 | For each required field: |
| 75 | - ✅ Field exists with correct type |
| 76 | - ❌ Field missing |
| 77 | - ❌ Field has wrong type |
| 78 | - ⚠️ Nullable mismatch |
| 79 | |
| 80 | ### 3.3 Relationship Coverage |
| 81 | For each relationship: |
| 82 | - ✅ Relation properly defined |
| 83 | - ❌ Relation missing |
| 84 | - ❌ Wrong cardinality (1:1, 1:N, N:M) |
| 85 | - ⚠️ Missing onDelete cascade |
| 86 | |
| 87 | ### 3.4 Naming Convention |
| 88 | - ✅ Table names follow `{prefix}_{entities}` pattern |
| 89 | - ❌ Inconsistent naming |
| 90 | - ⚠️ Non-standard field names |
| 91 | |
| 92 | **Boolean fields:** |
| 93 | - ✅ Boolean fields have `is_` prefix (e.g., `is_active`, `is_public`) |
| 94 | - ❌ Boolean field missing `is_` prefix (e.g., `active` → `is_active`) |
| 95 | |
| 96 | **Field name consistency:** |
| 97 | - ✅ Same-purpose fields have consistent names across tables |
| 98 | - ❌ Inconsistent naming (e.g., `expires_at` in one table, `expired_at` in another) |
| 99 | - Common fields to check: `*_at` timestamps, `*_id` foreign keys, status fields |
| 100 | |
| 101 | ### 3.5 Table Necessity |
| 102 | Compare with requirements to identify unnecessary tables: |
| 103 | |
| 104 | **Duplicate tables:** |
| 105 | - ❌ Multiple tables serving same purpose |
| 106 | - ⚠️ Tables with overlapping responsibilities |
| 107 | |
| 108 | **Unnecessary snapshot/history tables:** |
| 109 | - ❌ Snapshot table exists but requirements say data should be directly editable |
| 110 | - ❌ History table without audit/versioning requirement |
| 111 | - ✅ Snapshot table exists and requirements specify versioning/history |
| 112 | |
| 113 | --- |
| 114 | |
| 115 | ## Output Format |
| 116 | |
| 117 | ```markdown |
| 118 | # Validation Report: Database Schema |
| 119 | |
| 120 | ## Summary |
| 121 | - Total entities in requirements: X |
| 122 | - Entities found in schema: Y |
| 123 | - Missing entities: Z |
| 124 | |
| 125 | ## ✅ Valid Items |
| 126 | - [Entity] `users` - All fields match |
| 127 | - [Entity] `posts` - All fields match |
| 128 | |
| 129 | ## ❌ Issues Found |
| 130 | - [Missing Entity] `comments` - Defined in requirements but not in schema |
| 131 | - [Missing Field] `users.phone` - Required but not defined |
| 132 | - [Type Mismatch] `posts.view_count` - Expected Int, found String |
| 133 | - [Naming] `users.active` - Boolean field should be `is_active` |
| 134 | - [Naming] `sessions.expired_at` - Inconsistent with `tokens.expires_at` |
| 135 | - [Unnecessary Table] `post_snapshots` - Requirements say posts are directly editable |
| 136 | |
| 137 | ## ⚠️ Warnings |
| 138 | - [Nullable] `users.bio` - Requirements say required, schema allows null |
| 139 | - [Index] `posts` - Consider adding index on `created_at` |
| 140 | - [Duplicate] `user_profiles` and `users` - May have overlapping responsibilities |
| 141 | |
| 142 | ## Recommendation |
| 143 | Run `/fix-db` to fix the issues above. |
| 144 | ``` |
| 145 | |
| 146 | --- |
| 147 | |
| 148 | ## Important |
| 149 | |
| 150 | **This skill is READ-ONLY.** |
| 151 | |
| 152 | - Does NOT modify any files |
| 153 | - Does NOT run any build commands |
| 154 | - Only reports discrepancies |
| 155 | |
| 156 | To fix issues, use `/fix-db` skill. |