author avatar

amber.srivastava

Mon Oct 07 2024

To create a model in Prisma:
1. Open the schema.prisma file.
2. Define datasource and generator:


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

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


Create the model:


model Retro {
  id              String   @id @default(cuid())
  date            DateTime @default(now())   // Auto-fills current date
  scrumMasterId   String                        // For Scrum Master (User)
  slackChannel    String                        // Slack Channel input
  questions       String[]                      // Default retro questions
  projectId       Int       @relation(fields: [projectId], references: [id])
  project         Project   @relation(fields: [projectId], references: [id])
}


This creates the Retro table for your retrospectives.

@id: Marks a field as the primary key.
@default(): Sets a default value for a field.
@relation(): Defines relationships between models.
@unique: Ensures a field has unique values.
String[]: Defines an array of strings.
cuid(): Generates a unique ID.
@updatedAt: Automatically updates the field with the current timestamp when data changes.

#prisma #database #columns #model