diff --git a/makegreenboxtable.ts b/makegreenboxtable.ts deleted file mode 100644 index b133ea2..0000000 --- a/makegreenboxtable.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { prisma } from "./src/clients/database.js"; - -export async function makeGreenboxes() { - try { - const playersWithGreenbox = await prisma.player.findMany({ - where: { - greenboxString: { not: null }, - greenboxLastUpdate: { not: null }, - }, - select: { - playerId: true, - greenboxString: true, - greenboxLastUpdate: true, - }, - orderBy: { playerId: "asc" }, - }); - await prisma.greenbox.createMany({ - data: playersWithGreenbox.map((data) => { - return { - playerId: data.playerId, - data: data.greenboxString, - time: data.greenboxLastUpdate, - }; - }), - }); - } catch (error) { - console.log(error); - } -} - -makeGreenboxes(); diff --git a/prisma/migrations/20231124193505_greenbox_history/migration.sql b/prisma/migrations/20231124193505_greenbox_history/migration.sql index 9caa1b3..f3971ed 100644 --- a/prisma/migrations/20231124193505_greenbox_history/migration.sql +++ b/prisma/migrations/20231124193505_greenbox_history/migration.sql @@ -10,3 +10,8 @@ CREATE TABLE "Greenbox" ( -- AddForeignKey ALTER TABLE "Greenbox" ADD CONSTRAINT "Greenbox_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("playerId") ON DELETE RESTRICT ON UPDATE CASCADE; + +INSERT INTO "Greenbox" ("playerId", "data", "time") +SELECT "playerId", "greenboxString" as "data", "greenboxLastUpdate" as "time" +FROM "Player" +WHERE "greenboxString" IS NOT NULL AND "greenboxLastUpdate" IS NOT NULL;