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: Rename HPI table columns, add not null constraints #164

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not quite sure what you mean by this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One to talk through next week and add to the backlog I think. We're currently just string matching on the start/end of an itl3 in multiple tables.

What we might actually want to model is an ITL3 table, with relationships to other tables. This would be more efficient when it comes to queries and allow us to join multiple tables. Something like this maybe?

model Itl3 {
  id          Int       @id @default(autoincrement())
  code        String    @unique @db.VarChar(250)
  name        String    @db.VarChar(250)
  
  // Relationships
  GDHI        GDHI[]
  HPI         HPI[]
  Rent        Rent[]
  SocialRentEarnings SocialRentEarnings[]
  GasBills    GasBills[]
  ItlLookup   ItlLookup[]

  @@map("itl3")
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I see what you mean! Will make a note and we can talk through it at next dev call :)

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,2 @@
-- 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
Loading