Skip to content

Commit

Permalink
Add script to populate greenbox table based off of player table
Browse files Browse the repository at this point in the history
I wasn't sure where to put it, so I've just left it in the root folder for now.
Obviously it won't be staying there, once I know where the right place for it is.
  • Loading branch information
soolar committed Nov 24, 2023
1 parent cefebe2 commit 777b6e1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions makegreenboxtable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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();

0 comments on commit 777b6e1

Please sign in to comment.