// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

datasource db {
  provider          = "mysql"
  url               = env("DATABASE_URL")
  shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}

model User {
  id        Int    @id @default(autoincrement())
  google_id String @unique
  email     String @unique

  categories Category[]
  links      Link[]

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@map("user")
}

model Category {
  id    Int    @id @default(autoincrement())
  name  String @db.VarChar(255)
  links Link[]

  author   User @relation(fields: [authorId], references: [id])
  authorId Int

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@map("category")
}

model Link {
  id   Int    @id @default(autoincrement())
  name String @db.VarChar(255)
  url  String @db.Text

  category   Category @relation(fields: [categoryId], references: [id])
  categoryId Int

  author   User @relation(fields: [authorId], references: [id])
  authorId Int

  favorite  Boolean  @default(false)
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  @@map("link")
}
