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

feat: migration rename columns in gas_bills table #166

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions app/data/gasBillRepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ describe("gasBillRepo", () => {
const mockGasBill = 150; // Example gas bill amount

(prisma.gasBills.findFirstOrThrow as jest.Mock).mockResolvedValueOnce({
bill: mockGasBill,
kwh_cost_pence: mockGasBill,
});

const result = await gasBillRepo.getGasBillByITL3(itl);
expect(result).toBe(mockGasBill);
expect(prisma.gasBills.findFirstOrThrow).toHaveBeenCalledWith({
where: { itl: { startsWith: itl.substring(0, 3) } },
select: { bill: true },
where: { itl1: { startsWith: itl.substring(0, 3) } },
select: { kwh_cost_pence: true },
});
});

Expand Down
8 changes: 4 additions & 4 deletions app/data/gasBillRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import prisma from "./db";

const getGasBillByITL3 = async (itl: string): Promise<number> => {
try {
const { bill } = await prisma.gasBills.findFirstOrThrow({
const { kwh_cost_pence } = await prisma.gasBills.findFirstOrThrow({
where: {
itl: { startsWith: itl.substring(0, 3) },
itl1: { startsWith: itl.substring(0, 3) },
},
select: { bill: true },
select: { kwh_cost_pence: true },
});

return bill as number;
return kwh_cost_pence;
} catch (error) {
throw Error(`Data error: Unable to find gas_bills_2020 for itl3 ${itl}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- AlterTable
ALTER TABLE "gas_bills" RENAME COLUMN "bill" TO "kwh_cost_pence";
ALTER TABLE "gas_bills" RENAME COLUMN "itl" TO "itl1";
ALTER TABLE "gas_bills" RENAME COLUMN "Region" TO "region";
ALTER TABLE "gas_bills" ALTER COLUMN "kwh_cost_pence" SET NOT NULL;
ALTER TABLE "gas_bills" ALTER COLUMN "itl1" SET NOT NULL;
6 changes: 3 additions & 3 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ model SocialRent {

model GasBills {
id Int @id
region String @map("Region") @db.VarChar
itl String @db.VarChar
bill Float
region String @map("region") @db.VarChar
itl1 String @db.VarChar
kwh_cost_pence Float
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also want to map this to camelCase 👍

Suggested change
kwh_cost_pence Float
kwhCostPence Float @map("kwh_cost_pence")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing an @map here which would mean we can use camelCase not snake_case in getGasBillByITL3()

Copy link
Collaborator Author

@zz-hh-aa zz-hh-aa Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thanks for catching! Missed that one, should be fixed now at 28c4631

Excuse the strategy day multitasking brain carelessness 😅


@@map("gas_bills")
}
Loading