Data Schema

Below is the prisma data model for the pro version.

model Account {
  id                String  @id @default(cuid())
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String? @db.Text
  access_token      String? @db.Text
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String? @db.Text
  session_state     String?

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
  @@map(name: "accounts")
}

model Session {
  id           String   @id @default(cuid())
  sessionToken String   @unique
  userId       String
  expires      DateTime
  user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@map(name: "sessions")
}

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String    @unique
  emailVerified DateTime?
  image         String?
  accounts      Account[]
  sessions      Session[]
  display_name  String?   @db.VarChar

  todo         Todo[]
  Role         Role[]
  Organization Organization[]

  @@unique([id, email])
  @@map(name: "users")
}


model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
  @@map(name: "verification_tokens")
}


model Subscription {
  id             String         @id @unique
  price_id       String
  status         String
  period_ends_at DateTime       @db.Timestamp(6)
  Organization   Organization[]

  @@map(name: "subscriptions")
}


model Todo {
  id           String        @id @default(cuid())
  title        String        @db.VarChar
  description  String        @db.VarChar
  user_id      String
  org_id       String
  author       String?       @db.VarChar
  user         User?         @relation(fields: [user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
  organization Organization? @relation(fields: [org_id], references: [id], onDelete: Cascade, onUpdate: NoAction)

  @@map(name: "todos")
}


model Organization {
  id                 String  @id @default(cuid())
  name               String  @db.VarChar
  owner_user_id      String
  customer_id         Int? @unique 
  subscription_id    String?

  user         User?         @relation(fields: [owner_user_id], references: [id], onDelete: Cascade, onUpdate: NoAction)
  subscription Subscription? @relation(fields: [subscription_id], references: [id], onUpdate: NoAction)
  Role         Role[]
  Todo         Todo[]
  Invite       Invite[]

  @@unique([id, name])
  @@map(name: "organizations")
}


model Role {
  id       String @id @default(cuid())
  org_id   String
  org_name String
  user_id  String
  email    String
  role String @db.VarChar

  organization Organization? @relation(fields: [org_id, org_name], references: [id, name], onUpdate: NoAction)
  user         User?         @relation(fields: [user_id, email], references: [id, email], onUpdate: NoAction)

  @@map(name: "roles")
}


model Invite {
  id       String @id @default(cuid())
  org_id   String
  email String
  role String @db.VarChar

  organization Organization? @relation(fields: [org_id], references: [id], onUpdate: NoAction)
  @@map(name: "invites")
}