diff --git a/packages/kcms/.gitignore b/packages/kcms/.gitignore index c57d3aba..cb46def7 100644 --- a/packages/kcms/.gitignore +++ b/packages/kcms/.gitignore @@ -132,3 +132,5 @@ dist build/ data.json +*.db +*.db-journal diff --git a/packages/kcms/package.json b/packages/kcms/package.json index ab7ad1fb..02325321 100644 --- a/packages/kcms/package.json +++ b/packages/kcms/package.json @@ -22,11 +22,12 @@ "@hono/zod-openapi": "^0.16.0", "@hono/zod-validator": "^0.3.0", "@mikuroxina/mini-fn": "^6.0.0", + "@prisma/client": "5.20.0", + "config": "workspace:^", "esbuild": "^0.24.0", "hono": "^4.0.0", "typescript": "^5.3.2", - "zod": "^3.22.4", - "config": "workspace:^" + "zod": "^3.22.4" }, "devDependencies": { "@eslint/eslintrc": "^3.0.0", @@ -39,6 +40,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-vitest": "^0.5.0", "prettier": "^3.1.0", + "prisma": "^5.20.0", "tsx": "^4.6.2", "vitest": "^2.0.0" } diff --git a/packages/kcms/prisma/migrations/20241001112809_init/migration.sql b/packages/kcms/prisma/migrations/20241001112809_init/migration.sql new file mode 100644 index 00000000..f7f3110c --- /dev/null +++ b/packages/kcms/prisma/migrations/20241001112809_init/migration.sql @@ -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 +); diff --git a/packages/kcms/prisma/migrations/migration_lock.toml b/packages/kcms/prisma/migrations/migration_lock.toml new file mode 100644 index 00000000..e5e5c470 --- /dev/null +++ b/packages/kcms/prisma/migrations/migration_lock.toml @@ -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" \ No newline at end of file diff --git a/packages/kcms/prisma/schema.prisma b/packages/kcms/prisma/schema.prisma new file mode 100644 index 00000000..9caf2c22 --- /dev/null +++ b/packages/kcms/prisma/schema.prisma @@ -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") +} diff --git a/packages/kcms/src/team/models/team.ts b/packages/kcms/src/team/models/team.ts index 8856d0ed..46b41274 100644 --- a/packages/kcms/src/team/models/team.ts +++ b/packages/kcms/src/team/models/team.ts @@ -35,7 +35,7 @@ export class Team { private readonly members: Array; private readonly isMultiWalk: boolean; private readonly category: Department; - private readonly depatmentType: DepartmentType; + private readonly departmentType: DepartmentType; private readonly clubName?: string; private isEntered: boolean; @@ -56,7 +56,7 @@ export class Team { this.category = category; this.clubName = clubName; this.isEntered = isEntered; - this.depatmentType = departmentType; + this.departmentType = departmentType; } getId(): TeamID { @@ -83,7 +83,7 @@ export class Team { } getDepartmentType(): DepartmentType { - return this.depatmentType; + return this.departmentType; } getClubName(): string | undefined { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 15ff06da..5dba3948 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -58,6 +58,9 @@ importers: '@mikuroxina/mini-fn': specifier: ^6.0.0 version: 6.6.0 + '@prisma/client': + specifier: 5.20.0 + version: 5.20.0(prisma@5.20.0) config: specifier: workspace:^ version: link:../config @@ -104,6 +107,9 @@ importers: prettier: specifier: ^3.1.0 version: 3.3.3 + prisma: + specifier: ^5.20.0 + version: 5.20.0 tsx: specifier: ^4.6.2 version: 4.19.1 @@ -1183,6 +1189,30 @@ packages: '@polka/url@1.0.0-next.25': resolution: {integrity: sha512-j7P6Rgr3mmtdkeDGTe0E/aYyWEWVtc5yFXtHCRHs28/jptDEWfaVOc5T7cblqy1XKPPfCxJc/8DwQ5YgLOZOVQ==} + '@prisma/client@5.20.0': + resolution: {integrity: sha512-CLv55ZuMuUawMsxoqxGtLT3bEZoa2W8L3Qnp6rDIFWy+ZBrUcOFKdoeGPSnbBqxc3SkdxJrF+D1veN/WNynZYA==} + engines: {node: '>=16.13'} + peerDependencies: + prisma: '*' + peerDependenciesMeta: + prisma: + optional: true + + '@prisma/debug@5.20.0': + resolution: {integrity: sha512-oCx79MJ4HSujokA8S1g0xgZUGybD4SyIOydoHMngFYiwEwYDQ5tBQkK5XoEHuwOYDKUOKRn/J0MEymckc4IgsQ==} + + '@prisma/engines-version@5.20.0-12.06fc58a368dc7be9fbbbe894adf8d445d208c284': + resolution: {integrity: sha512-Lg8AS5lpi0auZe2Mn4gjuCg081UZf88k3cn0RCwHgR+6cyHHpttPZBElJTHf83ZGsRNAmVCZCfUGA57WB4u4JA==} + + '@prisma/engines@5.20.0': + resolution: {integrity: sha512-DtqkP+hcZvPEbj8t8dK5df2b7d3B8GNauKqaddRRqQBBlgkbdhJkxhoJTrOowlS3vaRt2iMCkU0+CSNn0KhqAQ==} + + '@prisma/fetch-engine@5.20.0': + resolution: {integrity: sha512-JVcaPXC940wOGpCOwuqQRTz6I9SaBK0c1BAyC1pcz9xBi+dzFgUu3G/p9GV1FhFs9OKpfSpIhQfUJE9y00zhqw==} + + '@prisma/get-platform@5.20.0': + resolution: {integrity: sha512-8/+CehTZZNzJlvuryRgc77hZCWrUDYd/PmlZ7p2yNXtmf2Una4BWnTbak3us6WVdqoz5wmptk6IhsXdG2v5fmA==} + '@remix-run/router@1.19.2': resolution: {integrity: sha512-baiMx18+IMuD1yyvOGaHM9QrVUPGGG0jC+z+IPHnRJWUAUvaKuWKyE8gjDj2rzv3sz9zOGoRSPgeBVHRhZnBlA==} engines: {node: '>=14.0.0'} @@ -2554,6 +2584,11 @@ packages: printable-characters@1.0.42: resolution: {integrity: sha512-dKp+C4iXWK4vVYZmYSd0KBH5F/h1HoZRsbJ82AVKRO3PEo8L4lBS/vLwhVtpwwuYcoIsVY+1JYKR268yn480uQ==} + prisma@5.20.0: + resolution: {integrity: sha512-6obb3ucKgAnsGS9x9gLOe8qa51XxvJ3vLQtmyf52CTey1Qcez3A6W6ROH5HIz5Q5bW+0VpmZb8WBohieMFGpig==} + engines: {node: '>=16.13'} + hasBin: true + prop-types@15.8.1: resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==} @@ -3851,6 +3886,31 @@ snapshots: '@polka/url@1.0.0-next.25': {} + '@prisma/client@5.20.0(prisma@5.20.0)': + optionalDependencies: + prisma: 5.20.0 + + '@prisma/debug@5.20.0': {} + + '@prisma/engines-version@5.20.0-12.06fc58a368dc7be9fbbbe894adf8d445d208c284': {} + + '@prisma/engines@5.20.0': + dependencies: + '@prisma/debug': 5.20.0 + '@prisma/engines-version': 5.20.0-12.06fc58a368dc7be9fbbbe894adf8d445d208c284 + '@prisma/fetch-engine': 5.20.0 + '@prisma/get-platform': 5.20.0 + + '@prisma/fetch-engine@5.20.0': + dependencies: + '@prisma/debug': 5.20.0 + '@prisma/engines-version': 5.20.0-12.06fc58a368dc7be9fbbbe894adf8d445d208c284 + '@prisma/get-platform': 5.20.0 + + '@prisma/get-platform@5.20.0': + dependencies: + '@prisma/debug': 5.20.0 + '@remix-run/router@1.19.2': {} '@rollup/rollup-android-arm-eabi@4.21.3': @@ -4319,7 +4379,7 @@ snapshots: sirv: 2.0.4 tinyglobby: 0.2.6 tinyrainbow: 1.2.0 - vitest: 2.1.1(@types/node@22.7.4)(@vitest/ui@2.1.1)(jsdom@25.0.1)(sugarss@4.0.1(postcss@8.4.47)) + vitest: 2.1.1(@types/node@20.16.10)(@vitest/ui@2.1.1)(jsdom@25.0.1)(sugarss@4.0.1(postcss@8.4.47)) '@vitest/utils@2.1.1': dependencies: @@ -5286,6 +5346,12 @@ snapshots: printable-characters@1.0.42: {} + prisma@5.20.0: + dependencies: + '@prisma/engines': 5.20.0 + optionalDependencies: + fsevents: 2.3.3 + prop-types@15.8.1: dependencies: loose-envify: 1.4.0