paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
684 stars 55 forks source link

Make sure model names are PascalCase too #204

Closed mubaidr closed 3 years ago

mubaidr commented 3 years ago

By default this scripts ignore lowercase model names and but converts relations, snake_case naming to PascalCase.

This edit ensures that all models are consistently named using PascalCase

Example schema:

model attachment {
  id               Int            @id @default(autoincrement())
  path             String
  attachment_type_id Int 
  attachment_type   attachment_type @relation(name: "attachment_to_attachment_type", fields: [attachment_type_id], references: [id])

  @@map("attachment")
}

model attachment_type {
  id          Int          @id @default(autoincrement())
  title       String?      @unique
  attachments attachment[] @relation(name: "attachment_to_attachment_type")
}

Current conversion:

model attachment {
  id               Int            @id @default(autoincrement())
  path             String
  attachmentTypeId Int            @map("attachment_type_id")
  attachmentType   AttachmentType @relation(name: "attachmentToattachment_type", fields: [attachmentTypeId], references: [id])

  @@map("attachment")
}

model AttachmentType {
  id          Int          @id @default(autoincrement())
  title       String?      @unique
  attachments attachment[] @relation(name: "attachmentToattachment_type")

  @@map("attachment_type")
}

new/Proposed changes:

model Attachment {
  id               Int            @id @default(autoincrement())
  path             String
  attachmentTypeId Int            @map("attachment_type_id")
  attachmentType   AttachmentType @relation(name: "attachmentToattachment_type", fields: [attachmentTypeId], references: [id])

  @@map("attachment")
}

model AttachmentType {
  id          Int          @id @default(autoincrement())
  title       String?      @unique
  attachments Attachment[] @relation(name: "attachmentToattachment_type")

  @@map("attachment_type")
}
mubaidr commented 3 years ago

Yeah. It was just a quick dirty try to fix.

AhmedElywa commented 3 years ago

I will try to fix this issue in my next version