Skip to content

Commit

Permalink
cleaning up script
Browse files Browse the repository at this point in the history
  • Loading branch information
angelaco11 committed Sep 17, 2024
1 parent c58a3e1 commit 65b7bb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
8 changes: 1 addition & 7 deletions services/app-api/handlers/measures/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,14 @@ export const listMeasures = handler(async (event, context) => {
}
} // if not state user, can safely assume admin type user due to baseline handler protections
const params = {
TableName: process.env.measureTable, // TODO: change this back to use env variable
// ...convertToDynamoExpression(
// { state: state, year: parseInt(year), coreSet: coreSet },
// "list"
// ),
TableName: process.env.measureTable,
KeyConditionExpression: "compoundKey = :compoundKey",
ExpressionAttributeValues: {
":compoundKey": `${state}${parseInt(year)}${coreSet}`,
},
};

console.log("PARAMS", params);
const queriedMeasures = await dynamoDb.queryAll<Measure>(params);
console.log("QUERIED MEASURES", queriedMeasures);
for (let v of queriedMeasures) {
const measure = measures[parseInt(year as string)]?.filter(
(m) => m.measure === (v as Measure)?.measure
Expand Down
21 changes: 14 additions & 7 deletions services/database/scripts/transformMeasureTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import {
paginateScan,
PutCommand,
} from "@aws-sdk/lib-dynamodb";
import prompt from "prompt-sync";

const transformMeasureTable = async () => {
const dbClient = buildClient(true);
const tableName = "local-measures";
const newTableName = "local-measure";
console.log(`Processing table ${tableName}`);
for await (let entry of scan(dbClient, tableName)) {
add(dbClient, newTableName, entry);
let stage = "local";
const isLocal = !!process.env.DYNAMODB_URL;
const dbClient = buildClient(isLocal);
const p = prompt();
if (!isLocal) {
stage = p("What environment would you like to modify: ");
}

const oldTable = `${stage}-measures`;
const newTable = `${stage}-measure`;
console.log(`Processing table ${oldTable}`);
for await (let entry of scan(dbClient, oldTable)) {
add(dbClient, newTable, entry);
}
};

Expand All @@ -33,7 +41,6 @@ async function add(client: DynamoDBDocumentClient, table: string, entry: any) {
compoundKey: newCompoundKey,
},
};
console.log("ADDING:", entry);
await client.send(new PutCommand(params));
}

Expand Down

0 comments on commit 65b7bb2

Please sign in to comment.