はじめに
このガイドでは、Prismaを使用して「アイデアデータベース」を効率的に管理する方法について詳しく解説します。参考として、Individual(個々の人物)、JobStateMaster(作業ステータスマスター)、ThoughtEntity(思考エンティティ)などのエンティティを含むサンプルスキーマを使用します。
モデルの理解
Individualモデル
model Individual {
id Int @id @default(autoincrement())
name String
thoughts ThoughtEntity[] @relation("TranscriptionByRelation")
images ThoughtEntity[] @relation("ThumbnailByRelation")
}
このモデルでは、Individualは人物を表し、thoughtsとimagesはThoughtEntityモデルへの関連性を持っています。
JobStateMasterモデル
model JobStateMaster {
id Int @id @default(autoincrement())
status String
thoughts ThoughtEntity[]
}
このモデルでは、JobStateMasterは作業ステータスを管理し、thoughtsはThoughtEntityモデルへの関連性を持っています。
ThoughtEntityモデル
model ThoughtEntity {
id Int @id @default(autoincrement())
theme String
title String
benefits String @db.Text
youtube String
transcriptionAllowed Boolean
jobState JobStateMaster? @relation(fields: [jobStateId], references: [id])
jobStateId Int?
transcriptionDocURL String?
transcriptionScriptURL String?
scriptURL String?
mentorAchievements String?
frontendTheme String?
thumbnail String?
thoughtURL String?
transcriptionById Int?
thumbnailById Int?
transcriptionBy Individual? @relation("TranscriptionByRelation", fields: [transcriptionById], references: [id])
thumbnailBy Individual? @relation("ThumbnailByRelation", fields: [thumbnailById], references: [id])
referenceURL String?
checked Boolean @default(false)
}
ThoughtEntityモデルは最も複雑です。theme、title、benefitsなど、自己説明的なさまざまなフィールドが含まれています。


コメント