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 build_prices table, make fields non-nullable #162

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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,13 @@
/*
Warnings:

- You are about to drop the `buildprices` table. If the table is not empty, all the data it contains will be lost.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should warnings be removed after the query is updated to use RENAME instead of DROP?

Copy link
Contributor Author

@DafyddLlyr DafyddLlyr Dec 6, 2024

Choose a reason for hiding this comment

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

Good spot thanks - yes! We should keep relevant warnings (very good for PRs) but remove redundant/incorrect ones. I'll fix this shortly 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see ced8b00


*/
-- 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
Loading