From 8be09fb751677e039319738c28beabd701ed1b53 Mon Sep 17 00:00:00 2001 From: zzhhaa Date: Thu, 12 Dec 2024 11:29:56 +0000 Subject: [PATCH 1/4] feat: rename social_rent_earnings table and cols to snake_case --- .../migration.sql | 5 +++++ .../migration.sql | 2 ++ prisma/schema.prisma | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 prisma/migrations/20241212112723_rename_social_rent_earnings/migration.sql create mode 100644 prisma/migrations/20241212112833_social_rent_earnings_rename_constraint/migration.sql diff --git a/prisma/migrations/20241212112723_rename_social_rent_earnings/migration.sql b/prisma/migrations/20241212112723_rename_social_rent_earnings/migration.sql new file mode 100644 index 00000000..8aa1900a --- /dev/null +++ b/prisma/migrations/20241212112723_rename_social_rent_earnings/migration.sql @@ -0,0 +1,5 @@ +-- Alter table +ALTER TABLE "socialrent" RENAME TO "social_rent_earnings"; + +-- Alter table +ALTER TABLE "social_rent_earnings" RENAME COLUMN "earningsperweek" TO "earnings_per_week"; \ No newline at end of file diff --git a/prisma/migrations/20241212112833_social_rent_earnings_rename_constraint/migration.sql b/prisma/migrations/20241212112833_social_rent_earnings_rename_constraint/migration.sql new file mode 100644 index 00000000..638dc61e --- /dev/null +++ b/prisma/migrations/20241212112833_social_rent_earnings_rename_constraint/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "social_rent_earnings" RENAME CONSTRAINT "socialrent_pkey" TO "social_rent_earnings_pkey"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 86e4c558..b09b42c6 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -79,13 +79,13 @@ model SocialRentAdjustments { @@map("soc_rent_adjustments") } -model SocialRent { +model SocialRentEarnings { id Int @id @default(autoincrement()) county String? @db.VarChar(250) itl3 String? @db.VarChar(250) - earningsPerWeek Float? @map("earningsperweek") + earningsPerWeek Float? @map("earnings_per_week") - @@map("socialrent") + @@map("social_rent_earnings") } model GasBills { From 46bd552179ebe8229ad66864be7b12e989c75285 Mon Sep 17 00:00:00 2001 From: zzhhaa Date: Thu, 12 Dec 2024 11:32:29 +0000 Subject: [PATCH 2/4] feat: make social_rent_earnings fields required --- .../migration.sql | 5 +++++ prisma/schema.prisma | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 prisma/migrations/20241212113106_make_social_rent_earnings_fields_required/migration.sql diff --git a/prisma/migrations/20241212113106_make_social_rent_earnings_fields_required/migration.sql b/prisma/migrations/20241212113106_make_social_rent_earnings_fields_required/migration.sql new file mode 100644 index 00000000..6089b7de --- /dev/null +++ b/prisma/migrations/20241212113106_make_social_rent_earnings_fields_required/migration.sql @@ -0,0 +1,5 @@ + +-- AlterTable +ALTER TABLE "social_rent_earnings" ALTER COLUMN "county" SET NOT NULL, +ALTER COLUMN "itl3" SET NOT NULL, +ALTER COLUMN "earnings_per_week" SET NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b09b42c6..5612bd38 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -81,9 +81,9 @@ model SocialRentAdjustments { model SocialRentEarnings { id Int @id @default(autoincrement()) - county String? @db.VarChar(250) - itl3 String? @db.VarChar(250) - earningsPerWeek Float? @map("earnings_per_week") + county String @db.VarChar(250) + itl3 String @db.VarChar(250) + earningsPerWeek Float @map("earnings_per_week") @@map("social_rent_earnings") } From bc4ddda7308e73947e256f9ac80c42442a70a3ed Mon Sep 17 00:00:00 2001 From: zzhhaa Date: Thu, 12 Dec 2024 11:35:31 +0000 Subject: [PATCH 3/4] chore: update references to social_rent_earnings --- app/data/socialRentEarningsRepo.test.ts | 8 ++++---- app/data/socialRentEarningsRepo.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/data/socialRentEarningsRepo.test.ts b/app/data/socialRentEarningsRepo.test.ts index 7093335a..11644479 100644 --- a/app/data/socialRentEarningsRepo.test.ts +++ b/app/data/socialRentEarningsRepo.test.ts @@ -18,7 +18,7 @@ describe("socialRentEarningsRepo", () => { const mockEarnings = 500; // Example average earnings // Mock the Prisma client response - (prisma.socialRent.aggregate as jest.Mock).mockResolvedValueOnce({ + (prisma.socialRentEarnings.aggregate as jest.Mock).mockResolvedValueOnce({ _avg: { earningsPerWeek: mockEarnings }, }); @@ -26,7 +26,7 @@ describe("socialRentEarningsRepo", () => { await socialRentEarningsRepo.getSocialRentEarningsByITL3(itl3); expect(result).toBe(mockEarnings); - expect(prisma.socialRent.aggregate).toHaveBeenCalledWith({ + expect(prisma.socialRentEarnings.aggregate).toHaveBeenCalledWith({ where: { itl3: { startsWith: itl3.substring(0, 3), @@ -42,7 +42,7 @@ describe("socialRentEarningsRepo", () => { const itl3 = "XYZ123"; // Mock the Prisma client response to return null for earningsPerWeek - (prisma.socialRent.aggregate as jest.Mock).mockResolvedValueOnce({ + (prisma.socialRentEarnings.aggregate as jest.Mock).mockResolvedValueOnce({ _avg: { earningsPerWeek: null }, }); @@ -57,7 +57,7 @@ describe("socialRentEarningsRepo", () => { const itl3 = "XYZ123"; // Mock the Prisma client to throw an error - (prisma.socialRent.aggregate as jest.Mock).mockRejectedValueOnce( + (prisma.socialRentEarnings.aggregate as jest.Mock).mockRejectedValueOnce( new Error("Database error") ); diff --git a/app/data/socialRentEarningsRepo.ts b/app/data/socialRentEarningsRepo.ts index 6a03aac9..7ab16191 100644 --- a/app/data/socialRentEarningsRepo.ts +++ b/app/data/socialRentEarningsRepo.ts @@ -2,7 +2,7 @@ import prisma from "./db"; const getSocialRentEarningsByITL3 = async (itl3: string): Promise => { try { - const result = await prisma.socialRent.aggregate({ + const result = await prisma.socialRentEarnings.aggregate({ where: { itl3: { startsWith: itl3.substring(0, 3), From 0807c90843f46f1d0e216fd0d9699468fb5a6004 Mon Sep 17 00:00:00 2001 From: zzhhaa Date: Fri, 13 Dec 2024 14:28:35 +0000 Subject: [PATCH 4/4] test: fix test following schema update --- app/data/socialRentEarningsRepo.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/data/socialRentEarningsRepo.test.ts b/app/data/socialRentEarningsRepo.test.ts index 11644479..f6195158 100644 --- a/app/data/socialRentEarningsRepo.test.ts +++ b/app/data/socialRentEarningsRepo.test.ts @@ -3,7 +3,7 @@ import { socialRentEarningsRepo } from "./socialRentEarningsRepo"; // Adjust the import prisma from "./db"; // Your Prisma setup file jest.mock("./db", () => ({ - socialRent: { + socialRentEarnings: { aggregate: jest.fn(), // Mock the aggregate method }, }));