From 3439fe7b0279e1e51cafacb4b4361490c6c10b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 6 Dec 2024 16:20:35 +0000 Subject: [PATCH 1/3] feat: Rename `build_prices` table, make not null --- .../migration.sql | 13 +++++++++++++ .../20241206161309_rename_constraint/migration.sql | 2 ++ .../migration.sql | 14 ++++++++++++++ prisma/schema.prisma | 10 +++++----- 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 prisma/migrations/20241206160747_update_build_prices_names/migration.sql create mode 100644 prisma/migrations/20241206161309_rename_constraint/migration.sql create mode 100644 prisma/migrations/20241206161734_make_build_prices_fields_required/migration.sql diff --git a/prisma/migrations/20241206160747_update_build_prices_names/migration.sql b/prisma/migrations/20241206160747_update_build_prices_names/migration.sql new file mode 100644 index 0000000..510c097 --- /dev/null +++ b/prisma/migrations/20241206160747_update_build_prices_names/migration.sql @@ -0,0 +1,13 @@ +/* + Warnings: + + - You are about to drop the `buildprices` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- Alter table +ALTER TABLE "buildprices" RENAME TO "build_prices"; + +-- Alter table +ALTER TABLE "build_prices" RENAME COLUMN "housetype" TO "house_type"; +ALTER TABLE "build_prices" RENAME COLUMN "pricerange" TO "price_range"; +ALTER TABLE "build_prices" RENAME COLUMN "pricemid" TO "price_mid"; \ No newline at end of file diff --git a/prisma/migrations/20241206161309_rename_constraint/migration.sql b/prisma/migrations/20241206161309_rename_constraint/migration.sql new file mode 100644 index 0000000..66c72c3 --- /dev/null +++ b/prisma/migrations/20241206161309_rename_constraint/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "build_prices" RENAME CONSTRAINT "buildprices_pkey" TO "build_prices_pkey"; diff --git a/prisma/migrations/20241206161734_make_build_prices_fields_required/migration.sql b/prisma/migrations/20241206161734_make_build_prices_fields_required/migration.sql new file mode 100644 index 0000000..306940c --- /dev/null +++ b/prisma/migrations/20241206161734_make_build_prices_fields_required/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - Made the column `house_type_description` on table `build_prices` required. This step will fail if there are existing NULL values in that column. + - Made the column `house_type` on table `build_prices` required. This step will fail if there are existing NULL values in that column. + - Made the column `price_range` on table `build_prices` required. This step will fail if there are existing NULL values in that column. + - Made the column `price_mid` on table `build_prices` required. This step will fail if there are existing NULL values in that column. + +*/ +-- AlterTable +ALTER TABLE "build_prices" ALTER COLUMN "house_type_description" SET NOT NULL, +ALTER COLUMN "house_type" SET NOT NULL, +ALTER COLUMN "price_range" SET NOT NULL, +ALTER COLUMN "price_mid" SET NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 86e4c55..7743124 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -10,12 +10,12 @@ datasource db { model BuildPrices { id Int @id @default(autoincrement()) - houseTypeDescription String? @map("house_type_description") @db.VarChar(250) - houseType String? @map("housetype") @db.VarChar(1) - priceRange String? @map("pricerange") @db.VarChar(50) - priceMid Float? @map("pricemid") + houseTypeDescription String @map("house_type_description") @db.VarChar(250) + houseType String @map("house_type") @db.VarChar(1) + priceRange String @map("price_range") @db.VarChar(50) + priceMid Float @map("price_mid") - @@map("buildprices") + @@map("build_prices") } model GDHI { From 30841abd384ca9c605e43f4ff99e4c3e25db4f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 6 Dec 2024 16:22:59 +0000 Subject: [PATCH 2/3] fix: Update code now that field in non-nullable --- app/data/buildPriceRepo.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/data/buildPriceRepo.ts b/app/data/buildPriceRepo.ts index 6bc2221..b32afbe 100644 --- a/app/data/buildPriceRepo.ts +++ b/app/data/buildPriceRepo.ts @@ -9,8 +9,7 @@ const getBuildPriceByHouseType = async (houseType: string): Promise => { select: { priceMid: true }, }); - // Cast to string as 'not: null' clause in Prisma query does not type narrow - return buildPrice as number; + return buildPrice; } catch (error) { throw new Error( `Data error: Unable to get buildPrice for houseType ${houseType}` From ced8b008d76d8de52e3701e8633de730d6e7b107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 6 Dec 2024 17:04:11 +0000 Subject: [PATCH 3/3] fix: Drop redundant warning --- .../20241206160747_update_build_prices_names/migration.sql | 6 ------ 1 file changed, 6 deletions(-) diff --git a/prisma/migrations/20241206160747_update_build_prices_names/migration.sql b/prisma/migrations/20241206160747_update_build_prices_names/migration.sql index 510c097..888cc31 100644 --- a/prisma/migrations/20241206160747_update_build_prices_names/migration.sql +++ b/prisma/migrations/20241206160747_update_build_prices_names/migration.sql @@ -1,9 +1,3 @@ -/* - Warnings: - - - You are about to drop the `buildprices` table. If the table is not empty, all the data it contains will be lost. - -*/ -- Alter table ALTER TABLE "buildprices" RENAME TO "build_prices";