From 1df047a84add22a8a9795a446ebe892f45357488 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Tue, 26 May 2026 10:21:50 +0000 Subject: [PATCH] landlord overrides --- src/app/db/schema/landlord_overrides.ts | 92 +++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/app/db/schema/landlord_overrides.ts diff --git a/src/app/db/schema/landlord_overrides.ts b/src/app/db/schema/landlord_overrides.ts new file mode 100644 index 0000000..4238e60 --- /dev/null +++ b/src/app/db/schema/landlord_overrides.ts @@ -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), + }), +);