From ec731dc33ce0eae95e241df6355d0233985322c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Tue, 17 Dec 2024 16:56:00 +0000 Subject: [PATCH] feat: Rename `HPI` table columns, add not null constraints (#164) * feat: HPI table * fix: Drop redundant warnings in migrations --- app/data/hpiRepo.ts | 4 ++-- .../20241206165018_update_hpi_table/migration.sql | 9 +++++++++ .../20241206165140_lad_code_not_null/migration.sql | 2 ++ prisma/schema.prisma | 8 ++++---- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 prisma/migrations/20241206165018_update_hpi_table/migration.sql create mode 100644 prisma/migrations/20241206165140_lad_code_not_null/migration.sql diff --git a/app/data/hpiRepo.ts b/app/data/hpiRepo.ts index a5763ef7..8c869477 100644 --- a/app/data/hpiRepo.ts +++ b/app/data/hpiRepo.ts @@ -5,6 +5,7 @@ const getHPIByITL3 = async (itl3: string): Promise => { const { _avg: { hpi2000: averageHpi }, } = await prisma.hPI.aggregate({ + // TODO: Should there be a relationship on ITL3? where: { itl3: { endsWith: itl3, @@ -20,8 +21,7 @@ const getHPIByITL3 = async (itl3: string): Promise => { throw new Error(`Data error: Unable to find hpi2000 for itl3 ${itl3}`); } - - return averageHpi as number; + return averageHpi; } catch (error) { throw Error(`Data error: Unable to find hpi2000 for itl3 ${itl3}`); } diff --git a/prisma/migrations/20241206165018_update_hpi_table/migration.sql b/prisma/migrations/20241206165018_update_hpi_table/migration.sql new file mode 100644 index 00000000..a107f46c --- /dev/null +++ b/prisma/migrations/20241206165018_update_hpi_table/migration.sql @@ -0,0 +1,9 @@ +-- AlterTable +ALTER TABLE "hpi" +RENAME COLUMN "ladcode" TO "lad_code"; + +-- AlterTable +ALTER TABLE "hpi" +ALTER COLUMN "region" SET NOT NULL, +ALTER COLUMN "itl3" SET NOT NULL, +ALTER COLUMN "hpi_2000" SET NOT NULL; diff --git a/prisma/migrations/20241206165140_lad_code_not_null/migration.sql b/prisma/migrations/20241206165140_lad_code_not_null/migration.sql new file mode 100644 index 00000000..f95612ac --- /dev/null +++ b/prisma/migrations/20241206165140_lad_code_not_null/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "hpi" ALTER COLUMN "lad_code" SET NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 28540cdd..26b07a04 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -30,10 +30,10 @@ model GDHI { model HPI { id Int @id @default(autoincrement()) - region String? @db.VarChar(250) - itl3 String? @db.VarChar(250) - ladCode String? @map("ladcode") @db.VarChar(250) - hpi2000 Float? @map("hpi_2000") + region String @db.VarChar(250) + itl3 String @db.VarChar(250) + ladCode String @map("lad_code") @db.VarChar(250) + hpi2000 Float @map("hpi_2000") @@map("hpi") }