Managing Schema Introspection

1. Pulling Existing Schema

npx prisma db pull
AspectDetail
GeneratesModels from current DB tables
PreservesCustom @map, @@map annotations on rerun

2. Mapping Table Names

OriginalResult
snake_casePascalCase model + @@map
PluralSingularized model name by convention

3. Mapping Column Names

OriginalResult
snake_casecamelCase + @map
Reserved wordRenamed with @map

4. Handling Unsupported Types

OutcomeDetail
Marked Unsupportedfield Unsupported("polygon")
Hidden from clientField added as @ignore
WorkaroundUse raw SQL to access

5. Using Custom Type Mappings

CaseApproach
Citext → StringCombine String @db.Citext
Domain typesMap manually to scalar

6. Preserving Manual Schema Changes

PreservedDetail
@@map / @mapKept on re-pull
Custom relation namesKept
Comments/// comments preserved

7. Updating Schema from Database

WorkflowDetail
DB-firstdb pull + prisma generate
HybridPeriodically pull, then maintain schema

8. Handling Database Views

AspectDetail
PreviewpreviewFeatures = ["views"]
Syntaxview Name { ... }
MigrationsView SQL stored under prisma/views/

9. Managing Legacy Database Schemas

IssueMitigation
Missing PKAdd via @@ignore or composite PK
Cyclic FKsMark onDelete: NoAction
Mixed namingUse @map/@@map

10. Syncing Schema Changes

CommandUse
db pushPush schema without migration history
migrate devVersioned sync
db pullPull DB → schema