Phase 1A done

This commit is contained in:
2026-05-03 21:16:52 +02:00
parent 49190c5d7e
commit b8995b3a1b
21 changed files with 1038 additions and 3 deletions
+35
View File
@@ -0,0 +1,35 @@
import { integer, real, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { circuits } from "./circuits.js";
import { projectDevices } from "./project-devices.js";
import { rooms } from "./rooms.js";
export const circuitDeviceRows = sqliteTable("circuit_device_rows", {
id: text("id").primaryKey(),
circuitId: text("circuit_id")
.notNull()
.references(() => circuits.id, { onDelete: "cascade" }),
linkedProjectDeviceId: text("linked_project_device_id").references(() => projectDevices.id, {
onDelete: "set null",
}),
legacyConsumerId: text("legacy_consumer_id"),
sortOrder: integer("sort_order").notNull().default(0),
name: text("name").notNull(),
displayName: text("display_name").notNull(),
phaseType: text("phase_type"),
connectionKind: text("connection_kind"),
costGroup: text("cost_group"),
category: text("category"),
level: text("level"),
roomId: text("room_id").references(() => rooms.id, {
onDelete: "set null",
}),
roomNumberSnapshot: text("room_number_snapshot"),
roomNameSnapshot: text("room_name_snapshot"),
quantity: integer("quantity").notNull(),
powerPerUnit: real("power_per_unit").notNull(),
simultaneityFactor: real("simultaneity_factor").notNull(),
cosPhi: real("cos_phi"),
remark: text("remark"),
overriddenFields: text("overridden_fields"),
});
+21
View File
@@ -0,0 +1,21 @@
import { integer, sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
import { circuitLists } from "./circuit-lists.js";
export const circuitSections = sqliteTable(
"circuit_sections",
{
id: text("id").primaryKey(),
circuitListId: text("circuit_list_id")
.notNull()
.references(() => circuitLists.id, { onDelete: "cascade" }),
key: text("key").notNull(),
displayName: text("display_name").notNull(),
prefix: text("prefix").notNull(),
sortOrder: integer("sort_order").notNull().default(0),
},
(table) => [
unique("circuit_sections_list_key_unique").on(table.circuitListId, table.key),
unique("circuit_sections_list_prefix_unique").on(table.circuitListId, table.prefix),
]
);
+33
View File
@@ -0,0 +1,33 @@
import { integer, real, sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
import { circuitLists } from "./circuit-lists.js";
import { circuitSections } from "./circuit-sections.js";
export const circuits = sqliteTable(
"circuits",
{
id: text("id").primaryKey(),
circuitListId: text("circuit_list_id")
.notNull()
.references(() => circuitLists.id, { onDelete: "cascade" }),
sectionId: text("section_id")
.notNull()
.references(() => circuitSections.id, { onDelete: "cascade" }),
equipmentIdentifier: text("equipment_identifier").notNull(),
displayName: text("display_name"),
sortOrder: integer("sort_order").notNull().default(0),
protectionType: text("protection_type"),
protectionRatedCurrent: real("protection_rated_current"),
protectionCharacteristic: text("protection_characteristic"),
cableType: text("cable_type"),
cableCrossSection: text("cable_cross_section"),
cableLength: real("cable_length"),
rcdAssignment: text("rcd_assignment"),
terminalDesignation: text("terminal_designation"),
voltage: real("voltage"),
status: text("status"),
isReserve: integer("is_reserve").notNull().default(0),
remark: text("remark"),
},
(table) => [unique("circuits_list_equipment_identifier_unique").on(table.circuitListId, table.equipmentIdentifier)]
);
@@ -0,0 +1,19 @@
import { sqliteTable, text } from "drizzle-orm/sqlite-core";
import { circuitDeviceRows } from "./circuit-device-rows.js";
import { circuitLists } from "./circuit-lists.js";
import { circuits } from "./circuits.js";
export const legacyConsumerCircuitMigrations = sqliteTable("legacy_consumer_circuit_migrations", {
consumerId: text("consumer_id").primaryKey(),
circuitId: text("circuit_id")
.notNull()
.references(() => circuits.id, { onDelete: "cascade" }),
circuitDeviceRowId: text("circuit_device_row_id")
.notNull()
.references(() => circuitDeviceRows.id, { onDelete: "cascade" }),
circuitListId: text("circuit_list_id")
.notNull()
.references(() => circuitLists.id, { onDelete: "cascade" }),
createdAtIso: text("created_at_iso").notNull(),
});
@@ -0,0 +1,24 @@
import { integer, sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
import { circuitLists } from "./circuit-lists.js";
export const legacyConsumerMigrationReports = sqliteTable(
"legacy_consumer_migration_reports",
{
id: text("id").primaryKey(),
circuitListId: text("circuit_list_id")
.notNull()
.references(() => circuitLists.id, { onDelete: "cascade" }),
legacyConsumerCount: integer("legacy_consumer_count").notNull(),
createdCircuitCount: integer("created_circuit_count").notNull(),
createdDeviceRowCount: integer("created_device_row_count").notNull(),
duplicateGroupedCount: integer("duplicate_grouped_count").notNull(),
generatedIdentifierCount: integer("generated_identifier_count").notNull(),
unassignedRowCount: integer("unassigned_row_count").notNull(),
warningsJson: text("warnings_json").notNull(),
generatedIdentifiersJson: text("generated_identifiers_json").notNull(),
duplicateGroupsJson: text("duplicate_groups_json").notNull(),
createdAtIso: text("created_at_iso").notNull(),
},
(table) => [unique("legacy_consumer_migration_reports_list_unique").on(table.circuitListId)]
);