forked from jappel/leistungsbilanz-ts
26 lines
854 B
TypeScript
26 lines
854 B
TypeScript
import { sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
|
|
import { circuitLists } from "./circuit-lists.js";
|
|
|
|
export const circuitListEquipmentIdentifiers = sqliteTable(
|
|
"circuit_list_equipment_identifiers",
|
|
{
|
|
ownerType: text("owner_type")
|
|
.$type<"circuit" | "distribution_board_component">()
|
|
.notNull(),
|
|
ownerId: text("owner_id").notNull(),
|
|
circuitListId: text("circuit_list_id")
|
|
.notNull()
|
|
.references(() => circuitLists.id, { onDelete: "cascade" }),
|
|
equipmentIdentifier: text("equipment_identifier").notNull(),
|
|
},
|
|
(table) => [
|
|
unique("circuit_list_equipment_identifiers_owner_unique").on(
|
|
table.ownerType,
|
|
table.ownerId
|
|
),
|
|
unique("circuit_list_equipment_identifiers_list_identifier_unique").on(
|
|
table.circuitListId,
|
|
table.equipmentIdentifier
|
|
),
|
|
]
|
|
);
|