Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty mutation input schema with missing imports while generating from pivot table #106

Closed
pedropmedina opened this issue Mar 16, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@pedropmedina
Copy link

pedropmedina commented Mar 16, 2023

Hi @chrishoermann. I'm having this issue with the recent version where not imports are generated for pivot tables and the schema itself is empty which kind of makes sense, but it's causing issue?

model CustomerCompanyContact {
  contact         Int
  contactsCompany Int @map("contacts_company")

  customerRef Customer? @relation(fields: [contactsCompany], references: [id], onDelete: Cascade)
  contactRef  Contact?  @relation(fields: [contact], references: [id], onDelete: Cascade)

  @@id([contact, contactsCompany])
  @@index([contactsCompany])
  @@map("customer_company_contacts")
}
// generated type in @prisma/client looks like this

  export type PartnerCompanyContactUpdateManyMutationInput = {

  }
// The above ^ model generates the following schema. 
// The model itself is just a pivot table. Also notice that not imports where generated either.
// The main problem between prev version 2.0.17 and latest version is that imports up top aren't there
// It's missing Prisma and zod imports causing the build to crash

export const PartnerCompanyContactUpdateManyMutationInputSchema: z.ZodType<Prisma.PartnerCompanyContactUpdateManyMutationInput> = z.object({
}).strict();

export default PartnerCompanyContactUpdateManyMutationInputSchema;
@chrishoermann
Copy link
Owner

@pedropmedina thanks for the report. I made changes to how the imports are handled in one of the latest Versions so there ist obviously a bug somewhere. can you provide a Schema/config so I can reproduce the issue?

@chrishoermann chrishoermann self-assigned this Mar 19, 2023
@chrishoermann chrishoermann added the bug Something isn't working label Mar 19, 2023
@pedropmedina
Copy link
Author

Hey @chrishoermann try this schema. The issue it's with join tables RoleToUser and RolesToResourcesToActions

generator client {
  provider        = "prisma-client-js"
  output          = "../../../../../node_modules/@prisma/client/auth"
  previewFeatures = ["fullTextSearch", "fullTextIndex"]
}

generator zod-prisma-types {
  provider             = "zod-prisma-types"
  output               = "./generated/zod"
  prismaClientPath     = "@prisma/client/auth"
  useMultipleFiles     = true
  useDefaultValidators = false
}

datasource db {
  provider = "mysql"
  url      = env("AUTH_DATABASE_URL")
}

model Application {
  id          String     @id @default(cuid())
  nameId      String     @unique @map("name_id") 
  name        String
  description String?    @db.Text
  url         String?
  resources   Resource[]
  createdAt   DateTime   @default(now()) @map("created_at")
  updatedAt   DateTime   @updatedAt @map("updated_at")

  @@map("applications")
}

model Action {
  id               String                      @id @default(cuid())
  nameId           String                      @unique @map("name_id")
  name             String
  createdAt        DateTime                    @default(now()) @map("created_at")
  updatedAt        DateTime                    @updatedAt @map("updated_at")
  rolesToResources RolesToResourcesToActions[]

  @@map("actions")
}

model Resource {
  id             String                      @id @default(cuid())
  name           String
  description    String?                     @db.Text
  application    Application                 @relation(fields: [applicationId], references: [id], onDelete: Cascade)
  applicationId  String                      @map("application_id")
  createdAt      DateTime                    @default(now()) @map("created_at")
  updatedAt      DateTime                    @updatedAt @map("updated_at")
  rolesToActions RolesToResourcesToActions[]

  @@map("resources")
}

model Role {
  id                 String                      @id @default(cuid())
  nameId             String                      @unique @map("name_id")
  name               String
  isSuperAdmin       Boolean?                    @default(false) @map("is_super_admin")
  isAdmin            Boolean?                    @default(false) @map("is_admin")
  createdAt          DateTime                    @default(now()) @map("created_at")
  updatedAt          DateTime                    @updatedAt @map("updated_at")
  resourcesToActions RolesToResourcesToActions[]
  users              RoleToUser[]

  @@map("roles")
}

model RoleToUser {
  user   User   @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId String @map("user_id")
  role   Role   @relation(fields: [roleId], references: [id], onDelete: Cascade)
  roleId String @map("role_id")

  @@id([userId, roleId])
  @@map("roles_to_users")
}

model RolesToResourcesToActions {
  roleId     String
  role       Role     @relation(fields: [roleId], references: [id], onDelete: Cascade)
  resourceId String
  resource   Resource @relation(fields: [resourceId], references: [id], onDelete: Cascade)
  actionId   String
  action     Action   @relation(fields: [actionId], references: [id], onDelete: Cascade)

  @@id([roleId, resourceId, actionId])
  @@map("roles_to_resources_to_actions")
}

model Department {
  id          String   @id @default(cuid())
  nameId      String   @unique @map("name_id") 
  name        String
  description String?  @db.Text
  users       User[]
  createdAt   DateTime @default(now()) @map("created_at")
  updatedAt   DateTime @updatedAt @map("updated_at")

  @@map("departments")
}

model UserType {
  id          String   @id @default(cuid())
  nameId      String   @unique @map("name_id") 
  name        String
  description String?  @db.Text
  createdAt   DateTime @default(now()) @map("created_at")
  updatedAt   DateTime @updatedAt @map("updated_at")
  user        User[]   @relation("user_type")

  @@map("user_types")
}

model User {
  firstName    String?      @map("first_name")
  lastName     String?      @map("last_name")
  phone        String?
  isActive     Boolean?     @default(true) @map("is_active")
  isEmployee   Boolean?     @default(false) @map("is_employee")
  isCustomer   Boolean?     @default(false) @map("is_customer")
  department   Department?  @relation(fields: [departmentId], references: [id])
  departmentId String?      @unique @map("department_id")
  userType     UserType?    @relation(name: "user_type", fields: [userTypeId], references: [id])
  userTypeId   String?      @unique @map("user_type_id")
  createdAt    DateTime     @default(now()) @map("created_at")
  updatedAt    DateTime     @updatedAt @map("updated_at")
  roles        RoleToUser[]
  id            String    @id @default(cuid())
  email         String    @unique

  @@map("users")
}
}

chrishoermann added a commit that referenced this issue Mar 27, 2023
@chrishoermann
Copy link
Owner

@pedropmedina this should now be fixed in the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants