Fright XO
Fright XO
Explore posts from servers
PPrisma
Created by Fright XO on 10/17/2024 in #help-and-questions
PRISMA_SKIP_POSTINSTALL_GENERATE is Not Skipping Generate on yarn install
I am running into errors during dockerfile builds, in which I cannot reach the database. My soluition was to try using the environment variables. During yarn install it seems the generate command is still running.
6 replies
PPrisma
Created by Fright XO on 6/24/2024 in #help-and-questions
Best Practices for Updating Nested Relations in Prisma with NestJS and SQL Server
Hello! I'm working on a project using NestJS, Prisma, and SQL Server, and I need help with updating a complex model with many relations. Here’s the context: I have the following models with relationships:
UserConfig
|- Preferences? // 1:1
| |- NotificationSettings[] // 1:N
| | `- EmailSettings? // 1:1
| `- ThemeSettings? // 1:1
`- AccountSettings? // 1:1
`- PrivacySettings[] // 1:N
UserConfig
|- Preferences? // 1:1
| |- NotificationSettings[] // 1:N
| | `- EmailSettings? // 1:1
| `- ThemeSettings? // 1:1
`- AccountSettings? // 1:1
`- PrivacySettings[] // 1:N
Models in Prisma Schema:
model UserConfig {
id Int @id @default(autoincrement())
userId Int @unique
preferences Preferences?
accountSettings AccountSettings?
}

model Preferences {
id Int @id @default(autoincrement())
userConfigId Int @unique
notificationSettings NotificationSettings[]
themeSettings ThemeSettings?
userConfig UserConfig @relation(fields: [userConfigId], references: [id], onDelete: Cascade)
}

model NotificationSettings {
id Int @id @default(autoincrement())
type String // "EMAIL" | "SMS"
preferencesId Int
emailSettings EmailSettings?
preferences Preferences @relation(fields: [preferencesId], references: [id], onDelete: Cascade)
}

model EmailSettings {
id Int @id @default(autoincrement())
email String
notificationSettingsId Int @unique
notificationSettings NotificationSettings @relation(fields: [notificationSettingsId], references: [id], onDelete: Cascade)
}

model ThemeSettings {
id Int @id @default(autoincrement())
theme String
preferencesId Int @unique
preferences Preferences @relation(fields: [preferencesId], references: [id], onDelete: Cascade)
}

model AccountSettings {
id Int @id @default(autoincrement())
userConfigId Int @unique
privacySettings PrivacySettings[]
userConfig UserConfig @relation(fields: [userConfigId], references: [id], onDelete: Cascade)
}

model PrivacySettings {
id Int @id @default(autoincrement())
setting String
accountSettingsId Int
accountSettings AccountSettings @relation(fields: [accountSettingsId], references: [id], onDelete: Cascade)
}
model UserConfig {
id Int @id @default(autoincrement())
userId Int @unique
preferences Preferences?
accountSettings AccountSettings?
}

model Preferences {
id Int @id @default(autoincrement())
userConfigId Int @unique
notificationSettings NotificationSettings[]
themeSettings ThemeSettings?
userConfig UserConfig @relation(fields: [userConfigId], references: [id], onDelete: Cascade)
}

model NotificationSettings {
id Int @id @default(autoincrement())
type String // "EMAIL" | "SMS"
preferencesId Int
emailSettings EmailSettings?
preferences Preferences @relation(fields: [preferencesId], references: [id], onDelete: Cascade)
}

model EmailSettings {
id Int @id @default(autoincrement())
email String
notificationSettingsId Int @unique
notificationSettings NotificationSettings @relation(fields: [notificationSettingsId], references: [id], onDelete: Cascade)
}

model ThemeSettings {
id Int @id @default(autoincrement())
theme String
preferencesId Int @unique
preferences Preferences @relation(fields: [preferencesId], references: [id], onDelete: Cascade)
}

model AccountSettings {
id Int @id @default(autoincrement())
userConfigId Int @unique
privacySettings PrivacySettings[]
userConfig UserConfig @relation(fields: [userConfigId], references: [id], onDelete: Cascade)
}

model PrivacySettings {
id Int @id @default(autoincrement())
setting String
accountSettingsId Int
accountSettings AccountSettings @relation(fields: [accountSettingsId], references: [id], onDelete: Cascade)
}
Question: How can I efficiently update these models in a single query or within a transaction? The update should handle creating, deleting, and updating nested related objects. I currently do not have services or controllers for the related models, but I can create them if necessary. Thank you for any guidance!
4 replies