add unique index on uprn, element, aspect type, element instance

This commit is contained in:
Daniel Roth 2026-01-27 09:20:14 +00:00
parent 09e9addfd0
commit aac478d8fd

View file

@ -5,28 +5,34 @@ import {
pgTable,
integer,
bigint,
uniqueIndex,
} from "drizzle-orm/pg-core";
import { sql } from "drizzle-orm";
import { element } from "./element";
import { aspectType } from "./aspect_type";
export const assetCondition = pgTable("asset_condition", {
id: bigserial("id", { mode: "bigint" }).primaryKey(),
export const assetCondition = pgTable(
"asset_condition",
{
id: bigserial("id", { mode: "bigint" }).primaryKey(),
uprn: bigint("uprn", { mode: "number" }).notNull(),
uprn: bigint("uprn", { mode: "number" }).notNull(),
element: element("element").notNull(),
aspectType: aspectType("aspect_type").notNull(),
element: element("element").notNull(),
aspectType: aspectType("aspect_type").notNull(),
elementInstance: integer("element_instance"),
value: text("value"),
value: text("value"),
quantity: integer("quantity"),
installDate: date("install_date"),
renewalYear: integer("renewal_year"),
quantity: integer("quantity"),
installDate: date("install_date"),
renewalYear: integer("renewal_year"),
elementInstance: integer("element_instance"),
sourceSystem: text("source_system"),
comments: text("comments"),
});
sourceSystem: text("source_system"),
comments: text("comments"),
},
(t) => ({
uniq: uniqueIndex("asset_condition_uprn_element_aspect_instance")
.on(t.uprn, t.element, t.aspectType, t.elementInstance),
})
);