$npx -y skills add wrtnlabs/autobe --skill fix-dbFix Prisma schema compilation errors
| 1 | # Fix Database Schema Errors |
| 2 | |
| 3 | Fix Prisma schema compilation errors according to code conventions. |
| 4 | |
| 5 | ## FORBIDDEN |
| 6 | |
| 7 | **NEVER use:** |
| 8 | - Prisma `enum` types (use String with TypeScript union types instead) |
| 9 | |
| 10 | --- |
| 11 | |
| 12 | ## Purpose |
| 13 | |
| 14 | Fix compilation errors in Prisma schema files to ensure `npm run build:prisma` passes. |
| 15 | |
| 16 | ## Workflow |
| 17 | |
| 18 | ``` |
| 19 | ┌─────────────────────────────────────┐ |
| 20 | │ Step 1: Run Build │ |
| 21 | │ npm run build:prisma │ |
| 22 | └───────────────┬─────────────────────┘ |
| 23 | │ |
| 24 | ▼ |
| 25 | ┌─────────────────────────────────────┐ |
| 26 | │ Step 2: Parse Errors │ |
| 27 | │ - Syntax errors │ |
| 28 | │ - Relation errors │ |
| 29 | │ - Type errors │ |
| 30 | └───────────────┬─────────────────────┘ |
| 31 | │ |
| 32 | ▼ |
| 33 | ┌─────────────────────────────────────┐ |
| 34 | │ Step 3: Fix by Convention │ |
| 35 | │ Apply code conventions │ |
| 36 | └───────────────┬─────────────────────┘ |
| 37 | │ |
| 38 | ▼ |
| 39 | ┌─────────────────────────────────────┐ |
| 40 | │ Step 4: Re-run Build │ |
| 41 | │ Loop until 0 errors │ |
| 42 | └─────────────────────────────────────┘ |
| 43 | ``` |
| 44 | |
| 45 | --- |
| 46 | |
| 47 | ## Step 1: Run Build |
| 48 | |
| 49 | ```bash |
| 50 | npm run build:prisma 2>&1 |
| 51 | ``` |
| 52 | |
| 53 | Capture all error output. |
| 54 | |
| 55 | --- |
| 56 | |
| 57 | ## Step 2: Parse Errors |
| 58 | |
| 59 | Common error types: |
| 60 | - `Error parsing attribute`: Syntax error in decorator |
| 61 | - `Error validating field`: Invalid field type |
| 62 | - `Error validating relation`: Missing or invalid relation |
| 63 | |
| 64 | --- |
| 65 | |
| 66 | ## Step 3: Fix by Convention |
| 67 | |
| 68 | ### Primary Key Convention |
| 69 | ```prisma |
| 70 | // Standard |
| 71 | id String @id @db.Uuid |
| 72 | ``` |
| 73 | |
| 74 | ### Timestamp Convention |
| 75 | ```prisma |
| 76 | created_at DateTime @db.Timestamptz |
| 77 | updated_at DateTime @db.Timestamptz |
| 78 | deleted_at DateTime? @db.Timestamptz |
| 79 | ``` |
| 80 | |
| 81 | ### Foreign Key Convention |
| 82 | ```prisma |
| 83 | {parent}_id String @db.Uuid |
| 84 | {parent} {prefix}_{parents} @relation(fields: [{parent}_id], references: [id], onDelete: Cascade) |
| 85 | ``` |
| 86 | |
| 87 | ### Union Type Fields (NOT enum) |
| 88 | ```prisma |
| 89 | // DO NOT use Prisma enum |
| 90 | status String // "active" | "inactive" defined in TypeScript |
| 91 | |
| 92 | // WRONG - Never do this |
| 93 | // enum Status { ACTIVE INACTIVE } |
| 94 | ``` |
| 95 | |
| 96 | ### Self-referential Relation |
| 97 | ```prisma |
| 98 | parent_id String? @db.Uuid |
| 99 | parent {Model}? @relation("recursive", fields: [parent_id], references: [id], onDelete: Cascade) |
| 100 | children {Model}[] @relation("recursive") |
| 101 | ``` |
| 102 | |
| 103 | ### Index Convention |
| 104 | ```prisma |
| 105 | @@index([{parent}_id, status]) |
| 106 | @@index([name(ops: raw("gin_trgm_ops"))], type: Gin) |
| 107 | ``` |
| 108 | |
| 109 | --- |
| 110 | |
| 111 | ## Step 4: Verify |
| 112 | |
| 113 | ```bash |
| 114 | npm run build:prisma |
| 115 | ``` |
| 116 | |
| 117 | Repeat Steps 2-4 until no errors. |
| 118 | |
| 119 | --- |
| 120 | |
| 121 | ## Common Fixes |
| 122 | |
| 123 | | Error Pattern | Fix | |
| 124 | |---------------|-----| |
| 125 | | Missing relation | Add `@relation` with fields and references | |
| 126 | | Invalid type | Use correct Prisma types (String, Int, DateTime, etc.) | |
| 127 | | Duplicate model | Remove duplicate or rename | |
| 128 | | Missing @@map | Add table name mapping | |
| 129 | | Enum error | Replace with String type | |
| 130 | |
| 131 | --- |
| 132 | |
| 133 | ## Exit Condition |
| 134 | |
| 135 | - `npm run build:prisma` completes with no errors |
| 136 | - All models properly defined |
| 137 | - All relations valid |