Skip to content

Commit

Permalink
332: Update section for 0330. (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
marklise authored Jun 13, 2024
1 parent a645aa8 commit 0df6ed3
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions migrations/20240613110810-sectionUpdates-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';
const { TABLE_NAME, dynamodb, getSubAreas } = require('../lambda/dynamoUtil');

//parks to update, section updates to be applied to every subarea within the park
const changes = [
{
"ORCS": '0330',
"section": 'Lower Mainland'
}
];

let subAreaErrors = []
let completedSubAreas = [];

exports.up = async function (dbOptions) {
console.log("------------------------------------------------------------------");
let completedParks = 0;
for (const park of changes) {
const section = park.section;

//get list of subareas for this park
const subAreas = await getSubAreas(park.ORCS);

//update section for each subarea
for (const subArea of subAreas) {
let data = {
pk: subArea.pk,
sk: subArea.sk,
section: section,
};

try {
await updateSection(data);
console.log('Updated:', subArea.subAreaName, 'section to', section);
completedSubAreas.push(subArea.subAreaName);
} catch (e) {
console.log('err:', e);
console.log('Failed to update sub area: ', subArea.subAreaName);
subAreaErrors.push(subArea.subAreaName);
}
}
completedParks++;
}
console.log("------------------------------------------------------------------");
console.log(`Successfully updated ${completedSubAreas.length} subAreas for`,completedParks,`parks.\n`);
process.stdout.write(`Failed to update ${subAreaErrors.length} subAreas.\n`);
};

async function updateSection(data) {
const updateObj = {
TableName: TABLE_NAME,
ConditionExpression: 'attribute_exists(pk) AND attribute_exists(sk)',
Key: {
pk: { S: `${data.pk}` },
sk: { S: `${data.sk}` },
},
UpdateExpression: 'set #section = :section',
ExpressionAttributeNames: {
'#section': 'section',
},
ExpressionAttributeValues: {
':section': { S: data.section },
},
};

return await dynamodb.updateItem(updateObj);
}

0 comments on commit 0df6ed3

Please sign in to comment.