mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
landlord overrides
This commit is contained in:
parent
5fc18dfcf6
commit
1df047a84a
1 changed files with 92 additions and 0 deletions
92
src/app/db/schema/landlord_overrides.ts
Normal file
92
src/app/db/schema/landlord_overrides.ts
Normal 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),
|
||||
}),
|
||||
);
|
||||
Loading…
Add table
Reference in a new issue