Skip to content

Commit

Permalink
removing all instances of old measure table
Browse files Browse the repository at this point in the history
  • Loading branch information
angelaco11 committed Sep 20, 2024
1 parent ee41519 commit af6c516
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion services/app-api/handlers/coreSets/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const deleteDependentMeasures = async (
TableName: process.env.measureTable!,
Key: {
compoundKey: `${state}${year}${coreSet}`,
coreSet: coreSet,
measure: measure,
},
};

Expand Down
1 change: 0 additions & 1 deletion services/app-api/handlers/measures/tests/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jest.mock("../../../libs/authorization", () => ({
}));

const event = { ...testEvent };
process.env.measureTableName = "SAMPLE TABLE";

describe("Test Create Measure Handler", () => {
beforeEach(() => {
Expand Down
1 change: 0 additions & 1 deletion services/app-api/handlers/measures/tests/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jest.mock("../../dynamoUtils/convertToDynamoExpressionVars", () => ({
}));

const event = { ...testEvent };
process.env.measureTableName = "SAMPLE TABLE";
process.env.measureTable = "SAMPLE TABLE";

describe("Test Get Measure Handlers", () => {
Expand Down
8 changes: 4 additions & 4 deletions services/app-api/storage/table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const mockCombinedRate = {

describe("Test database helper functions", () => {
beforeAll(() => {
process.env.measureTableName = "local-measures";
process.env.measureTable = "local-measure";
process.env.rateTableName = "local-rates";
});

Expand All @@ -72,10 +72,10 @@ describe("Test database helper functions", () => {

expect(result).toBe(mockMeasure);
expect(dynamodbLib.get).toHaveBeenCalledWith({
TableName: "local-measures",
TableName: "local-measure",
Key: {
compoundKey: "CO2024ACSZZZ-AD",
coreSet: "ACS",
compoundKey: "CO2024ACS",
measure: "ZZZ-AD",
},
});
});
Expand Down
6 changes: 3 additions & 3 deletions services/app-api/storage/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { RateParameters, CombinedRatesPayload } from "../types";
export const getMeasureFromTable = async (parameters: RateParameters) => {
const { state, year, coreSet, measure } = parameters;
return await dynamoDb.get<Types.Measure>({
TableName: process.env.measureTableName,
TableName: process.env.measureTable,
Key: {
compoundKey: `${state}${year}${coreSet}${measure}`,
coreSet: coreSet,
compoundKey: `${state}${year}${coreSet}`,
measure: measure,
},
});
};
Expand Down
11 changes: 8 additions & 3 deletions services/database/scripts/transformMeasureTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ import {
} from "@aws-sdk/lib-dynamodb";
import prompt from "prompt-sync";

/***
* Run with `npx tsx transformMeasureTable.ts`
*/
const transformMeasureTable = async () => {
let stage = "local";
const isLocal = !!process.env.DYNAMODB_URL;
const dbClient = buildClient(isLocal);
const p = prompt();
const runLocally = p("Do you want to run this script locally? Y/N: ");
const isLocal = runLocally === "Y" ? true : false;
if (!isLocal) {
stage = p("What environment would you like to modify: ");
stage = p("What environment are we running on (e.g. master, val, prod)? ");
}

const dbClient = buildClient(isLocal);

const oldTable = `${stage}-measures`;
const newTable = `${stage}-measure`;
console.log(`Processing table ${oldTable}`);
Expand Down
2 changes: 1 addition & 1 deletion services/uploads/src/dynamoSync/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const uploadFileToS3 = async (filePath, scanResult) => {

const syncDynamoToS3 = handler(async (_event, _context) => {
console.log("Syncing Dynamo to Uploads");
const measureResults = await scanAll(process.env.measureTableName);
const measureResults = await scanAll(process.env.measureTable);
const coreSetResults = await scanAll(process.env.coreSetTableName);
const rateResults = await scanAll(process.env.rateTableName);

Expand Down

0 comments on commit af6c516

Please sign in to comment.