Skip to content

Commit

Permalink
feat: HPI table
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Dec 6, 2024
1 parent 1c6ca4b commit 2d8d250
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/data/hpiRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const getHPIByITL3 = async (itl3: string): Promise<number> => {
const {
_avg: { hpi2000: averageHpi },
} = await prisma.hPI.aggregate({
// TODO: Should there be a relationship on ITL3?
where: {
itl3: {
endsWith: itl3,
Expand All @@ -20,8 +21,7 @@ const getHPIByITL3 = async (itl3: string): Promise<number> => {
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}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 4 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 2d8d250

Please sign in to comment.