Skip to content

Commit

Permalink
feat: Rename build_prices table, make fields non-nullable (#162)
Browse files Browse the repository at this point in the history
* feat: Rename `build_prices` table, make not null

* fix: Update code now that field in non-nullable

* fix: Drop redundant warning
  • Loading branch information
DafyddLlyr authored Dec 13, 2024
1 parent 0e9965a commit 6312e95
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
3 changes: 1 addition & 2 deletions app/data/buildPriceRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const getBuildPriceByHouseType = async (houseType: string): Promise<number> => {
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}`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- 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";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "build_prices" RENAME CONSTRAINT "buildprices_pkey" TO "build_prices_pkey";
Original file line number Diff line number Diff line change
@@ -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;
10 changes: 5 additions & 5 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6312e95

Please sign in to comment.