-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Prismaのスキーマ定義とマイグレーションの用意 (#363)
* feat: prismaのスキーマを書いた * feat: マイグレーションを生成した
- Loading branch information
Showing
7 changed files
with
203 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,3 +132,5 @@ dist | |
|
||
build/ | ||
data.json | ||
*.db | ||
*.db-journal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/kcms/prisma/migrations/20241001112809_init/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- CreateTable | ||
CREATE TABLE "Team" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"name" TEXT NOT NULL, | ||
"robot_type" TEXT NOT NULL, | ||
"department" TEXT NOT NULL, | ||
"club_name" TEXT, | ||
"is_entered" BOOLEAN NOT NULL | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "main_match" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"course_index" INTEGER NOT NULL, | ||
"match_index" INTEGER NOT NULL, | ||
"left_team_id" TEXT, | ||
"right_team_id" TEXT, | ||
"winner_team_id" TEXT, | ||
CONSTRAINT "main_match_left_team_id_fkey" FOREIGN KEY ("left_team_id") REFERENCES "Team" ("id") ON DELETE SET NULL ON UPDATE CASCADE, | ||
CONSTRAINT "main_match_right_team_id_fkey" FOREIGN KEY ("right_team_id") REFERENCES "Team" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "pre_match" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"course_index" INTEGER NOT NULL, | ||
"match_index" INTEGER NOT NULL, | ||
"left_team_id" TEXT, | ||
"right_team_id" TEXT, | ||
CONSTRAINT "pre_match_left_team_id_fkey" FOREIGN KEY ("left_team_id") REFERENCES "Team" ("id") ON DELETE SET NULL ON UPDATE CASCADE, | ||
CONSTRAINT "pre_match_right_team_id_fkey" FOREIGN KEY ("right_team_id") REFERENCES "Team" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "run_result" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"points" INTEGER NOT NULL, | ||
"goal_time_seconds" INTEGER NOT NULL, | ||
"finish_state" INTEGER NOT NULL, | ||
"team_id" TEXT NOT NULL, | ||
"main_match_id" TEXT, | ||
"pre_match_id" TEXT, | ||
CONSTRAINT "run_result_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team" ("id") ON DELETE RESTRICT ON UPDATE CASCADE, | ||
CONSTRAINT "run_result_main_match_id_fkey" FOREIGN KEY ("main_match_id") REFERENCES "main_match" ("id") ON DELETE SET NULL ON UPDATE CASCADE, | ||
CONSTRAINT "run_result_pre_match_id_fkey" FOREIGN KEY ("pre_match_id") REFERENCES "pre_match" ("id") ON DELETE SET NULL ON UPDATE CASCADE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "sqlite" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? | ||
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = "file:./kcmsx.db" | ||
} | ||
|
||
model Team { | ||
id String @id | ||
name String | ||
robotType String @map("robot_type") | ||
department String | ||
clubName String? @map("club_name") | ||
isEntered Boolean @map("is_entered") | ||
runResult RunResult[] | ||
mainLeftTeams MainMatch[] @relation("main_left_team") | ||
mainRightTeams MainMatch[] @relation("main_right_team") | ||
preLeftTeams PreMatch[] @relation("pre_left_team") | ||
preRightTeams PreMatch[] @relation("pre_right_team") | ||
} | ||
|
||
model MainMatch { | ||
id String @id | ||
courseIndex Int @map("course_index") | ||
matchIndex Int @map("match_index") | ||
leftTeamId String? @map("left_team_id") | ||
leftTeam Team? @relation("main_left_team", fields: [leftTeamId], references: [id]) | ||
rightTeamId String? @map("right_team_id") | ||
rightTeam Team? @relation("main_right_team", fields: [rightTeamId], references: [id]) | ||
// NOTE: アプリケーション側を信用するのでここはリレーションを作らないことにした (PreMatchも同様) | ||
winnerTeamId String? @map("winner_team_id") | ||
runResult RunResult[] | ||
@@map("main_match") | ||
} | ||
|
||
model PreMatch { | ||
id String @id | ||
courseIndex Int @map("course_index") | ||
matchIndex Int @map("match_index") | ||
leftTeamID String? @map("left_team_id") | ||
leftTeam Team? @relation("pre_left_team", fields: [leftTeamID], references: [id]) | ||
rightTeamID String? @map("right_team_id") | ||
rightTeam Team? @relation("pre_right_team", fields: [rightTeamID], references: [id]) | ||
runResult RunResult[] | ||
@@map("pre_match") | ||
} | ||
|
||
model RunResult { | ||
id String @id | ||
points Int | ||
goalTimeSeconds Int @map("goal_time_seconds") | ||
finishState Int @map("finish_state") | ||
team Team @relation(fields: [teamID], references: [id]) | ||
teamID String @map("team_id") | ||
mainMatch MainMatch? @relation(fields: [mainMatchId], references: [id]) | ||
mainMatchId String? @map("main_match_id") | ||
preMatch PreMatch? @relation(fields: [preMatchId], references: [id]) | ||
preMatchId String? @map("pre_match_id") | ||
@@map("run_result") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.