Skip to content

Commit

Permalink
Add data migration for Summon Mayfly Swarm (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
gausie committed Jun 24, 2024
1 parent 23abfa3 commit 670d8a5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/excavator-web/etl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function deleteKmails(ids: number[]) {
return text.includes(`${ids.length} messages deleted.`);
}

function hashData(data: Record<string, string | number | boolean>) {
export function hashData(data: Record<string, string | number | boolean>) {
return crypto
.createHash("md5")
.update(
Expand Down
3 changes: 2 additions & 1 deletion packages/excavator-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"start": "NODE_ENV=production node --import tsx ./server.ts",
"etl": "node --import tsx ./etl.ts",
"format": "prettier --write .",
"lint": "prettier --check ."
"lint": "prettier --check .",
"data-migration:fix-mayfly-zone": "node --import tsx ./prisma/migrations/20240624083527_fix_mayfly_zone/data-migration.ts"
},
"dependencies": {
"@chakra-ui/icons": "^2.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { PrismaClient } from "@prisma/client";

import { hashData } from "../../../etl.js";

const prisma = new PrismaClient();

async function main() {
await prisma.$transaction(async (tx) => {
const data = await tx.spadingData.findMany({
where: {
project: "Summon Mayfly Swarm",
data: {
path: ["area"],
equals: "Conspiracy Island",
},
},
});

for (const datum of data) {
await tx.spadingData.update({
where: { id: datum.id },
data: {
dataHash: hashData(
datum.data as unknown as Record<string, string | number | boolean>,
),
},
});
}
});
}

main()
.catch(async (e) => {
console.error(e);
process.exit(1);
})
.finally(async () => await prisma.$disconnect());
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Update the area of Mayfly data to be the zone instead of the location. This was only done for Conspiracy Island locations.
UPDATE "SpadingData"
SET
"data" = jsonb_set (data, '{area}', '"Conspiracy Island"')
WHERE
"project" = 'Summon Mayfly Swarm'
AND "data"->>'area' IN (
'The Secret Government Laboratory',
'The Mansion of Dr. Weirdeaux',
'The Deep Dark Jungle'
);

0 comments on commit 670d8a5

Please sign in to comment.