#Prisma - How do you guys prefer to setup your Models?

5 messages · Page 1 of 1 (latest)

proud grove

Basically just want to get a clean layout for my Schema and DB
For example, logging & guild do you have a separate model for log channels, log message, etc.
and then your guild, or do you just put all that into the guild model?
Just want to write clean code 😄

upper arch

I tend to think module-wise when creating my schema. While your code doesn't necessarily have to have a working module enabling/disabling, you can have separate models for each module/category.

This means that on a Guild, there can be a LoggingModule which stores info about logging, a ModerationModule which stores info about moderation.

The models would be 1-1 relation of course.

Although if your bot only specialises in logging for example, this wouldn't be too useful

proud grove
upper arch I tend to think module-wise when creating my schema. While your code doesn't nec...

Sorry for the late response, have been busy. But I agree! Did some researching on my own and found working with modules seemed better to me 😄
I did however have a question about Users, since multiple guilds can have multiple users, and possibly some of the same members, wouldn't it be best to store users containing something like "guild profiles" and storing those guild profiles in the Guild ?

ex:

model Guild {
  guildId        String      @id @unique
  guildName      String
  guildBrandName String      @default("")
  users          UserProfile[]
}

model User {
  userId  String  @id @unique
  guildProfiles  UserProfile[]
}

model UserProfile {
  user    User    @relation(fields: [userId], references: [userId])
  guild   Guild   @relation(fields: [guildId], references: [guildId])
  userId  String  @id
  guildId String

  @@unique([userId, guildId])
}
upper arch