Prisma Schema Generator
TalkingSchema's AI copilot generates complete schema.prisma files from any ERD — including all Prisma model definitions, @relation directives, enum types, default values, @id, @unique, and @@index attributes. The output is production-ready and maps directly to the relational structure defined in your diagram.
Outputs are provided as formatted code blocks, with an option to download as a .prisma file coming soon
How to Generate a Prisma Schema
Step 1 — Open or build your schema
Open an existing schema in TalkingSchema, import from a live database, or describe your system to the AI copilot. The AI maintains full context of the current ERD.
Step 2 — Ask the AI copilot
Use any of the following prompts in the chat panel:
Generate a schema.prisma file for this schema. Include all relations,
cascade rules, enums, and sensible defaults.
Export this schema as a Prisma ORM schema with all @relation directives,
@@index declarations, and @default values.
Create a schema.prisma for a PostgreSQL datasource. Use @db.Uuid for
all UUID primary keys and include @@map for snake_case table names.
Step 3 — Copy the output
The AI returns a complete, formatted schema.prisma block. Copy it directly into your project's prisma/ directory.
Example Output
Using the Global Sustainable Supply Chain (GSSC) schema — a 10-table 3NF transactional model — TalkingSchema generates the following Prisma schema:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum CarbonTier {
A
B
C
D
}
enum CustomerTier {
enterprise
mid_market @map("mid-market")
smb
}
enum OrderStatus {
draft
confirmed
shipped
received
cancelled
}
enum SalesOrderStatus {
pending
confirmed
shipped
delivered
cancelled
}
model Supplier {
supplierId String @id @default(uuid()) @map("supplier_id") @db.Uuid
companyName String @map("company_name") @db.VarChar(200)
country String @db.VarChar(100)
carbonTier CarbonTier @map("carbon_tier")
certification String? @db.VarChar(100)
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
products Product[]
purchaseOrders PurchaseOrder[]
@@map("suppliers")
}
model Product {
productId String @id @default(uuid()) @map("product_id") @db.Uuid
sku String @unique @db.VarChar(50)
name String @db.VarChar(200)
category String @db.VarChar(100)
unitWeightKg Decimal? @map("unit_weight_kg") @db.Decimal(8, 3)
unitCostUsd Decimal @map("unit_cost_usd") @db.Decimal(12, 4)
carbonIntensityScore Decimal? @map("carbon_intensity_score") @db.Decimal(5, 2)
supplierId String @map("supplier_id") @db.Uuid
isActive Boolean @default(true) @map("is_active")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
supplier Supplier @relation(fields: [supplierId], references: [supplierId])
purchaseOrderItems PurchaseOrderItem[]
salesOrderItems SalesOrderItem[]
inventory Inventory[]
@@map("products")
}
model Warehouse {
warehouseId String @id @default(uuid()) @map("warehouse_id") @db.Uuid
name String @db.VarChar(200)
locationCity String @map("location_city") @db.VarChar(100)
locationCountry String @map("location_country") @db.VarChar(100)
capacityUnits Int @map("capacity_units")
isActive Boolean @default(true) @map("is_active")
purchaseOrders PurchaseOrder[]
shipments Shipment[]
salesOrders SalesOrder[]
inventory Inventory[]
@@map("warehouses")
}
model Customer {
customerId String @id @default(uuid()) @map("customer_id") @db.Uuid
companyName String @map("company_name") @db.VarChar(200)
country String @db.VarChar(100)
tier CustomerTier
creditLimitUsd Decimal @default(0) @map("credit_limit_usd") @db.Decimal(14, 2)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
salesOrders SalesOrder[]
@@map("customers")
}
model PurchaseOrder {
poId String @id @default(uuid()) @map("po_id") @db.Uuid
supplierId String @map("supplier_id") @db.Uuid
warehouseId String @map("warehouse_id") @db.Uuid
orderDate DateTime @map("order_date") @db.Date
expectedDelivery DateTime? @map("expected_delivery") @db.Date
status OrderStatus?
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
supplier Supplier @relation(fields: [supplierId], references: [supplierId])
warehouse Warehouse @relation(fields: [warehouseId], references: [warehouseId])
items PurchaseOrderItem[]
shipments Shipment[]
@@map("purchase_orders")
}
model PurchaseOrderItem {
itemId String @id @default(uuid()) @map("item_id") @db.Uuid
poId String @map("po_id") @db.Uuid
productId String @map("product_id") @db.Uuid
quantity Int
unitCostUsd Decimal @map("unit_cost_usd") @db.Decimal(12, 4)
purchaseOrder PurchaseOrder @relation(fields: [poId], references: [poId], onDelete: Cascade)
product Product @relation(fields: [productId], references: [productId])
@@map("purchase_order_items")
}
model Shipment {
shipmentId String @id @default(uuid()) @map("shipment_id") @db.Uuid
poId String @map("po_id") @db.Uuid
warehouseId String @map("warehouse_id") @db.Uuid
carrier String? @db.VarChar(100)
shippedAt DateTime? @map("shipped_at") @db.Timestamptz(6)
arrivedAt DateTime? @map("arrived_at") @db.Timestamptz(6)
co2Kg Decimal? @map("co2_kg") @db.Decimal(10, 3)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
purchaseOrder PurchaseOrder @relation(fields: [poId], references: [poId])
warehouse Warehouse @relation(fields: [warehouseId], references: [warehouseId])
@@map("shipments")
}
model SalesOrder {
soId String @id @default(uuid()) @map("so_id") @db.Uuid
customerId String @map("customer_id") @db.Uuid
warehouseId String @map("warehouse_id") @db.Uuid
orderDate DateTime @map("order_date") @db.Date
status SalesOrderStatus?
paymentTerms String? @map("payment_terms") @db.VarChar(50)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(6)
customer Customer @relation(fields: [customerId], references: [customerId])
warehouse Warehouse @relation(fields: [warehouseId], references: [warehouseId])
items SalesOrderItem[]
@@map("sales_orders")
}
model SalesOrderItem {
itemId String @id @default(uuid()) @map("item_id") @db.Uuid
soId String @map("so_id") @db.Uuid
productId String @map("product_id") @db.Uuid
quantity Int
unitPriceUsd Decimal @map("unit_price_usd") @db.Decimal(12, 4)
salesOrder SalesOrder @relation(fields: [soId], references: [soId], onDelete: Cascade)
product Product @relation(fields: [productId], references: [productId])
@@map("sales_order_items")
}
model Inventory {
inventoryId String @id @default(uuid()) @map("inventory_id") @db.Uuid
warehouseId String @map("warehouse_id") @db.Uuid
productId String @map("product_id") @db.Uuid
quantityOnHand Int @default(0) @map("quantity_on_hand")
reorderPoint Int @default(0) @map("reorder_point")
lastCountedAt DateTime? @map("last_counted_at") @db.Timestamptz(6)
warehouse Warehouse @relation(fields: [warehouseId], references: [warehouseId])
product Product @relation(fields: [productId], references: [productId])
@@unique([warehouseId, productId])
@@map("inventory")
}
Customizing the Output
The AI copilot accepts precise instructions. Add any of the following to your prompt:
| Requirement | Prompt addition |
|---|---|
Use Int instead of String for IDs | "Use autoincrement integer IDs, not UUIDs" |
Include @@index for frequently queried columns | "Add database indexes for all foreign key columns and status fields" |
Use @map for snake_case ↔ camelCase | "Add @@map and @map directives for all models and fields" |
| Separate schema files per domain | "Split the output into separate .prisma files: suppliers.prisma, orders.prisma, logistics.prisma" |
| Add JSDoc comments | "Include /// JSDoc comments on each model describing its purpose" |
| Target MySQL instead of PostgreSQL | "Use MySQL as the datasource provider. Adjust types accordingly." |
Frequently Asked Questions
Does the Prisma schema include all relationships?
Yes. TalkingSchema maps every foreign key in the ERD to a @relation directive with the correct fields and references arrays, and applies onDelete and onUpdate cascade rules where defined in the schema.
What happens to enum types?
PostgreSQL enum types defined in TalkingSchema are converted to Prisma enum blocks. The AI uses the exact enum values from your schema.
Can I regenerate the schema after making ERD changes?
Yes. Ask the AI copilot for a fresh export at any time: "Regenerate the schema.prisma with the latest changes." The AI always works from the current state of the ERD.
Is this the same as prisma db pull?
No. prisma db pull introspects a running database. TalkingSchema generates a schema.prisma from your ERD model, which is useful when designing a new schema or when you want to keep the ORM layer in sync with your diagram without requiring a live database connection.