traintrape-moi/server/prisma/migrations/20241208192715_init/migration.sql

163 lines
5.5 KiB
MySQL
Raw Permalink Normal View History

-- CreateEnum
CREATE TYPE "MoneyUpdateType" AS ENUM ('START', 'NEW_RUN', 'WIN_CHALLENGE', 'BUY_TRAIN');
-- CreateTable
2024-12-08 12:41:37 +00:00
CREATE TABLE "Player" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
2024-12-07 12:06:15 +00:00
"password" TEXT NOT NULL,
"money" INTEGER NOT NULL DEFAULT 0,
2024-12-08 12:41:37 +00:00
CONSTRAINT "Player_pkey" PRIMARY KEY ("id")
);
2024-12-08 15:34:06 +00:00
-- CreateTable
CREATE TABLE "Game" (
"id" SERIAL NOT NULL,
"started" BOOLEAN NOT NULL DEFAULT false,
"currentRunId" INTEGER,
2024-12-08 15:34:06 +00:00
CONSTRAINT "Game_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "PlayerRun" (
"id" SERIAL NOT NULL,
"gameId" INTEGER NOT NULL,
"runnerId" INTEGER NOT NULL,
"start" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"end" TIMESTAMPTZ(3),
CONSTRAINT "PlayerRun_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Geolocation" (
"id" SERIAL NOT NULL,
2024-12-08 12:41:37 +00:00
"playerId" INTEGER NOT NULL,
"longitude" DOUBLE PRECISION NOT NULL,
"latitude" DOUBLE PRECISION NOT NULL,
2024-12-08 12:41:37 +00:00
"speed" DOUBLE PRECISION NOT NULL,
"accuracy" DOUBLE PRECISION NOT NULL,
"altitude" DOUBLE PRECISION NOT NULL,
"altitudeAccuracy" DOUBLE PRECISION NOT NULL,
"timestamp" TIMESTAMPTZ(3) NOT NULL,
CONSTRAINT "Geolocation_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "Challenge" (
"id" SERIAL NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"reward" INTEGER NOT NULL,
CONSTRAINT "Challenge_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "ChallengeAction" (
"id" SERIAL NOT NULL,
2024-12-08 12:41:37 +00:00
"playerId" INTEGER NOT NULL,
"challengeId" INTEGER NOT NULL,
"active" BOOLEAN NOT NULL DEFAULT false,
"success" BOOLEAN NOT NULL DEFAULT false,
2024-12-08 12:41:37 +00:00
"start" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"end" TIMESTAMPTZ(3),
"penaltyStart" TIMESTAMPTZ(3),
"penaltyEnd" TIMESTAMPTZ(3),
"runId" INTEGER NOT NULL,
CONSTRAINT "ChallengeAction_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "TrainTrip" (
"id" TEXT NOT NULL,
2024-12-08 12:41:37 +00:00
"playerId" INTEGER NOT NULL,
"distance" DOUBLE PRECISION NOT NULL,
"from" TEXT NOT NULL,
"to" TEXT NOT NULL,
2024-12-08 12:41:37 +00:00
"departureTime" TIMESTAMPTZ(3) NOT NULL,
"arrivalTime" TIMESTAMPTZ(3) NOT NULL,
"infoJson" JSONB NOT NULL,
"runId" INTEGER NOT NULL,
CONSTRAINT "TrainTrip_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "MoneyUpdate" (
"id" SERIAL NOT NULL,
2024-12-08 12:41:37 +00:00
"playerId" INTEGER NOT NULL,
"amount" INTEGER NOT NULL,
"reason" "MoneyUpdateType" NOT NULL,
"actionId" INTEGER,
"tripId" TEXT,
"runId" INTEGER,
2024-12-08 12:41:37 +00:00
"timestamp" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "MoneyUpdate_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
2024-12-08 12:41:37 +00:00
CREATE UNIQUE INDEX "Player_name_key" ON "Player"("name");
2024-12-08 15:34:06 +00:00
-- CreateIndex
CREATE UNIQUE INDEX "Game_currentRunId_key" ON "Game"("currentRunId");
2024-12-08 15:34:06 +00:00
-- CreateIndex
CREATE UNIQUE INDEX "Challenge_title_key" ON "Challenge"("title");
-- CreateIndex
CREATE UNIQUE INDEX "ChallengeAction_challengeId_key" ON "ChallengeAction"("challengeId");
-- CreateIndex
CREATE UNIQUE INDEX "MoneyUpdate_actionId_key" ON "MoneyUpdate"("actionId");
-- CreateIndex
CREATE UNIQUE INDEX "MoneyUpdate_tripId_key" ON "MoneyUpdate"("tripId");
-- CreateIndex
CREATE UNIQUE INDEX "MoneyUpdate_runId_key" ON "MoneyUpdate"("runId");
2024-12-08 15:34:06 +00:00
-- AddForeignKey
ALTER TABLE "Game" ADD CONSTRAINT "Game_currentRunId_fkey" FOREIGN KEY ("currentRunId") REFERENCES "PlayerRun"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PlayerRun" ADD CONSTRAINT "PlayerRun_gameId_fkey" FOREIGN KEY ("gameId") REFERENCES "Game"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "PlayerRun" ADD CONSTRAINT "PlayerRun_runnerId_fkey" FOREIGN KEY ("runnerId") REFERENCES "Player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
2024-12-08 15:34:06 +00:00
-- AddForeignKey
2024-12-08 12:41:37 +00:00
ALTER TABLE "Geolocation" ADD CONSTRAINT "Geolocation_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ChallengeAction" ADD CONSTRAINT "ChallengeAction_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ChallengeAction" ADD CONSTRAINT "ChallengeAction_challengeId_fkey" FOREIGN KEY ("challengeId") REFERENCES "Challenge"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ChallengeAction" ADD CONSTRAINT "ChallengeAction_runId_fkey" FOREIGN KEY ("runId") REFERENCES "PlayerRun"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
2024-12-08 12:41:37 +00:00
ALTER TABLE "TrainTrip" ADD CONSTRAINT "TrainTrip_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "TrainTrip" ADD CONSTRAINT "TrainTrip_runId_fkey" FOREIGN KEY ("runId") REFERENCES "PlayerRun"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
2024-12-08 12:41:37 +00:00
ALTER TABLE "MoneyUpdate" ADD CONSTRAINT "MoneyUpdate_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "MoneyUpdate" ADD CONSTRAINT "MoneyUpdate_actionId_fkey" FOREIGN KEY ("actionId") REFERENCES "ChallengeAction"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "MoneyUpdate" ADD CONSTRAINT "MoneyUpdate_tripId_fkey" FOREIGN KEY ("tripId") REFERENCES "TrainTrip"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "MoneyUpdate" ADD CONSTRAINT "MoneyUpdate_runId_fkey" FOREIGN KEY ("runId") REFERENCES "PlayerRun"("id") ON DELETE SET NULL ON UPDATE CASCADE;