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

117 lines
3.8 KiB
MySQL
Raw Normal View History

-- CreateEnum
CREATE TYPE "MoneyUpdateType" AS ENUM ('START', '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,
"currentRunner" BOOLEAN NOT NULL DEFAULT false,
2024-12-08 12:41:37 +00:00
CONSTRAINT "Player_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),
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,
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,
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");
-- 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");
-- 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
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
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;