landlord overrides

This commit is contained in:
Jun-te Kim 2026-05-26 10:21:50 +00:00
parent 5fc18dfcf6
commit 1df047a84a

View file

@ -0,0 +1,92 @@
import {
bigint,
pgEnum,
pgTable,
text,
timestamp,
unique,
uuid,
} from "drizzle-orm/pg-core";
import { portfolio } from "./portfolio";
// Enum string values mirror /workspaces/home/github/Model/domain/sal/*.py
// exactly (PropertyType.value, WallType.value). Keep in sync — see
// docs/adr/0002-landlord-override-vocabulary.md.
export const PropertyTypeValues: [string, ...string[]] = [
"House",
"Bungalow",
"Flat",
"Maisonette",
"Park home",
"Unknown",
];
export const WallTypeValues: [string, ...string[]] = [
"Cavity",
"Solid Brick",
"Timber frame",
"Sandstone",
"Unknown",
];
export const OverrideSourceValues: [string, ...string[]] = [
"classifier",
"user",
];
export const propertyTypeEnum = pgEnum("property_type", PropertyTypeValues);
export const wallTypeEnum = pgEnum("wall_type", WallTypeValues);
export const overrideSourceEnum = pgEnum(
"override_source",
OverrideSourceValues,
);
export const landlordPropertyTypeOverrides = pgTable(
"landlord_property_type_overrides",
{
id: uuid("id").defaultRandom().primaryKey(),
portfolioId: bigint("portfolio_id", { mode: "bigint" })
.notNull()
.references(() => portfolio.id, { onDelete: "cascade" }),
description: text("description").notNull(),
value: propertyTypeEnum("value").notNull(),
source: overrideSourceEnum("source").notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.notNull()
.defaultNow()
.$onUpdate(() => new Date()),
},
(table) => ({
portfolioDescriptionUnique: unique(
"landlord_property_type_overrides_portfolio_description_unique",
).on(table.portfolioId, table.description),
}),
);
export const landlordWallTypeOverrides = pgTable(
"landlord_wall_type_overrides",
{
id: uuid("id").defaultRandom().primaryKey(),
portfolioId: bigint("portfolio_id", { mode: "bigint" })
.notNull()
.references(() => portfolio.id, { onDelete: "cascade" }),
description: text("description").notNull(),
value: wallTypeEnum("value").notNull(),
source: overrideSourceEnum("source").notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.notNull()
.defaultNow()
.$onUpdate(() => new Date()),
},
(table) => ({
portfolioDescriptionUnique: unique(
"landlord_wall_type_overrides_portfolio_description_unique",
).on(table.portfolioId, table.description),
}),
);