From 2d8d250daa0ea520e4e2f19641b8f2934b66cd92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 6 Dec 2024 16:53:42 +0000 Subject: [PATCH] feat: HPI table --- app/data/hpiRepo.ts | 4 ++-- .../20241206165018_update_hpi_table/migration.sql | 9 +++++++++ .../20241206165140_lad_code_not_null/migration.sql | 8 ++++++++ prisma/schema.prisma | 8 ++++---- 4 files changed, 23 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..39d4590a --- /dev/null +++ b/prisma/migrations/20241206165140_lad_code_not_null/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - Made the column `lad_code` on table `hpi` required. This step will fail if there are existing NULL values in that column. + +*/ +-- AlterTable +ALTER TABLE "hpi" ALTER COLUMN "lad_code" SET NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 172cc349..c0aeda50 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") }