Before adding database constraints or designing schema relationships, thoroughly understand the underlying business logic and data relationships. Constraints that seem logical at first glance may break existing functionality or prevent valid use cases.
Before adding database constraints or designing schema relationships, thoroughly understand the underlying business logic and data relationships. Constraints that seem logical at first glance may break existing functionality or prevent valid use cases.
Key practices:
Example from schema design:
// Instead of separate optional fields for different credit types:
model CreditExpenseLog {
smsSegments Int?
callDuration Int?
// Consider a more extensible approach:
creditFor String // "SMS", "CALL", etc.
amount Int
metadata Json? // Store type-specific data
}
This approach prevents constraint conflicts like @@unique([outlookSubscriptionId, eventTypeId])
when the same subscription ID is legitimately reused across multiple event types, and makes the schema more maintainable as new credit types are added.
Enter the URL of a public GitHub repository