Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data migration for Summon Mayfly Swarm #95

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
);