Ajout structure de jeu

This commit is contained in:
2024-12-08 16:34:06 +01:00
parent 0d96b78c33
commit b93b8b4c04
12 changed files with 124 additions and 8 deletions

View File

@ -7,11 +7,19 @@ CREATE TABLE "Player" (
"name" TEXT NOT NULL,
"password" TEXT NOT NULL,
"money" INTEGER NOT NULL DEFAULT 0,
"currentRunner" BOOLEAN NOT NULL DEFAULT false,
CONSTRAINT "Player_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Game" (
"id" SERIAL NOT NULL,
"started" BOOLEAN NOT NULL DEFAULT false,
"currentRunnerId" INTEGER,
CONSTRAINT "Game_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Geolocation" (
"id" SERIAL NOT NULL,
@ -82,6 +90,9 @@ CREATE TABLE "MoneyUpdate" (
-- CreateIndex
CREATE UNIQUE INDEX "Player_name_key" ON "Player"("name");
-- CreateIndex
CREATE UNIQUE INDEX "Game_currentRunnerId_key" ON "Game"("currentRunnerId");
-- CreateIndex
CREATE UNIQUE INDEX "Challenge_title_key" ON "Challenge"("title");
@ -94,6 +105,9 @@ CREATE UNIQUE INDEX "MoneyUpdate_actionId_key" ON "MoneyUpdate"("actionId");
-- CreateIndex
CREATE UNIQUE INDEX "MoneyUpdate_tripId_key" ON "MoneyUpdate"("tripId");
-- AddForeignKey
ALTER TABLE "Game" ADD CONSTRAINT "Game_currentRunnerId_fkey" FOREIGN KEY ("currentRunnerId") REFERENCES "Player"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Geolocation" ADD CONSTRAINT "Geolocation_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -12,11 +12,18 @@ model Player {
name String @unique
password String
money Int @default(0)
currentRunner Boolean @default(false)
actions ChallengeAction[]
geolocations Geolocation[]
moneyUpdates MoneyUpdate[]
trips TrainTrip[]
runningGame Game?
}
model Game {
id Int @id @default(autoincrement())
started Boolean @default(false)
currentRunner Player? @relation(fields: [currentRunnerId], references: [id])
currentRunnerId Int? @unique
}
model Geolocation {

View File

@ -4,6 +4,7 @@ import * as bcrypt from 'bcrypt'
const prisma = new PrismaClient()
async function main() {
const game = await prisma.game.create({ data: {} })
const emmyPassword = await bcrypt.hash("Emmy", 10)
const emmy = await prisma.player.upsert({
where: { id: 1 },
@ -17,7 +18,7 @@ async function main() {
update: { name: 'Tamina' },
create: { name: 'Tamina', password: taminaPassword },
})
console.log({ emmy, tamina })
console.log({ game, emmy, tamina })
}
main()