mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-30 12:55:02 +00:00
Added index to ensure combinations of uprn and portfolio id remain unique
This commit is contained in:
parent
ee022b83c4
commit
4a899c27dc
4 changed files with 4906 additions and 29 deletions
1
src/app/db/migrations/0138_neat_havok.sql
Normal file
1
src/app/db/migrations/0138_neat_havok.sql
Normal file
|
|
@ -0,0 +1 @@
|
|||
CREATE UNIQUE INDEX "uq_property_portfolio_uprn" ON "property" USING btree ("portfolio_id","uprn") WHERE "property"."uprn" IS NOT NULL;
|
||||
4850
src/app/db/migrations/meta/0138_snapshot.json
Normal file
4850
src/app/db/migrations/meta/0138_snapshot.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -967,6 +967,13 @@
|
|||
"when": 1765400667595,
|
||||
"tag": "0137_shallow_speedball",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 138,
|
||||
"version": "7",
|
||||
"when": 1766319125106,
|
||||
"tag": "0138_neat_havok",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -9,10 +9,12 @@ import {
|
|||
boolean,
|
||||
smallint,
|
||||
bigint,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { portfolio, PortfolioStatus } from "./portfolio";
|
||||
import { InferModel } from "drizzle-orm";
|
||||
import { materialTypeEnum } from "./materials";
|
||||
import { sql } from "drizzle-orm";
|
||||
|
||||
// This is a placeholder for the property schema
|
||||
export interface PropertyMeta {
|
||||
|
|
@ -91,35 +93,52 @@ export const propertyCreationStatusEnum = pgEnum(
|
|||
export const epcEnum = pgEnum("epc", Epc);
|
||||
export const propertyStatusEnum = pgEnum("status", PortfolioStatus);
|
||||
|
||||
export const property = pgTable("property", {
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
portfolioId: bigint("portfolio_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => portfolio.id),
|
||||
creationStatus: propertyCreationStatusEnum("creation_status").notNull(),
|
||||
uprn: bigint("uprn", { mode: "bigint" }),
|
||||
landlordPropertyId: text("landlord_property_id"), // Optional ID used by landlords
|
||||
buildingReferenceNumber: bigint("building_reference_number", {
|
||||
mode: "bigint",
|
||||
}),
|
||||
status: propertyStatusEnum("status"),
|
||||
address: text("address"),
|
||||
postcode: text("postcode"),
|
||||
hasPreConditionReport: boolean("has_pre_condition_report"),
|
||||
hasRecommendations: boolean("has_recommendations"),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||
propertyType: text("property_type"),
|
||||
builtForm: text("built_form"),
|
||||
localAuthority: text("local_authority"),
|
||||
constituency: text("constituency"),
|
||||
numberOfRooms: integer("number_of_rooms"),
|
||||
yearBuilt: text("year_built"),
|
||||
tenure: text("tenure"),
|
||||
currentEpcRating: epcEnum("current_epc_rating"),
|
||||
currentSapPoints: real("current_sap_points"),
|
||||
currentValuation: real("current_valuation"),
|
||||
});
|
||||
export const property = pgTable(
|
||||
"property",
|
||||
{
|
||||
id: bigserial("id", { mode: "bigint" }).primaryKey(),
|
||||
|
||||
portfolioId: bigint("portfolio_id", { mode: "bigint" })
|
||||
.notNull()
|
||||
.references(() => portfolio.id),
|
||||
|
||||
creationStatus: propertyCreationStatusEnum("creation_status").notNull(),
|
||||
uprn: bigint("uprn", { mode: "bigint" }),
|
||||
|
||||
landlordPropertyId: text("landlord_property_id"),
|
||||
buildingReferenceNumber: bigint("building_reference_number", {
|
||||
mode: "bigint",
|
||||
}),
|
||||
|
||||
status: propertyStatusEnum("status"),
|
||||
address: text("address"),
|
||||
postcode: text("postcode"),
|
||||
|
||||
hasPreConditionReport: boolean("has_pre_condition_report"),
|
||||
hasRecommendations: boolean("has_recommendations"),
|
||||
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||
|
||||
propertyType: text("property_type"),
|
||||
builtForm: text("built_form"),
|
||||
localAuthority: text("local_authority"),
|
||||
constituency: text("constituency"),
|
||||
|
||||
numberOfRooms: integer("number_of_rooms"),
|
||||
yearBuilt: text("year_built"),
|
||||
tenure: text("tenure"),
|
||||
|
||||
currentEpcRating: epcEnum("current_epc_rating"),
|
||||
currentSapPoints: real("current_sap_points"),
|
||||
currentValuation: real("current_valuation"),
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex("uq_property_portfolio_uprn")
|
||||
.on(table.portfolioId, table.uprn)
|
||||
.where(sql`${table.uprn} IS NOT NULL`),
|
||||
]
|
||||
);
|
||||
|
||||
export const FeatureRating: [string, ...string[]] = [
|
||||
"Very good",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue