From 1c6ca4b3f97ae1493a2934735bc34201fdb1114f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 6 Dec 2024 16:45:44 +0000 Subject: [PATCH] feat: Rename gdhi tables, add not null constraints --- app/data/gdhiRepo.ts | 4 +--- .../20241206162843_rename_ghdi_table/migration.sql | 10 ++++++++++ prisma/schema.prisma | 8 ++++---- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 prisma/migrations/20241206162843_rename_ghdi_table/migration.sql diff --git a/app/data/gdhiRepo.ts b/app/data/gdhiRepo.ts index bcc42faf..8146136a 100644 --- a/app/data/gdhiRepo.ts +++ b/app/data/gdhiRepo.ts @@ -6,14 +6,12 @@ const getGDHI2020ByITL3 = async (itl3: string): Promise => { where: { AND: { itl3: { equals: itl3 }, - // TODO: Add `NOT NULL` constraint to column - gdhi2020: { not: null }, }, }, select: { gdhi2020: true }, }); - return gdhi2020 as number; + return gdhi2020; } catch (error) { throw Error(`Data error: Unable to find gdhi2020 for itl3 ${itl3}`); } diff --git a/prisma/migrations/20241206162843_rename_ghdi_table/migration.sql b/prisma/migrations/20241206162843_rename_ghdi_table/migration.sql new file mode 100644 index 00000000..d297f6d9 --- /dev/null +++ b/prisma/migrations/20241206162843_rename_ghdi_table/migration.sql @@ -0,0 +1,10 @@ +-- AlterTable +ALTER TABLE "gdhi" +RENAME COLUMN "itllevel" TO "itl_level"; + +-- AlterTable +ALTER TABLE "gdhi" +ALTER COLUMN "itl_level" SET NOT NULL, +ALTER COLUMN "itl3" SET NOT NULL, +ALTER COLUMN "region" SET NOT NULL, +ALTER COLUMN "gdhi_2020" SET NOT NULL; \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 77431245..172cc349 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -20,10 +20,10 @@ model BuildPrices { model GDHI { id Int @id @default(autoincrement()) - itlLevel String? @map("itllevel") @db.VarChar(250) - itl3 String? @db.VarChar(250) - region String? @db.VarChar(250) - gdhi2020 Float? @map("gdhi_2020") + itlLevel String @map("itl_level") @db.VarChar(250) + itl3 String @db.VarChar(250) + region String @db.VarChar(250) + gdhi2020 Float @map("gdhi_2020") @@map("gdhi") }