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

Relations as mixin still bugy #40

Closed
Daidalos117 opened this issue Oct 17, 2022 · 6 comments
Closed

Relations as mixin still bugy #40

Daidalos117 opened this issue Oct 17, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Daidalos117
Copy link

Daidalos117 commented Oct 17, 2022

Hi there,
I am following this issue.

Please again look into this: https://codesandbox.io/s/exciting-leaf-bxqzvt?file=/src/schema.prisma
Relation mixin is used by Request, Session, Token models, but it gets generated only for the Request.

If you want to, have a look into my full scheme: https://codesandbox.io/s/laughing-sun-u8sd54?file=/src/schema.prisma
Basically a lot of models should contain the relation, but only CitationResponse and CitationRequest contains it.

Thank you in advance!

@ridafkih
Copy link
Owner

@Daidalos117 Looking into this now, thank you for making this issue.

@ridafkih ridafkih added the bug Something isn't working label Oct 18, 2022
@ridafkih
Copy link
Owner

@Daidalos117 Would you be okay, by the way, if I were to take your schema and (once I get this resolved) use it as the example to be used in the unit tests for this library? It utilizes many features, so would be a great snapshot.

@Daidalos117
Copy link
Author

@ridafkih for sure! Use it 👍

@ridafkih
Copy link
Owner

@Daidalos117 I've created a pull-request that may act as a potential fix, the Prisma schema I get resulting from your configuration is as follows. Let me know if this looks correct to you.

datasource database {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
}

enum CitationStatus {
  PENDING
  ACCEPTED
  DECLINED
}

enum Language {
  CS
}

enum MessageStatus {
  NEW
  DELIVERED
  READ
}

enum Site {
  FACEBOOK
  INSTAGRAM
  YOUTUBE
  DELETED
  GOOGLE
  WWW
}

enum Status {
  FACEBOOK
  INSTAGRAM
  YOUTUBE
  DELETED
  GOOGLE
  WWW
}

enum TokenType {
  RESET_PASSWORD
}

model Profile {
  street     String?
  zip        String?
  city       String?
  categories String[]
  id         Int      @default(autoincrement()) @id
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt
  user       User     @relation(references: [id], fields: [userId])
  userId     Int      @unique
}

model Session {
  expiresAt          DateTime?
  handle             String    @unique
  hashedSessionToken String?
  antiCSRFToken      String?
  publicData         String?
  privateData        String?
  id                 Int       @default(autoincrement()) @id
  createdAt          DateTime  @default(now())
  updatedAt          DateTime  @updatedAt
  user               User      @relation(references: [id], fields: [userId])
  userId             Int       @unique
}

model SocialProfile {
  site           Site
  accessToken    String?
  refreshToken   String?
  extId          String?
  userName       String?
  followers      Int?
  description    String?
  conversionRate Int?
  processed      Boolean  @default(false)
  id             Int      @default(autoincrement()) @id
  createdAt      DateTime @default(now())
  updatedAt      DateTime @updatedAt
  user           User     @relation(references: [id], fields: [userId])
  userId         Int      @unique

  @@unique([userId, site, extId], map: "SocialProfile_userId_site_extId_key")
}

model Token {
  hashedToken String
  type        TokenType
  expiresAt   DateTime
  sentTo      String
  id          Int       @default(autoincrement()) @id
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt
  user        User      @relation(references: [id], fields: [userId])
  userId      Int       @unique

  @@unique([hashedToken, type])
}

model Conversation {
  requestId   Int
  description String
  title       String
  status      CitationStatus
  request     CitationRequest @relation(references: [id], fields: [requestId])
  id          Int             @default(autoincrement()) @id
  createdAt   DateTime        @default(now())
  updatedAt   DateTime        @updatedAt
  user        User            @relation(references: [id], fields: [userId])
  userId      Int             @unique
}

model Message {
  name           String?
  status         MessageStatus
  message        String
  reactionToId   Int           @unique
  reactionTo     Message?      @relation(references: [id], fields: [reactionToId])
  conversationId Int
  conversation   Conversation  @relation(references: [id], fields: [conversationId])
  id             Int           @default(autoincrement()) @id
  createdAt      DateTime      @default(now())
  updatedAt      DateTime      @updatedAt
  user           User          @relation(references: [id], fields: [userId])
  userId         Int           @unique
}

model User {
  name              String?
  email             String             @unique
  hashedPassword    String?
  nickname          String
  role              String
  photo             String             @default("")
  citationRequests  CitationRequest[]  @relation(name: "citationRequests")
  citationResponses CitationResponse[]
  profiles          Profile[]
  sessions          Session[]
  socialProfiles    SocialProfile[]
  tokens            Token[]
  messagesFromUser  Message            @relation(name: "FromUser")
  conversations     Conversation[]
  id                Int                @default(autoincrement()) @id
  createdAt         DateTime           @default(now())
  updatedAt         DateTime           @updatedAt
}

model CitationResponse {
  requestId   Int
  description String
  title       String
  status      CitationStatus
  request     CitationRequest @relation(references: [id], fields: [requestId])
  id          Int             @default(autoincrement()) @id
  createdAt   DateTime        @default(now())
  updatedAt   DateTime        @updatedAt
  user        User            @relation(references: [id], fields: [userId])
  userId      Int             @unique
}

model CitationRequest {
  userId      Int                @unique
  title       String
  description String
  categoryId  Int
  category    CitationCategory   @relation(references: [id], fields: [categoryId])
  responses   CitationResponse[]
  id          Int                @default(autoincrement()) @id
  createdAt   DateTime           @default(now())
  updatedAt   DateTime           @updatedAt
  user        User               @relation(references: [id], fields: [userId])
}

model CitationCategory {
  language  Language          @default(CS)
  name      String
  responses CitationRequest[]
  id        Int               @default(autoincrement()) @id
  createdAt DateTime          @default(now())
  updatedAt DateTime          @updatedAt
}

@ridafkih ridafkih self-assigned this Oct 18, 2022
@ridafkih
Copy link
Owner

@Daidalos117 Going to merge the changes in, let me know if there's any more issues. Will leave this open.

Should be out in version v1.7.1!

@Daidalos117
Copy link
Author

Thanks for quick fix, and sorry for long response from me! It seems ok, everything has userId as it should, thanks again 👍

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