|
1 | 1 | import type { DMMF } from '@prisma/generator-helper'; |
2 | 2 |
|
3 | 3 | /** |
4 | | - * Check if a field is a UUID using native DMMF type information |
5 | | - * 3-tier detection: native type � documentation � field name patterns |
| 4 | + * Check if a field is a UUID, based solely on the authoritative DMMF type info. |
| 5 | + * |
| 6 | + * UUID is a *column type*, not a naming convention. Prisma always records a |
| 7 | + * `uuid` column as the `@db.Uuid` native type (a bare `String` maps to `text`), |
| 8 | + * so the native-type/`@db.Uuid` checks capture every genuine UUID column. |
| 9 | + * |
| 10 | + * A previous third tier inferred UUID from field-name patterns (`id`, `*_id`, |
| 11 | + * `*_uuid`, `uuid`). That was a false-positive generator: any external-system |
| 12 | + * identifier stored as text — Stripe IDs (`acct_…`, `cus_…`, `txn_…`), slugs, |
| 13 | + * provider/session references — ends in `_id` without being a UUID, yet got |
| 14 | + * `Schema.isUUID()` applied and then died at decode time on real data. The DMMF |
| 15 | + * already knows the real type, so the name guess only ever contradicted ground |
| 16 | + * truth. It has been removed; use `/// @db.Uuid` (or a real `@db.Uuid` column) |
| 17 | + * to mark UUID columns explicitly. |
6 | 18 | */ |
7 | 19 | export function isUuidField(field: DMMF.Field) { |
8 | | - // 1. Check native type (most reliable) |
| 20 | + // Native type — the authoritative signal for a `uuid` column. |
9 | 21 | if (field.nativeType?.[0] === 'Uuid') { |
10 | 22 | return true; |
11 | 23 | } |
12 | 24 |
|
13 | | - // 2. Check documentation for @db.Uuid |
| 25 | + // `@db.Uuid` recorded in the field's documentation/attributes. |
14 | 26 | if (field.documentation?.includes('@db.Uuid')) { |
15 | 27 | return true; |
16 | 28 | } |
17 | 29 |
|
18 | | - // 3. Fallback: Field name patterns (only for String type) |
19 | | - if (field.type !== 'String') { |
20 | | - return false; |
21 | | - } |
22 | | - |
23 | | - const uuidFieldPatterns = [ |
24 | | - /^id$/, // Primary ID fields |
25 | | - /_id$/, // Foreign key ID fields |
26 | | - /^.*_uuid$/, // uuid suffix |
27 | | - /^uuid$/, // Direct uuid fields |
28 | | - ] as const; |
29 | | - |
30 | | - return uuidFieldPatterns.some((pattern) => pattern.test(field.name)); |
| 30 | + return false; |
31 | 31 | } |
32 | 32 |
|
33 | 33 | /** |
|
0 commit comments