From 734a2bcfc4a8d57a682634207567759e96cb7b70 Mon Sep 17 00:00:00 2001 From: Julian Appel Date: Fri, 31 Jul 2026 14:07:26 +0200 Subject: [PATCH] Create clean release database baseline --- AGENTS.md | 22 +- README.md | 8 +- ...eistungsbilanz-2026-05-03T19-47-12-976Z.db | Bin 90112 -> 0 bytes docs/README.md | 3 - docs/circuit-list-editor-api.md | 8 - docs/circuit-list-editor-architecture.md | 5 - docs/circuit-list-editor-known-limitations.md | 1 - docs/circuit-list-editor-migration.md | 90 - docs/current-architecture.md | 53 +- docs/development-workflow.md | 17 +- docs/local-db-circuit-first-migration.md | 137 - ...history-and-external-model-architecture.md | 2 - docs/spec/07-implementation-phases-todo.md | 13 +- package.json | 8 +- scripts/db-backfill-sections.ts | 26 - scripts/db-migrate-legacy-consumers.ts | 61 - scripts/db-verify-circuit-schema.js | 18 +- scripts/run-tests.mjs | 30 + src/db/migrations/0000_bizarre_colossus.sql | 28 - src/db/migrations/0000_whole_surge.sql | 300 +++ src/db/migrations/0001_global_devices.sql | 12 - .../0002_project_voltage_defaults.sql | 3 - .../migrations/0003_project_floors_rooms.sql | 19 - .../0004_circuit_lists_and_entry_fields.sql | 44 - src/db/migrations/0005_project_devices.sql | 14 - .../migrations/0006_device_display_name.sql | 7 - .../migrations/0007_consumer_device_link.sql | 3 - .../migrations/0008_circuit_first_model.sql | 99 - .../0009_project_device_circuit_fields.sql | 24 - .../0010_circuit_control_requirement.sql | 1 - .../0011_project_device_canonical_fields.sql | 9 - .../0012_project_revision_foundation.sql | 24 - .../0013_project_history_stacks.sql | 11 - src/db/migrations/0014_project_snapshots.sql | 16 - .../migrations/0015_modern_madame_masque.sql | 2 - src/db/migrations/0016_dashing_darkstar.sql | 4 - src/db/migrations/0017_vengeful_romulus.sql | 2 - src/db/migrations/0018_fancy_argent.sql | 1 - .../0019_normalize_project_voltages.sql | 48 - .../migrations/0020_normalize_phase_types.sql | 85 - .../0021_fill_missing_phase_types.sql | 75 - .../0022_default_remaining_phase_types.sql | 7 - .../0023_cheerful_night_thrasher.sql | 1 - .../migrations/0024_damp_mister_sinister.sql | 150 -- src/db/migrations/meta/0000_snapshot.json | 1586 +++++++++++- src/db/migrations/meta/0011_snapshot.json | 1450 ----------- src/db/migrations/meta/0012_snapshot.json | 1614 ------------ src/db/migrations/meta/0013_snapshot.json | 1694 ------------- src/db/migrations/meta/0014_snapshot.json | 1805 ------------- src/db/migrations/meta/0015_snapshot.json | 1822 -------------- src/db/migrations/meta/0016_snapshot.json | 1850 -------------- src/db/migrations/meta/0017_snapshot.json | 1877 -------------- src/db/migrations/meta/0018_snapshot.json | 1885 -------------- src/db/migrations/meta/0019_snapshot.json | 1885 -------------- src/db/migrations/meta/0020_snapshot.json | 1885 -------------- src/db/migrations/meta/0021_snapshot.json | 1885 -------------- src/db/migrations/meta/0022_snapshot.json | 1885 -------------- src/db/migrations/meta/0023_snapshot.json | 1893 -------------- src/db/migrations/meta/0024_snapshot.json | 2242 ----------------- src/db/migrations/meta/_journal.json | 172 +- ...ice-row-move-project-command.repository.ts | 8 - ...ow-structure-project-command.repository.ts | 5 - ...ircuit-device-row-structure.persistence.ts | 1 - .../circuit-device-row.persistence.ts | 2 - .../circuit-device-row.repository.ts | 1 - ...it-structure-project-command.repository.ts | 11 - src/db/repositories/circuit.persistence.ts | 16 - ...rd-structure-project-command.repository.ts | 12 +- .../legacy-consumer-migration.repository.ts | 142 -- ...ce-structure-project-command.repository.ts | 1 - ...on-structure-project-command.repository.ts | 9 +- ...ect-settings-project-command.repository.ts | 54 +- .../project-snapshot.repository.ts | 20 +- ...roject-state-restore-command.repository.ts | 137 - .../project-state-snapshot.persistence.ts | 4 - src/db/schema/circuit-device-rows.ts | 1 - src/db/schema/circuits.ts | 3 - src/db/schema/consumers.ts | 47 - .../legacy-consumer-circuit-migrations.ts | 19 - .../legacy-consumer-migration-report.ts | 24 - ...ice-row-structure-project-command.model.ts | 2 - src/domain/models/circuit-device-row.model.ts | 1 - .../models/circuit-project-command.model.ts | 7 - ...circuit-structure-project-command.model.ts | 9 - src/domain/models/circuit-tree.model.ts | 15 - src/domain/models/circuit.model.ts | 3 - ...istribution-board-project-command.model.ts | 27 +- ...n-board-structure-project-command.model.ts | 205 +- ...stribution-board-subtree-snapshot.model.ts | 1 - .../project-settings-project-command.model.ts | 92 +- .../models/project-state-snapshot.model.ts | 328 +-- src/domain/models/project-transfer.model.ts | 1 - .../ports/legacy-consumer-migration.store.ts | 143 -- .../legacy-consumer-migration-planner.ts | 60 - .../legacy-consumer-migration.service.ts | 269 -- .../services/project-voltage.service.ts | 28 - .../components/circuit-tree-editor.tsx | 25 +- .../components/circuit-tree-preview.tsx | 18 +- src/frontend/types.ts | 19 - src/frontend/utils/circuit-grid-model.ts | 53 +- src/frontend/utils/circuit-group-editing.ts | 6 - .../utils/circuit-structure-command.ts | 4 - .../controllers/circuit-tree.controller.ts | 4 - ...ow-move-project-command.repository.test.ts | 3 - ...ructure-project-command.repository.test.ts | 6 - tests/circuit-grid-model.test.ts | 49 +- tests/circuit-group-numbering.test.ts | 2 +- ...subtree-project-command.repository.test.ts | 1 - tests/circuit-group-subtree-snapshot.test.ts | 4 - tests/circuit-power-calculation.test.ts | 12 - ...circuit-project-command.repository.test.ts | 14 +- tests/circuit-structure-command.test.ts | 3 +- ...ructure-project-command.repository.test.ts | 16 - ...n-board-component-schema-migration.test.ts | 466 ---- ...ructure-project-command.repository.test.ts | 183 -- tests/distribution-board-subtree.test.ts | 5 - .../legacy-consumer-migration-planner.test.ts | 57 - ...gacy-consumer-migration.repository.test.ts | 245 -- .../legacy-consumer-migration.service.test.ts | 130 - tests/project-command.model.test.ts | 11 +- tests/project-command.service.test.ts | 7 - tests/project-device-schema-migration.test.ts | 98 - tests/project-device-schema.test.ts | 4 +- tests/project-device-sync.service.test.ts | 1 - ...ructure-project-command.repository.test.ts | 48 - ...ettings-project-command.repository.test.ts | 31 - tests/project-snapshot.repository.test.ts | 96 +- ...t-state-restore-command.repository.test.ts | 83 +- tests/project-state-snapshot.test.ts | 395 +-- 129 files changed, 2121 insertions(+), 30607 deletions(-) delete mode 100644 data/backups/leistungsbilanz-2026-05-03T19-47-12-976Z.db delete mode 100644 docs/circuit-list-editor-migration.md delete mode 100644 docs/local-db-circuit-first-migration.md delete mode 100644 scripts/db-backfill-sections.ts delete mode 100644 scripts/db-migrate-legacy-consumers.ts create mode 100644 scripts/run-tests.mjs delete mode 100644 src/db/migrations/0000_bizarre_colossus.sql create mode 100644 src/db/migrations/0000_whole_surge.sql delete mode 100644 src/db/migrations/0001_global_devices.sql delete mode 100644 src/db/migrations/0002_project_voltage_defaults.sql delete mode 100644 src/db/migrations/0003_project_floors_rooms.sql delete mode 100644 src/db/migrations/0004_circuit_lists_and_entry_fields.sql delete mode 100644 src/db/migrations/0005_project_devices.sql delete mode 100644 src/db/migrations/0006_device_display_name.sql delete mode 100644 src/db/migrations/0007_consumer_device_link.sql delete mode 100644 src/db/migrations/0008_circuit_first_model.sql delete mode 100644 src/db/migrations/0009_project_device_circuit_fields.sql delete mode 100644 src/db/migrations/0010_circuit_control_requirement.sql delete mode 100644 src/db/migrations/0011_project_device_canonical_fields.sql delete mode 100644 src/db/migrations/0012_project_revision_foundation.sql delete mode 100644 src/db/migrations/0013_project_history_stacks.sql delete mode 100644 src/db/migrations/0014_project_snapshots.sql delete mode 100644 src/db/migrations/0015_modern_madame_masque.sql delete mode 100644 src/db/migrations/0016_dashing_darkstar.sql delete mode 100644 src/db/migrations/0017_vengeful_romulus.sql delete mode 100644 src/db/migrations/0018_fancy_argent.sql delete mode 100644 src/db/migrations/0019_normalize_project_voltages.sql delete mode 100644 src/db/migrations/0020_normalize_phase_types.sql delete mode 100644 src/db/migrations/0021_fill_missing_phase_types.sql delete mode 100644 src/db/migrations/0022_default_remaining_phase_types.sql delete mode 100644 src/db/migrations/0023_cheerful_night_thrasher.sql delete mode 100644 src/db/migrations/0024_damp_mister_sinister.sql delete mode 100644 src/db/migrations/meta/0011_snapshot.json delete mode 100644 src/db/migrations/meta/0012_snapshot.json delete mode 100644 src/db/migrations/meta/0013_snapshot.json delete mode 100644 src/db/migrations/meta/0014_snapshot.json delete mode 100644 src/db/migrations/meta/0015_snapshot.json delete mode 100644 src/db/migrations/meta/0016_snapshot.json delete mode 100644 src/db/migrations/meta/0017_snapshot.json delete mode 100644 src/db/migrations/meta/0018_snapshot.json delete mode 100644 src/db/migrations/meta/0019_snapshot.json delete mode 100644 src/db/migrations/meta/0020_snapshot.json delete mode 100644 src/db/migrations/meta/0021_snapshot.json delete mode 100644 src/db/migrations/meta/0022_snapshot.json delete mode 100644 src/db/migrations/meta/0023_snapshot.json delete mode 100644 src/db/migrations/meta/0024_snapshot.json delete mode 100644 src/db/repositories/legacy-consumer-migration.repository.ts delete mode 100644 src/db/schema/consumers.ts delete mode 100644 src/db/schema/legacy-consumer-circuit-migrations.ts delete mode 100644 src/db/schema/legacy-consumer-migration-report.ts delete mode 100644 src/domain/ports/legacy-consumer-migration.store.ts delete mode 100644 src/domain/services/legacy-consumer-migration-planner.ts delete mode 100644 src/domain/services/legacy-consumer-migration.service.ts delete mode 100644 tests/distribution-board-component-schema-migration.test.ts delete mode 100644 tests/legacy-consumer-migration-planner.test.ts delete mode 100644 tests/legacy-consumer-migration.repository.test.ts delete mode 100644 tests/legacy-consumer-migration.service.test.ts delete mode 100644 tests/project-device-schema-migration.test.ts diff --git a/AGENTS.md b/AGENTS.md index 3470390..18896c9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -33,17 +33,12 @@ It must support circuits, device rows, project devices, drag-and-drop restructur - General application repositories also require an explicit `AppDatabase`; `src/server/composition/application-repositories.ts` owns their runtime instances, and controllers never import the global SQLite client. -- The upgrade-only legacy migration service follows the same dependency rule; - its concrete repositories are instantiated only in - `scripts/db-migrate-legacy-consumers.ts`. - General Circuit, CircuitDeviceRow, CircuitList and DistributionBoard repositories expose only active reads. Runtime writes belong in typed command repositories; direct integration fixtures belong under `tests/support`. -The supported runtime model is Circuit-First. The former Consumer UI and API are -removed. Retained `consumers` rows, migration mappings and reports are upgrade-only -data accessed by `npm run db:migrate:legacy-consumers`; do not build application -features on them. +The supported runtime model is Circuit-First. The former Consumer UI, API, +tables and upgrade tooling are removed; do not reintroduce them. See `docs/current-architecture.md` for the complete module and request flow. @@ -255,9 +250,9 @@ not change the project revision or undo/redo stacks. Restoring a server-stored snapshot verifies its checksum and the current-state hash, replaces supported project data atomically and records a new `restore` revision with a complete inverse command. Restore can therefore be undone and redone after a restart. -Snapshot schema version 7 also contains circuit-group identity, +Baseline snapshot schema version 1 contains circuit-group identity, distribution-board components and the separate circuit/component protection -records. Versions 1 through 6 remain readable. Portable duplicate imports +records. Pre-baseline snapshots are unsupported. Portable duplicate imports remap component ids and protection-owner references together with the existing project graph. The central revision boundary creates an automatic logical snapshot after each @@ -294,13 +289,11 @@ change in one revision and Undo/Redo restores them together; the project PUT route requires `expectedRevision`. The system catalog is `AV`, `SV`, `EV`, `USV`, `MSR`, `SiBe`; at least one must be enabled and a type used by a board cannot be disabled. -Distribution-board setup uses `distribution-board.insert` schema version 3 +Distribution-board setup uses `distribution-board.insert` schema version 1 with a complete stable snapshot of the board, circuit list, three default groups, main switch `-Q0` and surge protective device `-FA`. Its inverse removes only the same unchanged and still-empty structure; the POST route requires `expectedRevision` and returns the updated history state. -Stored schema-version 1 and 2 setup commands remain executable with their four -legacy sections and without invented components. Complete populated distribution-board copying and deletion use `distribution-board.insert-subtree` and `distribution-board.delete-subtree`. Their exact snapshots include the board, circuit list, groups, circuits, @@ -389,7 +382,10 @@ Users must be able to override sizing suggestions. ## Persistence and Migration Rules - SQLite is the currently supported database. -- Never edit an already applied migration. +- Migration `0000` is the clean release baseline for empty databases. +- Pre-baseline development databases, snapshots and stored commands are not + supported. +- After the first release, never edit an already applied migration. - Back up an existing database before applying a new migration. - Inspect generated SQL; it must contain only the intended schema change. - Keep database backups separate from logical project snapshots. diff --git a/README.md b/README.md index 86e93df..1b60bcd 100644 --- a/README.md +++ b/README.md @@ -108,11 +108,9 @@ npm run db:generate ``` `db:backup` verwendet die SQLite-Online-Backup-API und prüft das Ergebnis auf -Integrität und Fremdschlüsselverletzungen. Vor jeder Migration einer bestehenden -Datenbank ist ein Backup erforderlich. - -`db:migrate:legacy-consumers` und `db:backfill:sections` sind ausschließlich -Upgrade-Werkzeuge für ältere Datenbanken. Neue Installationen benötigen sie nicht. +Integrität und Fremdschlüsselverletzungen. Die Migration `0000` ist die +Release-Baseline und richtet ausschließlich eine neue, leere Datenbank ein. +Datenbanken aus Entwicklungsständen vor dieser Baseline werden nicht unterstützt. ## Dokumentation diff --git a/data/backups/leistungsbilanz-2026-05-03T19-47-12-976Z.db b/data/backups/leistungsbilanz-2026-05-03T19-47-12-976Z.db deleted file mode 100644 index c803dbab44f737ea2121c0b34592b3350222cefc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 90112 zcmeI5U5wjSc7VzGkw%&yImvDWBXG^eMQzn#&Ho=P0%u~&hU>}L9$QJ=Y{4P#y&Nmi zh+~p+;-o-3<4v&bOSc7zb{8=E5G)pb3W|NobFn}d=tHsSgNp*)b~jn{r7s1FKI}g9 zTxz5tJ(8<<$8l^N+9QdFm*?L5oy&874n!1M<@t>V1N*LHXu*8NdC)bh&=?sQ8`P)DJq0MBSvf$>L=AVdl(QbNO0Ry0-l4N>f@N z%Gae6)yjICu1hIJpqI9z zt`|gpOua!mes0&_WV`C~XAwVT8&Q0_e~2f%+4H+;I|WI*3&&VoC_=lNq<*KvsJ9ip z%VKW}{(9YZ>b>*sx)d|NQ%FtOrr)Jr=#w;xM;yNuby9zWdAIt)|wa2uVz=k ziF~_n6zsZtK}?9A_z3|%&~A$AM_)O`oc5=gFw;SMsy4ROXUcW|xVXKMxs^iO@%HP7 z7RRrwn>|)Y`RuL>X{}zk(rQW5Tfy&l-TQ4;21ia7s$o$tE?x9lswd3O) zW1(Q4TG)N&PQ6yHA3rXBxY>7xxr-?&q&#$=Q_LrP#E!AxtoAOAytvp@avr$YKAwP< zxZC`zjmA=`{&IbsQMng|J}!H!?Ierkdc7`w*vyQW3A2}_qR}$hK^QCSMBu*i9T!*a z*iNCO?IJr=&pFTX!Kz*H_+J9f%sm+(`hYyQ)Zf7RyOZ%@2 zMI-fv2Vterz}J%~PNDaqyfeFh@Bsbmx#iZ%HA&g$e-HMesy4n+E!8hI#^KxOM1kMg z8_X5==XX{s<$9wbe(Q}4XYpupuUf=gJUAidF(jXwVOh0tYOYj2b7Y(~27Yrms7@-| z-z=BwM~;Yh<}(WnQVibbiqr? zG@7MS{klGm$Nqj8eDMfjd1qm^T-SB+&gqQOh$JIKr6Ri#DJI0YOMU353qE;tn|_oX zX|X-3JW3dVSGRFW6@yb!iFm993|E-bI)r-tB1VS`D)jsC1LH?0FXfuTAd zy2C6VI!_p$6PTcWy|T#Xs*8Uu)P7hCYloNqap{kiw8hUsfEyA(0!RP}AOR$R1dsp{ zKmter34AF8F3!yg+l#Z7ZCJLV7@@CFO9@q5(fLkyy7 zL{UTHGdFa!KojqN{;S^-E|xQ8lu)V@;*-#^9ozC%-LP%TB+PbA-EVyF%z)Wy61{;xm#{=@Euh#G}SUG(`g9GN@s+NQ<*ZVX;gJ}uoI@lsGmdK z(4-33Dhzd32bDUp0}Tpi6312y-O&TXQJLWw4gmxF^!N{Fs?eI}YX2hCepUP5+JD#n ztM;F@pV$5k1h^pqB!C2v01`j~NB{{S0VIF~kN^@u0$+UsGt+`N$6w0)rNm!m`O6G{ zndUE3)6+s_v3gIKsr*Q&NlVXEezbV1{5So7U;PSV36TI2Kmter2|Tp~b`H%QX|-DJ zu}ZljR4Rhd65PGYwklM&RNJ9MR^3384c#?mmpFm!!#=YVqA-YAs1PK9kcsTN0hJ9U zbmhSEO&Ov|#1AdsQhnc4sPDKMm6_s(vcZ@pLzu;sA@pE}Duk4DM|qWXSdZLDd)*DG zDX+A%)ivb+LP)Y7@Ia3nn7XPwbx2ANL_#3s23Sm4QC%WK2*{QlFtqGL>tHr< zb>E;*84^L5dgDPCj$%_60&9+}=+ux6S688>Q7S{=&7#ayL&No-J|w^WAS4DvKn;cJ zvJQjbf=g{;6FC5jehyt-yIZ$i|9E!5-WzNSI_WZHE z=Z}RsU57Zl=4-M8O$z)dG%(k-137dZswxnr_w56_(w5_ZwbNv)20?EKzso% znlT2~8C4C#v7x`!!Hf8oCPUC(i zL9N#&SwG~@y<3}PRc(f6J;~BhR>nzIV5W{ww)!I~UhBN4sBcVh#Xd7!LR4M0;LH88VFj-2z=H^69kjZJ@593qCb}!2 zueb?{wKqhrc#<3ICND8ptn%;wPuD&YvgrRuPmhVQCP)AYAOR$R1dsp{Kmter2_OL^ zfCRpJ1hShMCRmP`<_RZRUdZDAlPnkT`2SSx2SV+i;RQD&fCP{L5h?3qr+LGOw0 zFy@Q|kN^@u0!RP}AOR$R1dsp{KmthMVF~c(|4*`1z~leIp@+={&qD%800|%gB!C2v z01`j~NB{{S0VIF~o&*9s{*UwjC&5x!MkIg)kN^@u0!RP}AOR$R1dsp{Kmrd>0OS7; z&koN-0!RP}AOR$R1dsp{Kmter2_OL^@T3sH`2Uk)DJ&-vKmter2_OL^fCP{L5G zX(uV$UYN>?<1@o0MAc=B*@0|WfeXdabXkY8xQ6c&oB5LzXA(XA;xwT++Wz8*S#eB- z`i`qnnJI1vbeJXwfo94MrFN(iMb#Z;lHyFFXRkQ>=9`7#X*OE#z)$N^(S_8rr5bixeHF(>&Vz^kmo zdgMmh>u%&ep8oW^eEXj8i=0qu$}8*kN=CcdvO2%fmIL{Aps@t>V1N*&3+)v@j86_h3Rtr=uz=Iv#B3+7>T+`ZIxE=J; zcGUHP$d9QvNXO6Z`kQQ5ef})sr)(pNZ}$)Jgg1MBH*KdNX?Nimiwi|)cazlbbQtxv zqIX&BZNXo!+fKcA-d&es=64FIDckhB)C+x*M)8Q_x1vt!Z!qsx|5#SX8-Bt(67{<2 zumqVr%Py}et5uZl*6Jl`J&vNyVV$M5=DFrtbM;K~YX3;Geu5KjNS9Wn*5$L@4BbeA zk^wI+JKJ1of-GUF)a`XTppUd;(u1n;$BK;Bn@{oZ`n$c&fB_zEd&riugv9MFUap*s zH$5-Cy|q`}t&CJbl*T?~UK9gADDp-e^|pp8vORCF89+|Zo>FMoyulRI2?2HW}td_ythZ+82>HN)j*WXSB=Ps=^FPvY^ zu7DHycHb!2b@zgp5Iyk|0(_v|6xENua*8?aPcvbrgZ5Ny2*T{2*Zt$-_D1Gb3T?;R zuOC_*zp`%jSRv)JyDp@)df`f|DP34S+kCUwRFelPTjy=P(6kfqKIt3L*2* zX1QEHazwl{pP6NlV(>m!G{r#t@J8U}PTJiK7_an)RJl><{X^j4HKFMWoR;2**%vv> zP?ScqRH|Rs$MM+T55s(8gs{A`Fk7zcx_IYwMrlNn5u#F&-G~$uV%(*^=biF%iqQ?d zIOfVJC=RrS_MB+6zB{C=Hq@C?y?JyT)!{_TQ->dC&rg-=Z<*sx@jM#0-+vz(#b$d0 zM!_&h21|^RPH#8Fa@{n=?OtYzQE5iWrV7S*aa58Q`MeOeHkGb6*DfrtWT_F=qmh6Bw%Vp}WtgGcXBl6P~=WIQOSQwG;}qzhC;hrEe`RE&P1`!u(S8_er>u=!!8Y<`tdHNn>N&Uy4`vQuZEUO0l%Lw=%@oG| zxz)}zdFD>NR<0jEE`GR~HQ&O)!p@FYeUl%k{&D#XGk% z6ZNJ2*M*{y`oe>-(wOl=62&P5*C>zGja?Xe)QhFn#y6^^`lZG=e8r_nPc81x{~r&E BgF^rS diff --git a/docs/README.md b/docs/README.md index 652a097..fbbd4bd 100644 --- a/docs/README.md +++ b/docs/README.md @@ -20,9 +20,6 @@ ausdrücklich getrennt und dürfen nicht als bereits implementiert verstanden we - [Entwicklungs- und Contributor-Workflow](development-workflow.md) - [Deployment und Betrieb](deployment.md) -- [Lokale Circuit-First-Datenbankmigration](local-db-circuit-first-migration.md) -- [Retained Legacy-Datenmigration](circuit-list-editor-migration.md) – - ausschließlich für Upgrades alter Datenbanken ## Zukunftsarchitektur diff --git a/docs/circuit-list-editor-api.md b/docs/circuit-list-editor-api.md index ff92fbf..7e3d2d3 100644 --- a/docs/circuit-list-editor-api.md +++ b/docs/circuit-list-editor-api.md @@ -225,8 +225,6 @@ returns HTTP `409` with `PROJECT_HISTORY_OPERATION_UNAVAILABLE`. `{ "distributionBoard": { ... }, "revision": { ... }, "history": { ... } }` - persistent Undo removes only the unchanged and still-empty generated structure; Redo restores the same ids - - stored command schema versions 1 and 2 remain executable with their four - legacy sections and without generated components - stale revisions return `409 PROJECT_REVISION_CONFLICT` - `PUT /projects/:projectId/distribution-boards/:distributionBoardId` - body: @@ -358,12 +356,6 @@ available only as the corresponding versioned commands through structure POST, move, reorder, renumber, identifier-restore, Circuit DELETE or CircuitDeviceRow DELETE routes. -## Removed Legacy Endpoints - -The former `/consumers` read/write endpoints were removed after every retained -consumer had a verified Circuit-First migration mapping. Database upgrade tooling -reads retained legacy rows directly; application features must use the Circuit-First -endpoints above. ## Linked Project Device Review diff --git a/docs/circuit-list-editor-architecture.md b/docs/circuit-list-editor-architecture.md index 2a761df..c58589b 100644 --- a/docs/circuit-list-editor-architecture.md +++ b/docs/circuit-list-editor-architecture.md @@ -49,11 +49,6 @@ The pure grid modules have no React state and are covered by focused unit tests. - Represents fixed header components, optional group protection and manually named auxiliary footer devices with their own unique BMK. - Group protection may own a separate one-to-one protection configuration. -- Retained legacy migration source - - Old `consumers` rows, mappings and reports are available only to explicit - database upgrade tooling. - - They are not application-domain entities and have no UI or API. - ## Why A Circuit Is Not One Row A circuit can contain zero, one, or many device rows. Treating a circuit as a single row breaks: diff --git a/docs/circuit-list-editor-known-limitations.md b/docs/circuit-list-editor-known-limitations.md index d0f3ab5..85fd206 100644 --- a/docs/circuit-list-editor-known-limitations.md +++ b/docs/circuit-list-editor-known-limitations.md @@ -23,4 +23,3 @@ - Protection and cable values are planner-owned manual selections. The later sizing/warning engine does not yet validate them against load, length or voltage-drop rules. -- Legacy consumer UI and server endpoints are removed; retained source rows and migration mappings remain available only for upgrade traceability. diff --git a/docs/circuit-list-editor-migration.md b/docs/circuit-list-editor-migration.md deleted file mode 100644 index 1f6364c..0000000 --- a/docs/circuit-list-editor-migration.md +++ /dev/null @@ -1,90 +0,0 @@ -# Circuit List Editor Migration - -## Status - -Upgrade-only. New installations already use the Circuit-First schema and do not -run this workflow. - -## Goal - -Migrate legacy row-first consumers into the circuit-first model without deleting legacy data. - -## Legacy Mapping - -Legacy `Consumer` rows map into: - -- `Circuit` for shared circuit identity and circuit-level technical fields -- `CircuitDeviceRow` for per-device load rows - -Multiple legacy consumers can map into one circuit when they share normalized circuit identity. - -For one circuit list, all new circuits, device rows, trace mappings and the migration report are committed in one SQLite transaction. A failed run therefore leaves none of those prepared migration writes behind. - -## Grouping Strategy (`circuitNumber`) - -Migration groups legacy rows by normalized `circuitNumber`: - -- valid/normalizable values become one target circuit per normalized value -- duplicates are grouped under that circuit (multiple `CircuitDeviceRow`s) -- missing/invalid values trigger generated identifiers and may fall back to `unassigned` section - -## Default Section Backfill - -Before migration, default sections are created/backfilled per circuit list. -This guarantees a valid target section space, including `unassigned` when no section can be inferred. - -## Migration Commands - -Run in this order for local database workflows: - -1. Backup: - - `npm run db:backup` -2. Migrate schema: - - `npm run db:migrate` -3. Verify circuit schema: - - `npm run db:verify:circuit-schema` -4. Backfill missing sections: - - `npm run db:backfill:sections` -5. Migrate legacy consumers: - - `npm run db:migrate:legacy-consumers` - -The migration command finishes with a cutover verification across the complete -database. It exits with an error while any legacy consumer lacks a migration -mapping, including consumers that cannot be migrated because they have no circuit -list assignment. The legacy multi-list UI was removed only after this check passed; -old `/projects/:projectId/circuit-lists` bookmarks redirect to the project page. - -## Validation Checks - -After migration, verify: - -- tree endpoint returns sections/circuits/rows -- grouped duplicate circuit numbers are reported -- generated identifiers are reported where expected -- migrated rows include `legacyConsumerId` traceability -- no duplicate BMKs exist inside one circuit list - -## If Tree Endpoint Returns Empty Sections - -Likely causes: - -- circuit-first tables missing (migration not run) -- sections not backfilled yet -- migrated dataset genuinely empty for selected list - -Actions: - -1. Run schema migration and verification commands. -2. Run section backfill command. -3. Run legacy-consumer migration command. -4. Retry tree endpoint. - -## Legacy Data Retention - -Do not delete legacy consumers yet. - -- legacy read/write endpoints have been removed from the application server -- migration trace tables reference old/new mapping -- retained rows allow upgrade verification and audit of the completed mapping -- a future automatic cleanup migration must migrate and verify old databases - before dropping these source and trace tables diff --git a/docs/current-architecture.md b/docs/current-architecture.md index 9b17158..076178f 100644 --- a/docs/current-architecture.md +++ b/docs/current-architecture.md @@ -9,10 +9,8 @@ Der unterstützte Editor ist Circuit-First: Ein Stromkreis ist nicht dasselbe wie eine Gerätezeile. BMK, Schutz- und Kabeldaten gehören zum Stromkreis; Last-, Raum- und Kategoriedaten gehören zur Gerätezeile. -Die frühere Consumer-Oberfläche und ihre API sind entfernt. Die Tabelle -`consumers` sowie Mappings und Reports bleiben ausschließlich erhalten, damit -ältere Datenbanken über den expliziten Upgrade-Befehl migriert und geprüft werden -können. +Die frühere Consumer-Oberfläche, ihre API, Tabellen und Upgrade-Werkzeuge sind +entfernt. Neue Funktionen bauen ausschließlich auf dem Circuit-First-Modell auf. ## Laufzeit @@ -130,8 +128,8 @@ Datenbank-Backups gespeichert. `POST /api/projects/:projectId/snapshots` erzeugt bei passender erwarteter Revision transaktional einen vollständigen, schema-versionierten Projektzustand mit SHA-256-Prüfwert. Enthalten sind Projekteinstellungen, Verteiler, Stromkreislisten, Bereiche, Stromkreise und -Gerätezeilen sowie Projektgeräte, Geschosse und Räume. Globale Geräte, -Legacy-Consumer und Migrationsberichte sind nicht Teil des Projekt-Snapshots. +Gerätezeilen sowie Projektgeräte, Geschosse und Räume. Globale Geräte sind nicht +Teil des Projekt-Snapshots. Create/List verändern weder Projektrevision noch Undo-/Redo-Stapel. `kind` unterscheidet benannte und automatische Stände. Die zentrale Revisionspersistenz erzeugt nach jeweils 25 weiteren Projektänderungen @@ -144,9 +142,7 @@ Prüfsumme, erwartete Revision und den unmittelbar zuvor gelesenen Projektzustand. Der Restore ersetzt alle unterstützten Projektdaten in einer Transaktion und schreibt dabei eine neue Revision mit Quelle `restore` sowie ein vollständiges inverses Kommando. Undo und Redo können deshalb auch einen -Restore nach einem Neustart exakt zurücknehmen oder wiederholen. Kompatible -Upgrade-only-Verknüpfungen und Migrationsnachweise bleiben erhalten, obwohl sie -nicht Bestandteil des logischen Snapshots sind. +Restore nach einem Neustart exakt zurücknehmen oder wiederholen. Die Projektseite bindet diese APIs in einem einklappbaren Bereich „Versionen und Sicherungspunkte“ ein. Dort können Benutzer Sicherungspunkte benennen, jeden aufgeführten benannten oder automatischen Stand nach @@ -246,8 +242,7 @@ Store leitet das inverse Kommando aus dem gespeicherten Projekt ab und schreibt Werte, Revision und Historienstapel gemeinsam. `PUT /api/projects/:projectId` verlangt deshalb `expectedRevision`, liefert Projekt plus aktualisierten Historienstand und besitzt keinen separaten direkten Settings-Schreibweg mehr. -Kommando- und Snapshot-Versionen vor dieser Erweiterung bleiben les- und -ausführbar; fehlende Metadaten werden dabei als `null` behandelt. +Kommando- und Snapshot-Payloads müssen dem aktuellen Baseline-Schema entsprechen. Die Projektseite zeigt Verteilungen, Etagen und Räume als kompakte Bestandsübersichten; ihre versionierten Erstellwege öffnen beschriftete Modals statt dauerhafter Eingabezeilen. Projektgeräte werden als durchsuchbare, @@ -264,8 +259,8 @@ rückgängig machbare Projektrevision. Der Modus `duplicate` ordnet Projekt-, Struktur-, Gruppen-, Verteilerkomponenten-, Raum-, Stromkreis- und Gerätezeilen-UUIDs sowie Schutzgeräte-Referenzen vollständig neu zu und legt die Kopie mit Revision `0` in einer Transaktion an. Upgrade-only- -Consumer-Verweise werden nicht in die Kopie übernommen; fachliche Verknüpfungen -innerhalb des unterstützten Laufzeitmodells bleiben erhalten. Die +Fachliche Verknüpfungen innerhalb des unterstützten Laufzeitmodells bleiben +erhalten. Die Projektübersicht verwendet dafür den separaten Collection-Endpunkt `POST /api/projects/import`, der ausschließlich eine neue Kopie anlegt und deshalb weder eine bestehende Projekt-ID noch `expectedRevision` annimmt. Das @@ -283,8 +278,6 @@ Controller-Schreibweg ist entfernt. Verteilungen besitzen eine optionale Etagenreferenz sowie eine Netzart aus dem Projektkatalog. Anlage und nachträgliche Bearbeitung prüfen die Projektzugehörigkeit der Etage und die Freigabe der Netzart in den Projekteinstellungen. -Gespeicherte Anlage-Commands der Schemas 1 und 2 bleiben mit ihren vier -Legacy-Abschnitten und ohne nachträglich erfundene Komponenten ausführbar. Bereits befüllte Verteilungen werden über `distribution-board.insert-subtree` und `distribution-board.delete-subtree` als vollständiger Unterbaum kopiert beziehungsweise gelöscht. Der Snapshot @@ -462,32 +455,30 @@ Kopieren in ein Projekt erzeugt ein eigenständiges Projektgerät. - SQLite ist die aktuell unterstützte Datenbank. - Fremdschlüssel werden für jeden Datenbankkontext aktiviert. -- `npm run db:migrate` wendet Drizzle-Migrationen an. +- `npm run db:migrate` richtet mit der einzelnen Migration `0000` das komplette + aktuelle Schema einer leeren Datenbank ein. - `npm run db:verify:circuit-schema` prüft erforderliche und entfernte Spalten. - `npm run db:backup` erzeugt ein konsistentes und verifiziertes Online-Backup. -- `npm run typecheck:scripts` prüft alle TypeScript-Wartungs- und - Upgrade-Skripte mit ihren Anwendungspfaden, ohne Code zu erzeugen. -- Angewendete Migrationen werden niemals nachträglich verändert. -- `db:migrate:legacy-consumers` ist Upgrade-Werkzeug, kein Anwendungspfad. - Der fachliche Migrationsdienst kennt nur schmale Reader-/Store-Ports unter - `src/domain/ports`; konkrete SQLite-Repositories werden ausschließlich im - CLI-Skript zusammengesetzt. +- `npm run typecheck:scripts` prüft die TypeScript-Wartungsskripte, ohne Code zu + erzeugen. +- Die Baseline ersetzt alle vorigen Entwicklungsmigrationen. Datenbanken, + Snapshots und persistierte Commands aus Vor-Baseline-Ständen werden bewusst + nicht unterstützt. Ab der ersten veröffentlichten Version sind angewendete + Migrationen unveränderlich und Änderungen erfolgen additiv. - Allgemeine Circuit-, Gerätezeilen-, CircuitList- und DistributionBoard- Repositories stellen im Anwendungspfad nur noch benötigte Leseabfragen bereit. - Fachliche Schreibvorgänge liegen in den typisierten Command-Repositories; - Upgrade-Schreibvorgänge bleiben in expliziten Migrationsadaptern. + Fachliche Schreibvorgänge liegen in den typisierten Command-Repositories. - Die vollständige Verteilungs-Testfixture liegt unter `tests/support/distribution-board-fixture.ts` und ist kein exportierter Produktions-Schreibweg. -- Migration `0024` bildet die additive relationale Grundlage für geschützte - Stromkreisgruppen und Verteilerkomponenten. Die drei bestehenden - Stromkreisabschnitte erhalten Kategorie und Gruppennummer 1. Separate - 1:1-Tabellen halten künftig Stromkreis- und Komponenten-Schutzgeräte; die - bisherigen flachen Schutzfelder bleiben in dieser Übergangsphase unverändert. +- Die Baseline bildet die relationale Grundlage für geschützte Stromkreisgruppen + und Verteilerkomponenten. Separate + 1:1-Tabellen halten Stromkreis- und Komponenten-Schutzgeräte. Die früheren + flachen Stromkreis-Schutzfelder sind aus der Baseline entfernt. Ein triggergeführtes Register erzwingt bereits eine normalisierte, stromkreislistenweite BMK-Eindeutigkeit über Stromkreise und Verteilerkomponenten. Snapshot- und Transfer-Integration verwenden - Snapshot-Schema 7. Persistente Insert/Delete/Update-Commands für + Snapshot-Schema 1 der Baseline. Persistente Insert/Delete/Update-Commands für veränderliche Verteilerkomponenten, Gruppen einschließlich befüllter Unterbäume sowie vollständige Gruppensortierung sind integriert. Der Editor zeigt die geschützte Struktur an und bearbeitet veränderliche Gruppen- und diff --git a/docs/development-workflow.md b/docs/development-workflow.md index b4447f0..b19b7ff 100644 --- a/docs/development-workflow.md +++ b/docs/development-workflow.md @@ -96,18 +96,19 @@ erneut direkte Schreibmethoden erhalten. ## Migrationen -1. Bestehende lokale Datenbank sichern: `npm run db:backup`. -2. Schema unter `src/db/schema/` ändern. -3. `npm run db:generate` ausführen. -4. Das generierte SQL vollständig prüfen; es darf nur die beabsichtigte Änderung +1. Schema unter `src/db/schema/` ändern. +2. `npm run db:generate` ausführen. +3. Das generierte SQL vollständig prüfen; es darf nur die beabsichtigte Änderung enthalten. -5. Upgrade-/Erhaltungstest ergänzen, wenn Spalten oder Beziehungen geändert +4. Upgrade-/Erhaltungstest ergänzen, wenn Spalten oder Beziehungen geändert werden. -6. `npm test`, `npm run db:migrate` und +5. `npm test`, `npm run db:migrate` und `npm run db:verify:circuit-schema` ausführen. -Bereits angewendete SQL-Migrationen dürfen nicht geändert oder neu sortiert -werden. Korrekturen erfolgen immer über eine neue Migration. +`0000` ist die saubere Baseline für leere Neuinstallationen. Vor-Baseline- +Entwicklungsdatenbanken werden nicht aktualisiert. Nach Veröffentlichung der +ersten Version dürfen angewendete SQL-Migrationen nicht geändert oder neu +sortiert werden; Korrekturen erfolgen dann immer über eine neue Migration. ## Pull-Request-Handoff diff --git a/docs/local-db-circuit-first-migration.md b/docs/local-db-circuit-first-migration.md deleted file mode 100644 index 995f6bf..0000000 --- a/docs/local-db-circuit-first-migration.md +++ /dev/null @@ -1,137 +0,0 @@ -# Local DB Migration: Circuit-First Schema - -This project uses SQLite at `data/leistungsbilanz.db` and Drizzle migrations in `src/db/migrations`. - -This document is an upgrade runbook for databases created before the Circuit-First -cutover. A clean installation only needs the normal `db:migrate` and schema -verification steps documented in the main README. - -## Safe command order - -1. Backup local DB (required before schema/data migration) - -```bash -npm run db:backup -``` - -The command uses SQLite's online backup API, so committed WAL changes are included -even while the application is running. It opens the resulting standalone database -and requires both `PRAGMA integrity_check` and `PRAGMA foreign_key_check` to pass. -Database backups are operational recovery files and remain separate from the future -user-visible project version history. - -2. Apply pending schema migrations (includes `0008_circuit_first_model`, the additive - `0009_project_device_circuit_fields` transition and the post-cutover - `0011_project_device_canonical_fields` cleanup) - -```bash -npm run db:migrate -``` - -3. Verify circuit-first tables exist - -```bash -npm run db:verify:circuit-schema -``` - -4. Backfill default sections for existing `circuit_lists` - -```bash -npm run db:backfill:sections -``` - -5. Run legacy consumer -> circuit/device-row migration explicitly - -```bash -npm run db:migrate:legacy-consumers -``` - -## Verification SQL - -Run these against `data/leistungsbilanz.db`: - -```sql -SELECT name -FROM sqlite_master -WHERE type = 'table' - AND name IN ( - 'circuit_sections', - 'circuits', - 'circuit_device_rows', - 'legacy_consumer_circuit_migrations', - 'legacy_consumer_migration_reports' - ) -ORDER BY name; -``` - -The verification command also checks the circuit-first project-device columns added by migration `0009`. - -```sql -SELECT circuit_list_id, key, prefix, sort_order -FROM circuit_sections -ORDER BY circuit_list_id, sort_order; -``` - -```sql -SELECT circuit_list_id, COUNT(*) AS circuits -FROM circuits -GROUP BY circuit_list_id; -``` - -```sql -SELECT c.circuit_list_id, COUNT(r.id) AS device_rows -FROM circuits c -LEFT JOIN circuit_device_rows r ON r.circuit_id = c.id -GROUP BY c.circuit_list_id; -``` - -## API verification - -After the steps above: - -`GET /api/projects/:projectId/circuit-lists/:circuitListId/tree` - -Expected response shape: - -```json -{ - "circuitListId": "string", - "sections": [ - { - "id": "string", - "key": "lighting|single_phase|three_phase|unassigned|...", - "displayName": "string", - "prefix": "-1F|-2F|-3F|-UF|...", - "sortOrder": 10, - "circuits": [ - { - "id": "string", - "equipmentIdentifier": "-2F1", - "displayName": "string", - "sortOrder": 10, - "isReserve": false, - "circuitTotalPower": 1.23, - "deviceRows": [ - { - "id": "string", - "displayName": "string", - "quantity": 1, - "powerPerUnit": 0.3, - "simultaneityFactor": 1, - "rowTotalPower": 0.3 - } - ] - } - ] - } - ] -} -``` - -If migrations were not applied, endpoint may return an empty fallback with a warning. - -## Visual verification - -Manual device rows and multi-device circuits can be created directly in the -circuit-list editor. The former development scripts for direct database writes -were removed because they bypassed project revisions and persistent undo/redo. diff --git a/docs/project-history-and-external-model-architecture.md b/docs/project-history-and-external-model-architecture.md index dffecfc..ae03868 100644 --- a/docs/project-history-and-external-model-architecture.md +++ b/docs/project-history-and-external-model-architecture.md @@ -93,8 +93,6 @@ Implemented named-snapshot foundation: - restore records a new `restore` revision containing both the selected target state and the complete pre-restore inverse; undo/redo therefore remains available after application restarts -- compatible upgrade-only Consumer links, mappings and reports are preserved - separately and are never imported into the logical snapshot payload - arbitrary restore payloads are rejected by the generic user-command endpoint; only server-stored snapshots can initiate a forward restore - the project page provides an initially collapsed snapshot/timeline panel, diff --git a/docs/spec/07-implementation-phases-todo.md b/docs/spec/07-implementation-phases-todo.md index 03b6a4c..16124c0 100644 --- a/docs/spec/07-implementation-phases-todo.md +++ b/docs/spec/07-implementation-phases-todo.md @@ -342,9 +342,8 @@ Implemented foundation: - circuit-device-row transaction tests cover both successful commits and forced SQLite rollbacks - project-device row synchronization has real multi-row SQLite commit and rollback coverage - BMK swaps and section reorder have real SQLite commit and rollback coverage -- the legacy consumer migration service depends only on narrow domain ports; - all concrete repositories are composed at the script entry point -- legacy circuit, row, mapping and report writes have real late-failure rollback coverage +- the former Consumer migration service, mappings and reports were removed with + the pre-release database cutover - circuit and device-row persistence value mapping is separated from the general repositories - obsolete direct Circuit, CircuitDeviceRow, CircuitList, DistributionBoard and Project repository writes are removed; integration fixtures live under @@ -362,8 +361,9 @@ Implemented foundation: direct global SQLite access - TypeScript maintenance and upgrade scripts have a dedicated no-emit typecheck, including all referenced application modules -- the legacy consumer UI and application read/write endpoints are removed after verified data cutover -- retained legacy rows are accessible only through explicit database upgrade tooling +- the former Consumer UI, API, tables and upgrade tooling are removed +- migration `0000` is the clean baseline for new installations; pre-baseline + development databases are intentionally unsupported - project devices no longer persist duplicate legacy power, phase, cosPhi or remark fields ## Phase 12: Project Revisions and Persistent Undo / Redo @@ -618,7 +618,8 @@ Implemented handoff: - README is a concise setup and project entry point without prototype status lists - `docs/README.md` separates current, operational, future, specification and archived material -- current runtime, module boundaries and upgrade-only legacy data are documented explicitly +- current runtime and module boundaries are documented without unsupported + upgrade-only data paths - contributor workflow covers clean databases, safe demo data, migrations, tests and commits - development Compose is clearly separated from the currently unsupported production deployment - `AGENTS.md` points LLM-assisted work to supported code paths and deferred architecture diff --git a/package.json b/package.json index 4216834..7f61d4d 100644 --- a/package.json +++ b/package.json @@ -15,14 +15,12 @@ "build:web": "next build", "typecheck:scripts": "tsc --noEmit -p tsconfig.scripts.json", "start": "node dist/server/index.js", - "test": "tsx --test tests/protection-device.test.ts tests/distribution-board-component.test.ts tests/distribution-board-component-schema-migration.test.ts tests/circuit-group-numbering.test.ts tests/project-device-schema.test.ts tests/project-device-schema-migration.test.ts tests/project-device-placement.service.test.ts tests/project-device-sync.service.test.ts tests/legacy-consumer-migration-planner.test.ts tests/legacy-consumer-migration.service.test.ts tests/legacy-consumer-migration.repository.test.ts tests/circuit-numbering.service.test.ts tests/circuit-power-calculation.test.ts tests/circuit-tree.controller.test.ts tests/circuit-editor-history.test.ts tests/circuit-grid-insertion.test.ts tests/circuit-grid-safety.test.ts tests/circuit-grid-model.test.ts tests/circuit-structure-command.test.ts tests/circuit-device-row-move-command.test.ts tests/circuit-section-reorder-command.test.ts tests/circuit-section-renumber-command.test.ts tests/circuit-grid-projection.test.ts tests/distribution-board-structure-project-command.repository.test.ts tests/project-location-structure-project-command.repository.test.ts tests/project-device-project-command.repository.test.ts tests/project-device-structure-project-command.repository.test.ts tests/project-device-row-sync-project-command.repository.test.ts tests/circuit-section-reorder-project-command.repository.test.ts tests/circuit-section-renumber-project-command.repository.test.ts tests/project-command.model.test.ts tests/project-revision.persistence.test.ts tests/circuit-project-command.repository.test.ts tests/circuit-structure-project-command.repository.test.ts tests/circuit-device-row-project-command.repository.test.ts tests/circuit-device-row-structure-project-command.repository.test.ts tests/circuit-device-row-move-project-command.repository.test.ts tests/project-history.repository.test.ts tests/project-history-timeline.test.ts tests/project-version-history.test.ts tests/project-overview-import.test.ts tests/project-settings-project-command.repository.test.ts tests/project-state-snapshot.test.ts tests/project-snapshot-policy.test.ts tests/project-snapshot.repository.test.ts tests/project-state-restore-command.repository.test.ts tests/project-command.service.test.ts tests/database-backup.test.ts", - "test:watch": "tsx --watch --test tests/protection-device.test.ts tests/distribution-board-component.test.ts tests/distribution-board-component-schema-migration.test.ts tests/circuit-group-numbering.test.ts tests/project-device-schema.test.ts tests/project-device-schema-migration.test.ts tests/project-device-placement.service.test.ts tests/project-device-sync.service.test.ts tests/legacy-consumer-migration-planner.test.ts tests/legacy-consumer-migration.service.test.ts tests/legacy-consumer-migration.repository.test.ts tests/circuit-numbering.service.test.ts tests/circuit-power-calculation.test.ts tests/circuit-tree.controller.test.ts tests/circuit-editor-history.test.ts tests/circuit-grid-insertion.test.ts tests/circuit-grid-safety.test.ts tests/circuit-grid-model.test.ts tests/circuit-structure-command.test.ts tests/circuit-device-row-move-command.test.ts tests/circuit-section-reorder-command.test.ts tests/circuit-section-renumber-command.test.ts tests/circuit-grid-projection.test.ts tests/distribution-board-structure-project-command.repository.test.ts tests/project-location-structure-project-command.repository.test.ts tests/project-device-project-command.repository.test.ts tests/project-device-structure-project-command.repository.test.ts tests/project-device-row-sync-project-command.repository.test.ts tests/circuit-section-reorder-project-command.repository.test.ts tests/circuit-section-renumber-project-command.repository.test.ts tests/project-command.model.test.ts tests/project-revision.persistence.test.ts tests/circuit-project-command.repository.test.ts tests/circuit-structure-project-command.repository.test.ts tests/circuit-device-row-project-command.repository.test.ts tests/circuit-device-row-structure-project-command.repository.test.ts tests/circuit-device-row-move-project-command.repository.test.ts tests/project-history.repository.test.ts tests/project-history-timeline.test.ts tests/project-version-history.test.ts tests/project-overview-import.test.ts tests/project-settings-project-command.repository.test.ts tests/project-state-snapshot.test.ts tests/project-snapshot-policy.test.ts tests/project-snapshot.repository.test.ts tests/project-state-restore-command.repository.test.ts tests/project-command.service.test.ts tests/database-backup.test.ts", + "test": "node scripts/run-tests.mjs", + "test:watch": "node scripts/run-tests.mjs --watch", "db:generate": "drizzle-kit generate", "db:migrate": "drizzle-kit migrate", "db:backup": "tsx scripts/db-backup.ts", - "db:verify:circuit-schema": "node scripts/db-verify-circuit-schema.js", - "db:backfill:sections": "tsx scripts/db-backfill-sections.ts", - "db:migrate:legacy-consumers": "tsx scripts/db-migrate-legacy-consumers.ts" + "db:verify:circuit-schema": "node scripts/db-verify-circuit-schema.js" }, "keywords": [], "author": "", diff --git a/scripts/db-backfill-sections.ts b/scripts/db-backfill-sections.ts deleted file mode 100644 index 08deb06..0000000 --- a/scripts/db-backfill-sections.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { db } from "../src/db/client.js"; -import { CircuitListRepository } from "../src/db/repositories/circuit-list.repository.js"; -import { CircuitSectionRepository } from "../src/db/repositories/circuit-section.repository.js"; -import { ProjectRepository } from "../src/db/repositories/project.repository.js"; - -const projectRepository = new ProjectRepository(db); -const circuitListRepository = new CircuitListRepository(db); -const circuitSectionRepository = new CircuitSectionRepository(db); - -async function run() { - const projects = await projectRepository.list(); - let totalLists = 0; - for (const project of projects) { - const lists = await circuitListRepository.listByProject(project.id); - for (const list of lists) { - await circuitSectionRepository.createDefaults(list.id); - totalLists += 1; - } - } - console.log(`Section backfill done for ${totalLists} circuit list(s).`); -} - -run().catch((error) => { - console.error("Section backfill failed:", error); - process.exit(1); -}); diff --git a/scripts/db-migrate-legacy-consumers.ts b/scripts/db-migrate-legacy-consumers.ts deleted file mode 100644 index 7da8d70..0000000 --- a/scripts/db-migrate-legacy-consumers.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { db } from "../src/db/client.js"; -import { CircuitRepository } from "../src/db/repositories/circuit.repository.js"; -import { CircuitListRepository } from "../src/db/repositories/circuit-list.repository.js"; -import { CircuitSectionRepository } from "../src/db/repositories/circuit-section.repository.js"; -import { LegacyConsumerMigrationRepository } from "../src/db/repositories/legacy-consumer-migration.repository.js"; -import { ProjectRepository } from "../src/db/repositories/project.repository.js"; -import { RoomRepository } from "../src/db/repositories/room.repository.js"; -import { LegacyConsumerMigrationService } from "../src/domain/services/legacy-consumer-migration.service.js"; - -const projectRepository = new ProjectRepository(db); -const circuitListRepository = new CircuitListRepository(db); -const migrationRepository = new LegacyConsumerMigrationRepository(db); -const migrationService = new LegacyConsumerMigrationService({ - circuitListReader: circuitListRepository, - sectionStore: new CircuitSectionRepository(db), - circuitReader: new CircuitRepository(db), - roomReader: new RoomRepository(db), - migrationStore: migrationRepository, -}); - -async function run() { - const projects = await projectRepository.list(); - const reports = []; - - for (const project of projects) { - const lists = await circuitListRepository.listByProject(project.id); - for (const list of lists) { - const report = await migrationService.migrateCircuitList(project.id, list.id); - reports.push({ - projectId: project.id, - circuitListId: list.id, - legacyConsumerCount: report.legacyConsumerCount, - createdCircuitCount: report.createdCircuitCount, - createdDeviceRowCount: report.createdDeviceRowCount, - generatedIdentifiers: report.generatedIdentifiers.length, - unassignedRows: report.unassignedRows.length, - }); - } - } - - const unmigratedConsumers = - await migrationRepository.listUnmigratedConsumers(); - if (unmigratedConsumers.length > 0) { - const withoutCircuitList = unmigratedConsumers.filter( - (consumer) => !consumer.circuitListId - ).length; - throw new Error( - `Cutover verification failed: ${unmigratedConsumers.length} legacy consumer(s) remain unmigrated` + - ` (${withoutCircuitList} without a circuit list).` - ); - } - - console.log("Legacy consumer migration summary:"); - console.table(reports); - console.log("Cutover verification passed: all legacy consumers are mapped."); -} - -run().catch((error) => { - console.error("Legacy consumer migration failed:", error); - process.exit(1); -}); diff --git a/scripts/db-verify-circuit-schema.js b/scripts/db-verify-circuit-schema.js index 0fff995..6d291f0 100644 --- a/scripts/db-verify-circuit-schema.js +++ b/scripts/db-verify-circuit-schema.js @@ -12,8 +12,6 @@ const requiredTables = [ "circuit_protection_devices", "distribution_board_components", "distribution_board_component_protection_devices", - "legacy_consumer_circuit_migrations", - "legacy_consumer_migration_reports", ]; const tablePlaceholders = requiredTables.map(() => "?").join(", "); @@ -57,6 +55,14 @@ const circuitColumns = new Set( db.prepare("PRAGMA table_info(circuits)").all().map((column) => column.name) ); const missingCircuitColumns = requiredCircuitColumns.filter((name) => !circuitColumns.has(name)); +const removedCircuitColumns = [ + "protection_type", + "protection_rated_current", + "protection_characteristic", +]; +const remainingRemovedCircuitColumns = removedCircuitColumns.filter((name) => + circuitColumns.has(name) +); const requiredCircuitSectionColumns = ["category", "group_number"]; const circuitSectionColumns = new Set( db @@ -164,6 +170,14 @@ if (missingCircuitColumns.length > 0) { process.exit(1); } +if (remainingRemovedCircuitColumns.length > 0) { + console.error( + "Transitional circuit protection columns still present:", + remainingRemovedCircuitColumns.join(", ") + ); + process.exit(1); +} + if (missingCircuitSectionColumns.length > 0) { console.error( "Missing circuit-section columns:", diff --git a/scripts/run-tests.mjs b/scripts/run-tests.mjs new file mode 100644 index 0000000..ab48b36 --- /dev/null +++ b/scripts/run-tests.mjs @@ -0,0 +1,30 @@ +import { readdirSync } from "node:fs"; +import { spawnSync } from "node:child_process"; +import path from "node:path"; + +const testFiles = readdirSync(path.resolve("tests"), { + withFileTypes: true, +}) + .filter((entry) => entry.isFile() && entry.name.endsWith(".test.ts")) + .map((entry) => path.join("tests", entry.name)) + .sort(); + +if (testFiles.length === 0) { + throw new Error("No TypeScript test files found."); +} + +const watch = process.argv.includes("--watch"); +const result = spawnSync( + process.execPath, + [ + "--import", + "tsx", + "--test", + "--test-concurrency=1", + ...(watch ? ["--watch"] : []), + ...testFiles, + ], + { stdio: "inherit" } +); + +process.exit(result.status ?? 1); diff --git a/src/db/migrations/0000_bizarre_colossus.sql b/src/db/migrations/0000_bizarre_colossus.sql deleted file mode 100644 index 71e123f..0000000 --- a/src/db/migrations/0000_bizarre_colossus.sql +++ /dev/null @@ -1,28 +0,0 @@ -CREATE TABLE `consumers` ( - `id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `distribution_board_id` text, - `name` text NOT NULL, - `category` text, - `quantity` integer NOT NULL, - `installed_power_per_unit_kw` real NOT NULL, - `demand_factor` real NOT NULL, - `voltage_v` real, - `phase_count` integer, - `power_factor` real, - `note` text, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`distribution_board_id`) REFERENCES `distribution_boards`(`id`) ON UPDATE no action ON DELETE set null -); ---> statement-breakpoint -CREATE TABLE `distribution_boards` ( - `id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `name` text NOT NULL, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `projects` ( - `id` text PRIMARY KEY NOT NULL, - `name` text NOT NULL -); diff --git a/src/db/migrations/0000_whole_surge.sql b/src/db/migrations/0000_whole_surge.sql new file mode 100644 index 0000000..ad5a66f --- /dev/null +++ b/src/db/migrations/0000_whole_surge.sql @@ -0,0 +1,300 @@ +CREATE TABLE `circuit_device_rows` ( + `id` text PRIMARY KEY NOT NULL, + `circuit_id` text NOT NULL, + `linked_project_device_id` text, + `sort_order` integer DEFAULT 0 NOT NULL, + `name` text NOT NULL, + `display_name` text NOT NULL, + `phase_type` text, + `connection_kind` text, + `cost_group` text, + `category` text, + `level` text, + `room_id` text, + `room_number_snapshot` text, + `room_name_snapshot` text, + `quantity` integer NOT NULL, + `power_per_unit` real NOT NULL, + `simultaneity_factor` real NOT NULL, + `cos_phi` real, + `remark` text, + `overridden_fields` text, + FOREIGN KEY (`circuit_id`) REFERENCES `circuits`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`linked_project_device_id`) REFERENCES `project_devices`(`id`) ON UPDATE no action ON DELETE set null, + FOREIGN KEY (`room_id`) REFERENCES `rooms`(`id`) ON UPDATE no action ON DELETE set null +); +--> statement-breakpoint +CREATE TABLE `circuit_list_equipment_identifiers` ( + `owner_type` text NOT NULL, + `owner_id` text NOT NULL, + `circuit_list_id` text NOT NULL, + `equipment_identifier` text NOT NULL, + FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `circuit_list_equipment_identifiers_owner_unique` ON `circuit_list_equipment_identifiers` (`owner_type`,`owner_id`);--> statement-breakpoint +CREATE UNIQUE INDEX `circuit_list_equipment_identifiers_list_identifier_unique` ON `circuit_list_equipment_identifiers` (`circuit_list_id`,`equipment_identifier`);--> statement-breakpoint +CREATE TABLE `circuit_lists` ( + `id` text PRIMARY KEY NOT NULL, + `project_id` text NOT NULL, + `distribution_board_id` text NOT NULL, + `name` text NOT NULL, + FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`distribution_board_id`) REFERENCES `distribution_boards`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `circuit_lists_distribution_board_id_unique` ON `circuit_lists` (`distribution_board_id`);--> statement-breakpoint +CREATE TABLE `circuit_protection_devices` ( + `circuit_id` text PRIMARY KEY NOT NULL, + `type` text NOT NULL, + `rated_current_a` real NOT NULL, + `fuse_utilization_category` text, + `trip_characteristic` text, + `rcd_type` text, + `rated_residual_current_ma` real, + FOREIGN KEY (`circuit_id`) REFERENCES `circuits`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `circuit_sections` ( + `id` text PRIMARY KEY NOT NULL, + `circuit_list_id` text NOT NULL, + `key` text NOT NULL, + `display_name` text NOT NULL, + `prefix` text NOT NULL, + `sort_order` integer DEFAULT 0 NOT NULL, + `category` text, + `group_number` integer, + FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `circuit_sections_list_key_unique` ON `circuit_sections` (`circuit_list_id`,`key`);--> statement-breakpoint +CREATE UNIQUE INDEX `circuit_sections_list_prefix_unique` ON `circuit_sections` (`circuit_list_id`,`prefix`);--> statement-breakpoint +CREATE UNIQUE INDEX `circuit_sections_list_category_group_unique` ON `circuit_sections` (`circuit_list_id`,`category`,`group_number`);--> statement-breakpoint +CREATE TABLE `circuits` ( + `id` text PRIMARY KEY NOT NULL, + `circuit_list_id` text NOT NULL, + `section_id` text NOT NULL, + `equipment_identifier` text NOT NULL, + `display_name` text, + `sort_order` integer DEFAULT 0 NOT NULL, + `cable_type` text, + `cable_cross_section` text, + `cable_length` real, + `rcd_assignment` text, + `terminal_designation` text, + `voltage` real, + `control_requirement` text, + `status` text, + `is_reserve` integer DEFAULT 0 NOT NULL, + `remark` text, + FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`section_id`) REFERENCES `circuit_sections`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `circuits_list_equipment_identifier_unique` ON `circuits` (`circuit_list_id`,`equipment_identifier`);--> statement-breakpoint +CREATE TABLE `distribution_board_component_protection_devices` ( + `component_id` text PRIMARY KEY NOT NULL, + `type` text NOT NULL, + `rated_current_a` real NOT NULL, + `fuse_utilization_category` text, + `trip_characteristic` text, + `rcd_type` text, + `rated_residual_current_ma` real, + FOREIGN KEY (`component_id`) REFERENCES `distribution_board_components`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `distribution_board_components` ( + `id` text PRIMARY KEY NOT NULL, + `circuit_list_id` text NOT NULL, + `section_id` text, + `equipment_identifier` text NOT NULL, + `name` text NOT NULL, + `role` text NOT NULL, + `placement` text NOT NULL, + `sort_order` integer DEFAULT 0 NOT NULL, + FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`section_id`) REFERENCES `circuit_sections`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `distribution_board_components_list_identifier_unique` ON `distribution_board_components` (`circuit_list_id`,`equipment_identifier`);--> statement-breakpoint +CREATE UNIQUE INDEX `distribution_board_components_section_role_unique` ON `distribution_board_components` (`section_id`,`role`);--> statement-breakpoint +CREATE TABLE `distribution_boards` ( + `id` text PRIMARY KEY NOT NULL, + `project_id` text NOT NULL, + `name` text NOT NULL, + `floor_id` text, + `supply_type` text, + `simultaneity_factor` real DEFAULT 1 NOT NULL, + FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`floor_id`) REFERENCES `floors`(`id`) ON UPDATE no action ON DELETE set null +); +--> statement-breakpoint +CREATE TABLE `floors` ( + `id` text PRIMARY KEY NOT NULL, + `project_id` text NOT NULL, + `name` text NOT NULL, + `sort_order` integer DEFAULT 0 NOT NULL, + FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `global_devices` ( + `id` text PRIMARY KEY NOT NULL, + `name` text NOT NULL, + `display_name` text NOT NULL, + `category` text, + `quantity` integer NOT NULL, + `installed_power_per_unit_kw` real NOT NULL, + `demand_factor` real NOT NULL, + `voltage_v` real, + `phase_count` integer, + `power_factor` real, + `note` text +); +--> statement-breakpoint +CREATE TABLE `project_change_sets` ( + `id` text PRIMARY KEY NOT NULL, + `project_revision_id` text NOT NULL, + `command_type` text NOT NULL, + `payload_schema_version` integer NOT NULL, + `forward_payload_json` text NOT NULL, + `inverse_payload_json` text NOT NULL, + FOREIGN KEY (`project_revision_id`) REFERENCES `project_revisions`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `project_change_sets_revision_unique` ON `project_change_sets` (`project_revision_id`);--> statement-breakpoint +CREATE TABLE `project_devices` ( + `id` text PRIMARY KEY NOT NULL, + `project_id` text NOT NULL, + `name` text NOT NULL, + `display_name` text NOT NULL, + `phase_type` text DEFAULT 'single_phase' NOT NULL, + `connection_kind` text, + `cost_group` text, + `category` text, + `quantity` integer NOT NULL, + `power_per_unit` real DEFAULT 0 NOT NULL, + `simultaneity_factor` real DEFAULT 1 NOT NULL, + `cos_phi` real, + `remark` text, + `voltage_v` real, + FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `project_history_stack_entries` ( + `change_set_id` text PRIMARY KEY NOT NULL, + `project_id` text NOT NULL, + `stack` text NOT NULL, + `position` integer NOT NULL, + FOREIGN KEY (`change_set_id`) REFERENCES `project_change_sets`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, + CONSTRAINT "project_history_stack_entries_stack_check" CHECK("project_history_stack_entries"."stack" in ('undo', 'redo')) +); +--> statement-breakpoint +CREATE UNIQUE INDEX `project_history_stack_entries_position_unique` ON `project_history_stack_entries` (`project_id`,`stack`,`position`);--> statement-breakpoint +CREATE TABLE `project_revisions` ( + `id` text PRIMARY KEY NOT NULL, + `project_id` text NOT NULL, + `revision_number` integer NOT NULL, + `created_at_iso` text NOT NULL, + `actor_id` text, + `source` text NOT NULL, + `description` text, + FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE UNIQUE INDEX `project_revisions_project_number_unique` ON `project_revisions` (`project_id`,`revision_number`);--> statement-breakpoint +CREATE TABLE `project_snapshots` ( + `id` text PRIMARY KEY NOT NULL, + `project_id` text NOT NULL, + `source_revision` integer NOT NULL, + `schema_version` integer NOT NULL, + `kind` text DEFAULT 'named' NOT NULL, + `name` text NOT NULL, + `description` text, + `payload_json` text NOT NULL, + `payload_sha256` text NOT NULL, + `created_at_iso` text NOT NULL, + `created_by_actor_id` text, + FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE INDEX `project_snapshots_project_created_idx` ON `project_snapshots` (`project_id`,`created_at_iso`);--> statement-breakpoint +CREATE INDEX `project_snapshots_project_kind_revision_idx` ON `project_snapshots` (`project_id`,`kind`,`source_revision`);--> statement-breakpoint +CREATE UNIQUE INDEX `project_snapshots_project_name_unique` ON `project_snapshots` (`project_id`,`name`);--> statement-breakpoint +CREATE TABLE `projects` ( + `id` text PRIMARY KEY NOT NULL, + `name` text NOT NULL, + `internal_project_number` text, + `external_project_number` text, + `building_owner` text, + `description` text, + `single_phase_voltage_v` integer DEFAULT 230 NOT NULL, + `three_phase_voltage_v` integer DEFAULT 400 NOT NULL, + `enabled_distribution_board_supply_types` text DEFAULT '["AV","SV","EV","USV","MSR","SiBe"]' NOT NULL, + `current_revision` integer DEFAULT 0 NOT NULL +); +--> statement-breakpoint +CREATE TABLE `rooms` ( + `id` text PRIMARY KEY NOT NULL, + `project_id` text NOT NULL, + `floor_id` text, + `room_number` text NOT NULL, + `room_name` text NOT NULL, + FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, + FOREIGN KEY (`floor_id`) REFERENCES `floors`(`id`) ON UPDATE no action ON DELETE set null +); +--> statement-breakpoint +CREATE UNIQUE INDEX `circuit_list_equipment_identifiers_normalized_unique` +ON `circuit_list_equipment_identifiers` (`circuit_list_id`, lower(trim(`equipment_identifier`))); +--> statement-breakpoint +CREATE UNIQUE INDEX `distribution_board_components_fixed_role_unique` +ON `distribution_board_components` (`circuit_list_id`, `role`) +WHERE `role` IN ('main_switch', 'surge_protective_device'); +--> statement-breakpoint +CREATE TRIGGER `circuits_equipment_identifier_insert` +AFTER INSERT ON `circuits` +BEGIN + INSERT INTO `circuit_list_equipment_identifiers` + (`owner_type`, `owner_id`, `circuit_list_id`, `equipment_identifier`) + VALUES ('circuit', NEW.`id`, NEW.`circuit_list_id`, NEW.`equipment_identifier`); +END; +--> statement-breakpoint +CREATE TRIGGER `circuits_equipment_identifier_update` +AFTER UPDATE OF `circuit_list_id`, `equipment_identifier` ON `circuits` +BEGIN + UPDATE `circuit_list_equipment_identifiers` + SET `circuit_list_id` = NEW.`circuit_list_id`, + `equipment_identifier` = NEW.`equipment_identifier` + WHERE `owner_type` = 'circuit' AND `owner_id` = OLD.`id`; +END; +--> statement-breakpoint +CREATE TRIGGER `circuits_equipment_identifier_delete` +AFTER DELETE ON `circuits` +BEGIN + DELETE FROM `circuit_list_equipment_identifiers` + WHERE `owner_type` = 'circuit' AND `owner_id` = OLD.`id`; +END; +--> statement-breakpoint +CREATE TRIGGER `distribution_board_components_equipment_identifier_insert` +AFTER INSERT ON `distribution_board_components` +BEGIN + INSERT INTO `circuit_list_equipment_identifiers` + (`owner_type`, `owner_id`, `circuit_list_id`, `equipment_identifier`) + VALUES ('distribution_board_component', NEW.`id`, NEW.`circuit_list_id`, NEW.`equipment_identifier`); +END; +--> statement-breakpoint +CREATE TRIGGER `distribution_board_components_equipment_identifier_update` +AFTER UPDATE OF `circuit_list_id`, `equipment_identifier` ON `distribution_board_components` +BEGIN + UPDATE `circuit_list_equipment_identifiers` + SET `circuit_list_id` = NEW.`circuit_list_id`, + `equipment_identifier` = NEW.`equipment_identifier` + WHERE `owner_type` = 'distribution_board_component' AND `owner_id` = OLD.`id`; +END; +--> statement-breakpoint +CREATE TRIGGER `distribution_board_components_equipment_identifier_delete` +AFTER DELETE ON `distribution_board_components` +BEGIN + DELETE FROM `circuit_list_equipment_identifiers` + WHERE `owner_type` = 'distribution_board_component' AND `owner_id` = OLD.`id`; +END; diff --git a/src/db/migrations/0001_global_devices.sql b/src/db/migrations/0001_global_devices.sql deleted file mode 100644 index 8a065b1..0000000 --- a/src/db/migrations/0001_global_devices.sql +++ /dev/null @@ -1,12 +0,0 @@ -CREATE TABLE `global_devices` ( - `id` text PRIMARY KEY NOT NULL, - `name` text NOT NULL, - `category` text, - `quantity` integer NOT NULL, - `installed_power_per_unit_kw` real NOT NULL, - `demand_factor` real NOT NULL, - `voltage_v` real, - `phase_count` integer, - `power_factor` real, - `note` text -); diff --git a/src/db/migrations/0002_project_voltage_defaults.sql b/src/db/migrations/0002_project_voltage_defaults.sql deleted file mode 100644 index a1671c9..0000000 --- a/src/db/migrations/0002_project_voltage_defaults.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `projects` ADD COLUMN `single_phase_voltage_v` integer NOT NULL DEFAULT 230; ---> statement-breakpoint -ALTER TABLE `projects` ADD COLUMN `three_phase_voltage_v` integer NOT NULL DEFAULT 400; diff --git a/src/db/migrations/0003_project_floors_rooms.sql b/src/db/migrations/0003_project_floors_rooms.sql deleted file mode 100644 index 1cc95e3..0000000 --- a/src/db/migrations/0003_project_floors_rooms.sql +++ /dev/null @@ -1,19 +0,0 @@ -CREATE TABLE `floors` ( - `id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `name` text NOT NULL, - `sort_order` integer NOT NULL DEFAULT 0, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `rooms` ( - `id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `floor_id` text, - `room_number` text NOT NULL, - `room_name` text NOT NULL, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`floor_id`) REFERENCES `floors`(`id`) ON UPDATE no action ON DELETE set null -); ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `room_id` text REFERENCES `rooms`(`id`) ON UPDATE no action ON DELETE set null; diff --git a/src/db/migrations/0004_circuit_lists_and_entry_fields.sql b/src/db/migrations/0004_circuit_lists_and_entry_fields.sql deleted file mode 100644 index 263a255..0000000 --- a/src/db/migrations/0004_circuit_lists_and_entry_fields.sql +++ /dev/null @@ -1,44 +0,0 @@ -CREATE TABLE `circuit_lists` ( - `id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `distribution_board_id` text NOT NULL, - `name` text NOT NULL, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`distribution_board_id`) REFERENCES `distribution_boards`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE UNIQUE INDEX `circuit_lists_distribution_board_id_unique` ON `circuit_lists` (`distribution_board_id`); ---> statement-breakpoint -INSERT INTO `circuit_lists` (`id`, `project_id`, `distribution_board_id`, `name`) -SELECT `id`, `project_id`, `id`, `name` || ' Stromkreisliste' -FROM `distribution_boards`; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `circuit_list_id` text REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE set null; ---> statement-breakpoint -UPDATE `consumers` SET `circuit_list_id` = `distribution_board_id` WHERE `distribution_board_id` IS NOT NULL; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `circuit_number` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `description` text; ---> statement-breakpoint -UPDATE `consumers` SET `description` = `name` WHERE `description` IS NULL; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `device_type` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `phase_type` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `trade_or_cost_group` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `group_name` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `protection_type` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `protection_rated_current` real; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `protection_characteristic` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `cable_type` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `cable_cross_section` text; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `comment` text; diff --git a/src/db/migrations/0005_project_devices.sql b/src/db/migrations/0005_project_devices.sql deleted file mode 100644 index 5199be3..0000000 --- a/src/db/migrations/0005_project_devices.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE `project_devices` ( - `id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `name` text NOT NULL, - `category` text, - `quantity` integer NOT NULL, - `installed_power_per_unit_kw` real NOT NULL, - `demand_factor` real NOT NULL, - `voltage_v` real, - `phase_count` integer, - `power_factor` real, - `note` text, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade -); diff --git a/src/db/migrations/0006_device_display_name.sql b/src/db/migrations/0006_device_display_name.sql deleted file mode 100644 index ce753a0..0000000 --- a/src/db/migrations/0006_device_display_name.sql +++ /dev/null @@ -1,7 +0,0 @@ -ALTER TABLE `global_devices` ADD COLUMN `display_name` text; ---> statement-breakpoint -UPDATE `global_devices` SET `display_name` = `name` WHERE `display_name` IS NULL; ---> statement-breakpoint -ALTER TABLE `project_devices` ADD COLUMN `display_name` text; ---> statement-breakpoint -UPDATE `project_devices` SET `display_name` = `name` WHERE `display_name` IS NULL; diff --git a/src/db/migrations/0007_consumer_device_link.sql b/src/db/migrations/0007_consumer_device_link.sql deleted file mode 100644 index d5d667d..0000000 --- a/src/db/migrations/0007_consumer_device_link.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `consumers` ADD COLUMN `project_device_id` text REFERENCES `project_devices`(`id`) ON UPDATE no action ON DELETE set null; ---> statement-breakpoint -ALTER TABLE `consumers` ADD COLUMN `is_linked_to_device` integer NOT NULL DEFAULT 0; diff --git a/src/db/migrations/0008_circuit_first_model.sql b/src/db/migrations/0008_circuit_first_model.sql deleted file mode 100644 index 485a911..0000000 --- a/src/db/migrations/0008_circuit_first_model.sql +++ /dev/null @@ -1,99 +0,0 @@ -CREATE TABLE `circuit_sections` ( - `id` text PRIMARY KEY NOT NULL, - `circuit_list_id` text NOT NULL, - `key` text NOT NULL, - `display_name` text NOT NULL, - `prefix` text NOT NULL, - `sort_order` integer NOT NULL DEFAULT 0, - FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE UNIQUE INDEX `circuit_sections_list_key_unique` ON `circuit_sections` (`circuit_list_id`,`key`); ---> statement-breakpoint -CREATE UNIQUE INDEX `circuit_sections_list_prefix_unique` ON `circuit_sections` (`circuit_list_id`,`prefix`); ---> statement-breakpoint - -CREATE TABLE `circuits` ( - `id` text PRIMARY KEY NOT NULL, - `circuit_list_id` text NOT NULL, - `section_id` text NOT NULL, - `equipment_identifier` text NOT NULL, - `display_name` text, - `sort_order` integer NOT NULL DEFAULT 0, - `protection_type` text, - `protection_rated_current` real, - `protection_characteristic` text, - `cable_type` text, - `cable_cross_section` text, - `cable_length` real, - `rcd_assignment` text, - `terminal_designation` text, - `voltage` real, - `status` text, - `is_reserve` integer NOT NULL DEFAULT 0, - `remark` text, - FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`section_id`) REFERENCES `circuit_sections`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE UNIQUE INDEX `circuits_list_equipment_identifier_unique` ON `circuits` (`circuit_list_id`,`equipment_identifier`); ---> statement-breakpoint - -CREATE TABLE `circuit_device_rows` ( - `id` text PRIMARY KEY NOT NULL, - `circuit_id` text NOT NULL, - `linked_project_device_id` text, - `legacy_consumer_id` text, - `sort_order` integer NOT NULL DEFAULT 0, - `name` text NOT NULL, - `display_name` text NOT NULL, - `phase_type` text, - `connection_kind` text, - `cost_group` text, - `category` text, - `level` text, - `room_id` text, - `room_number_snapshot` text, - `room_name_snapshot` text, - `quantity` integer NOT NULL, - `power_per_unit` real NOT NULL, - `simultaneity_factor` real NOT NULL, - `cos_phi` real, - `remark` text, - `overridden_fields` text, - FOREIGN KEY (`circuit_id`) REFERENCES `circuits`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`linked_project_device_id`) REFERENCES `project_devices`(`id`) ON UPDATE no action ON DELETE set null, - FOREIGN KEY (`room_id`) REFERENCES `rooms`(`id`) ON UPDATE no action ON DELETE set null -); ---> statement-breakpoint - -CREATE TABLE `legacy_consumer_circuit_migrations` ( - `consumer_id` text PRIMARY KEY NOT NULL, - `circuit_id` text NOT NULL, - `circuit_device_row_id` text NOT NULL, - `circuit_list_id` text NOT NULL, - `created_at_iso` text NOT NULL, - FOREIGN KEY (`circuit_id`) REFERENCES `circuits`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`circuit_device_row_id`) REFERENCES `circuit_device_rows`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint - -CREATE TABLE `legacy_consumer_migration_reports` ( - `id` text PRIMARY KEY NOT NULL, - `circuit_list_id` text NOT NULL, - `legacy_consumer_count` integer NOT NULL, - `created_circuit_count` integer NOT NULL, - `created_device_row_count` integer NOT NULL, - `duplicate_grouped_count` integer NOT NULL, - `generated_identifier_count` integer NOT NULL, - `unassigned_row_count` integer NOT NULL, - `warnings_json` text NOT NULL, - `generated_identifiers_json` text NOT NULL, - `duplicate_groups_json` text NOT NULL, - `created_at_iso` text NOT NULL, - FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE UNIQUE INDEX `legacy_consumer_migration_reports_list_unique` ON `legacy_consumer_migration_reports` (`circuit_list_id`); - diff --git a/src/db/migrations/0009_project_device_circuit_fields.sql b/src/db/migrations/0009_project_device_circuit_fields.sql deleted file mode 100644 index 2c2c631..0000000 --- a/src/db/migrations/0009_project_device_circuit_fields.sql +++ /dev/null @@ -1,24 +0,0 @@ -ALTER TABLE `project_devices` ADD COLUMN `phase_type` text NOT NULL DEFAULT 'single_phase'; ---> statement-breakpoint -UPDATE `project_devices` -SET `phase_type` = CASE WHEN `phase_count` = 3 THEN 'three_phase' ELSE 'single_phase' END; ---> statement-breakpoint -ALTER TABLE `project_devices` ADD COLUMN `connection_kind` text; ---> statement-breakpoint -ALTER TABLE `project_devices` ADD COLUMN `cost_group` text; ---> statement-breakpoint -ALTER TABLE `project_devices` ADD COLUMN `power_per_unit` real NOT NULL DEFAULT 0; ---> statement-breakpoint -UPDATE `project_devices` SET `power_per_unit` = `installed_power_per_unit_kw`; ---> statement-breakpoint -ALTER TABLE `project_devices` ADD COLUMN `simultaneity_factor` real NOT NULL DEFAULT 1; ---> statement-breakpoint -UPDATE `project_devices` SET `simultaneity_factor` = `demand_factor`; ---> statement-breakpoint -ALTER TABLE `project_devices` ADD COLUMN `cos_phi` real; ---> statement-breakpoint -UPDATE `project_devices` SET `cos_phi` = `power_factor`; ---> statement-breakpoint -ALTER TABLE `project_devices` ADD COLUMN `remark` text; ---> statement-breakpoint -UPDATE `project_devices` SET `remark` = `note`; diff --git a/src/db/migrations/0010_circuit_control_requirement.sql b/src/db/migrations/0010_circuit_control_requirement.sql deleted file mode 100644 index c51fdf8..0000000 --- a/src/db/migrations/0010_circuit_control_requirement.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `circuits` ADD COLUMN `control_requirement` text; diff --git a/src/db/migrations/0011_project_device_canonical_fields.sql b/src/db/migrations/0011_project_device_canonical_fields.sql deleted file mode 100644 index 1ed5969..0000000 --- a/src/db/migrations/0011_project_device_canonical_fields.sql +++ /dev/null @@ -1,9 +0,0 @@ -ALTER TABLE `project_devices` DROP COLUMN `installed_power_per_unit_kw`; ---> statement-breakpoint -ALTER TABLE `project_devices` DROP COLUMN `demand_factor`; ---> statement-breakpoint -ALTER TABLE `project_devices` DROP COLUMN `phase_count`; ---> statement-breakpoint -ALTER TABLE `project_devices` DROP COLUMN `power_factor`; ---> statement-breakpoint -ALTER TABLE `project_devices` DROP COLUMN `note`; diff --git a/src/db/migrations/0012_project_revision_foundation.sql b/src/db/migrations/0012_project_revision_foundation.sql deleted file mode 100644 index 7df8d19..0000000 --- a/src/db/migrations/0012_project_revision_foundation.sql +++ /dev/null @@ -1,24 +0,0 @@ -CREATE TABLE `project_change_sets` ( - `id` text PRIMARY KEY NOT NULL, - `project_revision_id` text NOT NULL, - `command_type` text NOT NULL, - `payload_schema_version` integer NOT NULL, - `forward_payload_json` text NOT NULL, - `inverse_payload_json` text NOT NULL, - FOREIGN KEY (`project_revision_id`) REFERENCES `project_revisions`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE UNIQUE INDEX `project_change_sets_revision_unique` ON `project_change_sets` (`project_revision_id`);--> statement-breakpoint -CREATE TABLE `project_revisions` ( - `id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `revision_number` integer NOT NULL, - `created_at_iso` text NOT NULL, - `actor_id` text, - `source` text NOT NULL, - `description` text, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE UNIQUE INDEX `project_revisions_project_number_unique` ON `project_revisions` (`project_id`,`revision_number`);--> statement-breakpoint -ALTER TABLE `projects` ADD `current_revision` integer DEFAULT 0 NOT NULL; diff --git a/src/db/migrations/0013_project_history_stacks.sql b/src/db/migrations/0013_project_history_stacks.sql deleted file mode 100644 index 8fd8b30..0000000 --- a/src/db/migrations/0013_project_history_stacks.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `project_history_stack_entries` ( - `change_set_id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `stack` text NOT NULL, - `position` integer NOT NULL, - FOREIGN KEY (`change_set_id`) REFERENCES `project_change_sets`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, - CONSTRAINT "project_history_stack_entries_stack_check" CHECK("project_history_stack_entries"."stack" in ('undo', 'redo')) -); ---> statement-breakpoint -CREATE UNIQUE INDEX `project_history_stack_entries_position_unique` ON `project_history_stack_entries` (`project_id`,`stack`,`position`); diff --git a/src/db/migrations/0014_project_snapshots.sql b/src/db/migrations/0014_project_snapshots.sql deleted file mode 100644 index a088cb4..0000000 --- a/src/db/migrations/0014_project_snapshots.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE `project_snapshots` ( - `id` text PRIMARY KEY NOT NULL, - `project_id` text NOT NULL, - `source_revision` integer NOT NULL, - `schema_version` integer NOT NULL, - `name` text NOT NULL, - `description` text, - `payload_json` text NOT NULL, - `payload_sha256` text NOT NULL, - `created_at_iso` text NOT NULL, - `created_by_actor_id` text, - FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE INDEX `project_snapshots_project_created_idx` ON `project_snapshots` (`project_id`,`created_at_iso`);--> statement-breakpoint -CREATE UNIQUE INDEX `project_snapshots_project_name_unique` ON `project_snapshots` (`project_id`,`name`); \ No newline at end of file diff --git a/src/db/migrations/0015_modern_madame_masque.sql b/src/db/migrations/0015_modern_madame_masque.sql deleted file mode 100644 index 2007787..0000000 --- a/src/db/migrations/0015_modern_madame_masque.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `project_snapshots` ADD `kind` text DEFAULT 'named' NOT NULL;--> statement-breakpoint -CREATE INDEX `project_snapshots_project_kind_revision_idx` ON `project_snapshots` (`project_id`,`kind`,`source_revision`); \ No newline at end of file diff --git a/src/db/migrations/0016_dashing_darkstar.sql b/src/db/migrations/0016_dashing_darkstar.sql deleted file mode 100644 index 2228b1b..0000000 --- a/src/db/migrations/0016_dashing_darkstar.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE `projects` ADD `internal_project_number` text;--> statement-breakpoint -ALTER TABLE `projects` ADD `external_project_number` text;--> statement-breakpoint -ALTER TABLE `projects` ADD `building_owner` text;--> statement-breakpoint -ALTER TABLE `projects` ADD `description` text; \ No newline at end of file diff --git a/src/db/migrations/0017_vengeful_romulus.sql b/src/db/migrations/0017_vengeful_romulus.sql deleted file mode 100644 index 8198de7..0000000 --- a/src/db/migrations/0017_vengeful_romulus.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `distribution_boards` ADD `floor_id` text REFERENCES floors(id);--> statement-breakpoint -ALTER TABLE `distribution_boards` ADD `supply_type` text; \ No newline at end of file diff --git a/src/db/migrations/0018_fancy_argent.sql b/src/db/migrations/0018_fancy_argent.sql deleted file mode 100644 index feab398..0000000 --- a/src/db/migrations/0018_fancy_argent.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `projects` ADD `enabled_distribution_board_supply_types` text DEFAULT '["AV","SV","EV","USV","MSR","SiBe"]' NOT NULL; \ No newline at end of file diff --git a/src/db/migrations/0019_normalize_project_voltages.sql b/src/db/migrations/0019_normalize_project_voltages.sql deleted file mode 100644 index 6d74e31..0000000 --- a/src/db/migrations/0019_normalize_project_voltages.sql +++ /dev/null @@ -1,48 +0,0 @@ -UPDATE `global_devices` -SET `voltage_v` = NULL; ---> statement-breakpoint -UPDATE `project_devices` AS `pd` -SET `voltage_v` = CASE - WHEN `pd`.`phase_type` = 'three_phase' THEN `p`.`three_phase_voltage_v` - ELSE `p`.`single_phase_voltage_v` -END -FROM `projects` AS `p` -WHERE `p`.`id` = `pd`.`project_id`; ---> statement-breakpoint -WITH `derived_circuit_voltages` AS ( - SELECT - `c`.`id` AS `circuit_id`, - CASE - WHEN `cs`.`key` = 'three_phase' THEN `p`.`three_phase_voltage_v` - WHEN `cs`.`key` IN ('lighting', 'single_phase') THEN `p`.`single_phase_voltage_v` - WHEN EXISTS ( - SELECT 1 - FROM `circuit_device_rows` AS `three_phase_row` - WHERE `three_phase_row`.`circuit_id` = `c`.`id` - AND `three_phase_row`.`phase_type` = 'three_phase' - ) AND NOT EXISTS ( - SELECT 1 - FROM `circuit_device_rows` AS `other_row` - WHERE `other_row`.`circuit_id` = `c`.`id` - AND `other_row`.`phase_type` = 'single_phase' - ) THEN `p`.`three_phase_voltage_v` - ELSE `p`.`single_phase_voltage_v` - END AS `derived_voltage` - FROM `circuits` AS `c` - INNER JOIN `circuit_lists` AS `cl` - ON `cl`.`id` = `c`.`circuit_list_id` - INNER JOIN `projects` AS `p` - ON `p`.`id` = `cl`.`project_id` - INNER JOIN `circuit_sections` AS `cs` - ON `cs`.`id` = `c`.`section_id` -) -UPDATE `circuits` -SET `voltage` = ( - SELECT `derived_voltage` - FROM `derived_circuit_voltages` - WHERE `circuit_id` = `circuits`.`id` -) -WHERE `id` IN ( - SELECT `circuit_id` - FROM `derived_circuit_voltages` -); diff --git a/src/db/migrations/0020_normalize_phase_types.sql b/src/db/migrations/0020_normalize_phase_types.sql deleted file mode 100644 index 2ec4303..0000000 --- a/src/db/migrations/0020_normalize_phase_types.sql +++ /dev/null @@ -1,85 +0,0 @@ -UPDATE `project_devices` -SET `phase_type` = CASE - WHEN LOWER(REPLACE(REPLACE(TRIM(`phase_type`), '-', ''), '_', '')) - IN ('1ph', '1phase', '1phasig', 'einphasig', 'singlephase') - THEN 'single_phase' - WHEN LOWER(REPLACE(REPLACE(TRIM(`phase_type`), '-', ''), '_', '')) - IN ('3ph', '3phase', '3phasig', 'dreiphasig', 'threephase') - THEN 'three_phase' - ELSE `phase_type` -END -WHERE LOWER(REPLACE(REPLACE(TRIM(`phase_type`), '-', ''), '_', '')) - IN ( - '1ph', - '1phase', - '1phasig', - 'einphasig', - 'singlephase', - '3ph', - '3phase', - '3phasig', - 'dreiphasig', - 'threephase' - ); ---> statement-breakpoint -UPDATE `circuit_device_rows` -SET `phase_type` = CASE - WHEN LOWER(REPLACE(REPLACE(TRIM(`phase_type`), '-', ''), '_', '')) - IN ('1ph', '1phase', '1phasig', 'einphasig', 'singlephase') - THEN 'single_phase' - WHEN LOWER(REPLACE(REPLACE(TRIM(`phase_type`), '-', ''), '_', '')) - IN ('3ph', '3phase', '3phasig', 'dreiphasig', 'threephase') - THEN 'three_phase' - ELSE `phase_type` -END -WHERE LOWER(REPLACE(REPLACE(TRIM(`phase_type`), '-', ''), '_', '')) - IN ( - '1ph', - '1phase', - '1phasig', - 'einphasig', - 'singlephase', - '3ph', - '3phase', - '3phasig', - 'dreiphasig', - 'threephase' - ); ---> statement-breakpoint -WITH `derived_circuit_voltages` AS ( - SELECT - `c`.`id` AS `circuit_id`, - CASE - WHEN `cs`.`key` = 'three_phase' THEN `p`.`three_phase_voltage_v` - WHEN `cs`.`key` IN ('lighting', 'single_phase') THEN `p`.`single_phase_voltage_v` - WHEN EXISTS ( - SELECT 1 - FROM `circuit_device_rows` AS `three_phase_row` - WHERE `three_phase_row`.`circuit_id` = `c`.`id` - AND `three_phase_row`.`phase_type` = 'three_phase' - ) AND NOT EXISTS ( - SELECT 1 - FROM `circuit_device_rows` AS `single_phase_row` - WHERE `single_phase_row`.`circuit_id` = `c`.`id` - AND `single_phase_row`.`phase_type` = 'single_phase' - ) THEN `p`.`three_phase_voltage_v` - ELSE `p`.`single_phase_voltage_v` - END AS `derived_voltage` - FROM `circuits` AS `c` - INNER JOIN `circuit_lists` AS `cl` - ON `cl`.`id` = `c`.`circuit_list_id` - INNER JOIN `projects` AS `p` - ON `p`.`id` = `cl`.`project_id` - INNER JOIN `circuit_sections` AS `cs` - ON `cs`.`id` = `c`.`section_id` -) -UPDATE `circuits` -SET `voltage` = ( - SELECT `derived_voltage` - FROM `derived_circuit_voltages` - WHERE `circuit_id` = `circuits`.`id` -) -WHERE `id` IN ( - SELECT `circuit_id` - FROM `derived_circuit_voltages` -); diff --git a/src/db/migrations/0021_fill_missing_phase_types.sql b/src/db/migrations/0021_fill_missing_phase_types.sql deleted file mode 100644 index fe6cbf4..0000000 --- a/src/db/migrations/0021_fill_missing_phase_types.sql +++ /dev/null @@ -1,75 +0,0 @@ -UPDATE `circuit_device_rows` -SET `phase_type` = COALESCE( - ( - SELECT `pd`.`phase_type` - FROM `project_devices` AS `pd` - WHERE `pd`.`id` = `circuit_device_rows`.`linked_project_device_id` - AND `pd`.`phase_type` IN ('single_phase', 'three_phase') - ), - ( - SELECT CASE - WHEN `cs`.`key` = 'three_phase' THEN 'three_phase' - WHEN `cs`.`key` IN ('lighting', 'single_phase') THEN 'single_phase' - ELSE NULL - END - FROM `circuits` AS `c` - INNER JOIN `circuit_sections` AS `cs` - ON `cs`.`id` = `c`.`section_id` - WHERE `c`.`id` = `circuit_device_rows`.`circuit_id` - ) -) -WHERE `phase_type` IS NULL - AND ( - EXISTS ( - SELECT 1 - FROM `project_devices` AS `pd` - WHERE `pd`.`id` = `circuit_device_rows`.`linked_project_device_id` - AND `pd`.`phase_type` IN ('single_phase', 'three_phase') - ) - OR EXISTS ( - SELECT 1 - FROM `circuits` AS `c` - INNER JOIN `circuit_sections` AS `cs` - ON `cs`.`id` = `c`.`section_id` - WHERE `c`.`id` = `circuit_device_rows`.`circuit_id` - AND `cs`.`key` IN ('lighting', 'single_phase', 'three_phase') - ) - ); ---> statement-breakpoint -WITH `derived_circuit_voltages` AS ( - SELECT - `c`.`id` AS `circuit_id`, - CASE - WHEN `cs`.`key` = 'three_phase' THEN `p`.`three_phase_voltage_v` - WHEN `cs`.`key` IN ('lighting', 'single_phase') THEN `p`.`single_phase_voltage_v` - WHEN EXISTS ( - SELECT 1 - FROM `circuit_device_rows` AS `three_phase_row` - WHERE `three_phase_row`.`circuit_id` = `c`.`id` - AND `three_phase_row`.`phase_type` = 'three_phase' - ) AND NOT EXISTS ( - SELECT 1 - FROM `circuit_device_rows` AS `single_phase_row` - WHERE `single_phase_row`.`circuit_id` = `c`.`id` - AND `single_phase_row`.`phase_type` = 'single_phase' - ) THEN `p`.`three_phase_voltage_v` - ELSE `p`.`single_phase_voltage_v` - END AS `derived_voltage` - FROM `circuits` AS `c` - INNER JOIN `circuit_lists` AS `cl` - ON `cl`.`id` = `c`.`circuit_list_id` - INNER JOIN `projects` AS `p` - ON `p`.`id` = `cl`.`project_id` - INNER JOIN `circuit_sections` AS `cs` - ON `cs`.`id` = `c`.`section_id` -) -UPDATE `circuits` -SET `voltage` = ( - SELECT `derived_voltage` - FROM `derived_circuit_voltages` - WHERE `circuit_id` = `circuits`.`id` -) -WHERE `id` IN ( - SELECT `circuit_id` - FROM `derived_circuit_voltages` -); diff --git a/src/db/migrations/0022_default_remaining_phase_types.sql b/src/db/migrations/0022_default_remaining_phase_types.sql deleted file mode 100644 index 139bf6b..0000000 --- a/src/db/migrations/0022_default_remaining_phase_types.sql +++ /dev/null @@ -1,7 +0,0 @@ -UPDATE `circuit_device_rows` -SET `phase_type` = 'single_phase' -WHERE `phase_type` IS NULL; ---> statement-breakpoint -UPDATE `global_devices` -SET `phase_count` = 1 -WHERE `phase_count` IS NULL OR `phase_count` NOT IN (1, 3); diff --git a/src/db/migrations/0023_cheerful_night_thrasher.sql b/src/db/migrations/0023_cheerful_night_thrasher.sql deleted file mode 100644 index c68bb46..0000000 --- a/src/db/migrations/0023_cheerful_night_thrasher.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `distribution_boards` ADD `simultaneity_factor` real DEFAULT 1 NOT NULL; \ No newline at end of file diff --git a/src/db/migrations/0024_damp_mister_sinister.sql b/src/db/migrations/0024_damp_mister_sinister.sql deleted file mode 100644 index 3e054c3..0000000 --- a/src/db/migrations/0024_damp_mister_sinister.sql +++ /dev/null @@ -1,150 +0,0 @@ -CREATE TABLE `circuit_list_equipment_identifiers` ( - `owner_type` text NOT NULL, - `owner_id` text NOT NULL, - `circuit_list_id` text NOT NULL, - `equipment_identifier` text NOT NULL, - FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE UNIQUE INDEX `circuit_list_equipment_identifiers_owner_unique` ON `circuit_list_equipment_identifiers` (`owner_type`,`owner_id`);--> statement-breakpoint -CREATE UNIQUE INDEX `circuit_list_equipment_identifiers_list_identifier_unique` ON `circuit_list_equipment_identifiers` (`circuit_list_id`,`equipment_identifier`);--> statement-breakpoint -CREATE TABLE `circuit_protection_devices` ( - `circuit_id` text PRIMARY KEY NOT NULL, - `type` text NOT NULL, - `rated_current_a` real NOT NULL, - `fuse_utilization_category` text, - `trip_characteristic` text, - `rcd_type` text, - `rated_residual_current_ma` real, - FOREIGN KEY (`circuit_id`) REFERENCES `circuits`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `distribution_board_component_protection_devices` ( - `component_id` text PRIMARY KEY NOT NULL, - `type` text NOT NULL, - `rated_current_a` real NOT NULL, - `fuse_utilization_category` text, - `trip_characteristic` text, - `rcd_type` text, - `rated_residual_current_ma` real, - FOREIGN KEY (`component_id`) REFERENCES `distribution_board_components`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE TABLE `distribution_board_components` ( - `id` text PRIMARY KEY NOT NULL, - `circuit_list_id` text NOT NULL, - `section_id` text, - `equipment_identifier` text NOT NULL, - `name` text NOT NULL, - `role` text NOT NULL, - `placement` text NOT NULL, - `sort_order` integer DEFAULT 0 NOT NULL, - FOREIGN KEY (`circuit_list_id`) REFERENCES `circuit_lists`(`id`) ON UPDATE no action ON DELETE cascade, - FOREIGN KEY (`section_id`) REFERENCES `circuit_sections`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE UNIQUE INDEX `distribution_board_components_list_identifier_unique` ON `distribution_board_components` (`circuit_list_id`,`equipment_identifier`);--> statement-breakpoint -CREATE UNIQUE INDEX `distribution_board_components_section_role_unique` ON `distribution_board_components` (`section_id`,`role`);--> statement-breakpoint -ALTER TABLE `circuit_sections` ADD `category` text;--> statement-breakpoint -ALTER TABLE `circuit_sections` ADD `group_number` integer;--> statement-breakpoint -CREATE UNIQUE INDEX `circuit_sections_list_category_group_unique` ON `circuit_sections` (`circuit_list_id`,`category`,`group_number`);--> statement-breakpoint -UPDATE `circuit_sections` -SET - `category` = CASE `key` - WHEN 'lighting' THEN 'lighting' - WHEN 'single_phase' THEN 'single_phase' - WHEN 'three_phase' THEN 'three_phase' - END, - `group_number` = 1 -WHERE `key` IN ('lighting', 'single_phase', 'three_phase');--> statement-breakpoint -INSERT INTO `circuit_list_equipment_identifiers` ( - `owner_type`, - `owner_id`, - `circuit_list_id`, - `equipment_identifier` -) -SELECT - 'circuit', - `id`, - `circuit_list_id`, - `equipment_identifier` -FROM `circuits`;--> statement-breakpoint -CREATE UNIQUE INDEX `circuit_list_equipment_identifiers_normalized_unique` -ON `circuit_list_equipment_identifiers` ( - `circuit_list_id`, - lower(trim(`equipment_identifier`)) -);--> statement-breakpoint -CREATE UNIQUE INDEX `distribution_board_components_fixed_role_unique` -ON `distribution_board_components` (`circuit_list_id`, `role`) -WHERE `role` IN ('main_switch', 'surge_protective_device');--> statement-breakpoint -CREATE TRIGGER `circuits_equipment_identifier_insert` -AFTER INSERT ON `circuits` -BEGIN - INSERT INTO `circuit_list_equipment_identifiers` ( - `owner_type`, - `owner_id`, - `circuit_list_id`, - `equipment_identifier` - ) - VALUES ( - 'circuit', - NEW.`id`, - NEW.`circuit_list_id`, - NEW.`equipment_identifier` - ); -END;--> statement-breakpoint -CREATE TRIGGER `circuits_equipment_identifier_update` -AFTER UPDATE OF `circuit_list_id`, `equipment_identifier` ON `circuits` -BEGIN - UPDATE `circuit_list_equipment_identifiers` - SET - `circuit_list_id` = NEW.`circuit_list_id`, - `equipment_identifier` = NEW.`equipment_identifier` - WHERE - `owner_type` = 'circuit' - AND `owner_id` = OLD.`id`; -END;--> statement-breakpoint -CREATE TRIGGER `circuits_equipment_identifier_delete` -AFTER DELETE ON `circuits` -BEGIN - DELETE FROM `circuit_list_equipment_identifiers` - WHERE - `owner_type` = 'circuit' - AND `owner_id` = OLD.`id`; -END;--> statement-breakpoint -CREATE TRIGGER `distribution_board_components_equipment_identifier_insert` -AFTER INSERT ON `distribution_board_components` -BEGIN - INSERT INTO `circuit_list_equipment_identifiers` ( - `owner_type`, - `owner_id`, - `circuit_list_id`, - `equipment_identifier` - ) - VALUES ( - 'distribution_board_component', - NEW.`id`, - NEW.`circuit_list_id`, - NEW.`equipment_identifier` - ); -END;--> statement-breakpoint -CREATE TRIGGER `distribution_board_components_equipment_identifier_update` -AFTER UPDATE OF `circuit_list_id`, `equipment_identifier` -ON `distribution_board_components` -BEGIN - UPDATE `circuit_list_equipment_identifiers` - SET - `circuit_list_id` = NEW.`circuit_list_id`, - `equipment_identifier` = NEW.`equipment_identifier` - WHERE - `owner_type` = 'distribution_board_component' - AND `owner_id` = OLD.`id`; -END;--> statement-breakpoint -CREATE TRIGGER `distribution_board_components_equipment_identifier_delete` -AFTER DELETE ON `distribution_board_components` -BEGIN - DELETE FROM `circuit_list_equipment_identifiers` - WHERE - `owner_type` = 'distribution_board_component' - AND `owner_id` = OLD.`id`; -END; diff --git a/src/db/migrations/meta/0000_snapshot.json b/src/db/migrations/meta/0000_snapshot.json index 40ca397..1f5d1e6 100644 --- a/src/db/migrations/meta/0000_snapshot.json +++ b/src/db/migrations/meta/0000_snapshot.json @@ -1,11 +1,271 @@ { "version": "6", "dialect": "sqlite", - "id": "d219f155-9dd0-48e3-8fd2-8278f1f788ca", + "id": "2f464eb0-b1c4-4d2d-bfc8-a1466788c961", "prevId": "00000000-0000-0000-0000-000000000000", "tables": { - "consumers": { - "name": "consumers", + "circuit_device_rows": { + "name": "circuit_device_rows", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "circuit_id": { + "name": "circuit_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "linked_project_device_id": { + "name": "linked_project_device_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "phase_type": { + "name": "phase_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "connection_kind": { + "name": "connection_kind", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_group": { + "name": "cost_group", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "room_id": { + "name": "room_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "room_number_snapshot": { + "name": "room_number_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "room_name_snapshot": { + "name": "room_name_snapshot", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "quantity": { + "name": "quantity", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "power_per_unit": { + "name": "power_per_unit", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "simultaneity_factor": { + "name": "simultaneity_factor", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "cos_phi": { + "name": "cos_phi", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "overridden_fields": { + "name": "overridden_fields", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "circuit_device_rows_circuit_id_circuits_id_fk": { + "name": "circuit_device_rows_circuit_id_circuits_id_fk", + "tableFrom": "circuit_device_rows", + "tableTo": "circuits", + "columnsFrom": [ + "circuit_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { + "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", + "tableFrom": "circuit_device_rows", + "tableTo": "project_devices", + "columnsFrom": [ + "linked_project_device_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "circuit_device_rows_room_id_rooms_id_fk": { + "name": "circuit_device_rows_room_id_rooms_id_fk", + "tableFrom": "circuit_device_rows", + "tableTo": "rooms", + "columnsFrom": [ + "room_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "circuit_list_equipment_identifiers": { + "name": "circuit_list_equipment_identifiers", + "columns": { + "owner_type": { + "name": "owner_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "circuit_list_id": { + "name": "circuit_list_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "equipment_identifier": { + "name": "equipment_identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "circuit_list_equipment_identifiers_owner_unique": { + "name": "circuit_list_equipment_identifiers_owner_unique", + "columns": [ + "owner_type", + "owner_id" + ], + "isUnique": true + }, + "circuit_list_equipment_identifiers_list_identifier_unique": { + "name": "circuit_list_equipment_identifiers_list_identifier_unique", + "columns": [ + "circuit_list_id", + "equipment_identifier" + ], + "isUnique": true + } + }, + "foreignKeys": { + "circuit_list_equipment_identifiers_circuit_list_id_circuit_lists_id_fk": { + "name": "circuit_list_equipment_identifiers_circuit_list_id_circuit_lists_id_fk", + "tableFrom": "circuit_list_equipment_identifiers", + "tableTo": "circuit_lists", + "columnsFrom": [ + "circuit_list_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "circuit_lists": { + "name": "circuit_lists", "columns": { "id": { "name": "id", @@ -25,7 +285,7 @@ "name": "distribution_board_id", "type": "text", "primaryKey": false, - "notNull": false, + "notNull": true, "autoincrement": false }, "name": { @@ -34,6 +294,729 @@ "primaryKey": false, "notNull": true, "autoincrement": false + } + }, + "indexes": { + "circuit_lists_distribution_board_id_unique": { + "name": "circuit_lists_distribution_board_id_unique", + "columns": [ + "distribution_board_id" + ], + "isUnique": true + } + }, + "foreignKeys": { + "circuit_lists_project_id_projects_id_fk": { + "name": "circuit_lists_project_id_projects_id_fk", + "tableFrom": "circuit_lists", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "circuit_lists_distribution_board_id_distribution_boards_id_fk": { + "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", + "tableFrom": "circuit_lists", + "tableTo": "distribution_boards", + "columnsFrom": [ + "distribution_board_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "circuit_protection_devices": { + "name": "circuit_protection_devices", + "columns": { + "circuit_id": { + "name": "circuit_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rated_current_a": { + "name": "rated_current_a", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "fuse_utilization_category": { + "name": "fuse_utilization_category", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "trip_characteristic": { + "name": "trip_characteristic", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rcd_type": { + "name": "rcd_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rated_residual_current_ma": { + "name": "rated_residual_current_ma", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "circuit_protection_devices_circuit_id_circuits_id_fk": { + "name": "circuit_protection_devices_circuit_id_circuits_id_fk", + "tableFrom": "circuit_protection_devices", + "tableTo": "circuits", + "columnsFrom": [ + "circuit_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "circuit_sections": { + "name": "circuit_sections", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "circuit_list_id": { + "name": "circuit_list_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "prefix": { + "name": "prefix", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "group_number": { + "name": "group_number", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "circuit_sections_list_key_unique": { + "name": "circuit_sections_list_key_unique", + "columns": [ + "circuit_list_id", + "key" + ], + "isUnique": true + }, + "circuit_sections_list_prefix_unique": { + "name": "circuit_sections_list_prefix_unique", + "columns": [ + "circuit_list_id", + "prefix" + ], + "isUnique": true + }, + "circuit_sections_list_category_group_unique": { + "name": "circuit_sections_list_category_group_unique", + "columns": [ + "circuit_list_id", + "category", + "group_number" + ], + "isUnique": true + } + }, + "foreignKeys": { + "circuit_sections_circuit_list_id_circuit_lists_id_fk": { + "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", + "tableFrom": "circuit_sections", + "tableTo": "circuit_lists", + "columnsFrom": [ + "circuit_list_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "circuits": { + "name": "circuits", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "circuit_list_id": { + "name": "circuit_list_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "section_id": { + "name": "section_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "equipment_identifier": { + "name": "equipment_identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "cable_type": { + "name": "cable_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cable_cross_section": { + "name": "cable_cross_section", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cable_length": { + "name": "cable_length", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rcd_assignment": { + "name": "rcd_assignment", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "terminal_designation": { + "name": "terminal_designation", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "voltage": { + "name": "voltage", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "control_requirement": { + "name": "control_requirement", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "is_reserve": { + "name": "is_reserve", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "circuits_list_equipment_identifier_unique": { + "name": "circuits_list_equipment_identifier_unique", + "columns": [ + "circuit_list_id", + "equipment_identifier" + ], + "isUnique": true + } + }, + "foreignKeys": { + "circuits_circuit_list_id_circuit_lists_id_fk": { + "name": "circuits_circuit_list_id_circuit_lists_id_fk", + "tableFrom": "circuits", + "tableTo": "circuit_lists", + "columnsFrom": [ + "circuit_list_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "circuits_section_id_circuit_sections_id_fk": { + "name": "circuits_section_id_circuit_sections_id_fk", + "tableFrom": "circuits", + "tableTo": "circuit_sections", + "columnsFrom": [ + "section_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "distribution_board_component_protection_devices": { + "name": "distribution_board_component_protection_devices", + "columns": { + "component_id": { + "name": "component_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "rated_current_a": { + "name": "rated_current_a", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "fuse_utilization_category": { + "name": "fuse_utilization_category", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "trip_characteristic": { + "name": "trip_characteristic", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rcd_type": { + "name": "rcd_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "rated_residual_current_ma": { + "name": "rated_residual_current_ma", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "distribution_board_component_protection_devices_component_id_distribution_board_components_id_fk": { + "name": "distribution_board_component_protection_devices_component_id_distribution_board_components_id_fk", + "tableFrom": "distribution_board_component_protection_devices", + "tableTo": "distribution_board_components", + "columnsFrom": [ + "component_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "distribution_board_components": { + "name": "distribution_board_components", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "circuit_list_id": { + "name": "circuit_list_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "section_id": { + "name": "section_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "equipment_identifier": { + "name": "equipment_identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "placement": { + "name": "placement", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": { + "distribution_board_components_list_identifier_unique": { + "name": "distribution_board_components_list_identifier_unique", + "columns": [ + "circuit_list_id", + "equipment_identifier" + ], + "isUnique": true + }, + "distribution_board_components_section_role_unique": { + "name": "distribution_board_components_section_role_unique", + "columns": [ + "section_id", + "role" + ], + "isUnique": true + } + }, + "foreignKeys": { + "distribution_board_components_circuit_list_id_circuit_lists_id_fk": { + "name": "distribution_board_components_circuit_list_id_circuit_lists_id_fk", + "tableFrom": "distribution_board_components", + "tableTo": "circuit_lists", + "columnsFrom": [ + "circuit_list_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "distribution_board_components_section_id_circuit_sections_id_fk": { + "name": "distribution_board_components_section_id_circuit_sections_id_fk", + "tableFrom": "distribution_board_components", + "tableTo": "circuit_sections", + "columnsFrom": [ + "section_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "distribution_boards": { + "name": "distribution_boards", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "floor_id": { + "name": "floor_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "supply_type": { + "name": "supply_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "simultaneity_factor": { + "name": "simultaneity_factor", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + } + }, + "indexes": {}, + "foreignKeys": { + "distribution_boards_project_id_projects_id_fk": { + "name": "distribution_boards_project_id_projects_id_fk", + "tableFrom": "distribution_boards", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "distribution_boards_floor_id_floors_id_fk": { + "name": "distribution_boards_floor_id_floors_id_fk", + "tableFrom": "distribution_boards", + "tableTo": "floors", + "columnsFrom": [ + "floor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "floors": { + "name": "floors", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "floors_project_id_projects_id_fk": { + "name": "floors_project_id_projects_id_fk", + "tableFrom": "floors", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "global_devices": { + "name": "global_devices", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false }, "category": { "name": "category", @@ -93,40 +1076,87 @@ } }, "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_change_sets": { + "name": "project_change_sets", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_revision_id": { + "name": "project_revision_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "command_type": { + "name": "command_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "payload_schema_version": { + "name": "payload_schema_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "forward_payload_json": { + "name": "forward_payload_json", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "inverse_payload_json": { + "name": "inverse_payload_json", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "project_change_sets_revision_unique": { + "name": "project_change_sets_revision_unique", + "columns": [ + "project_revision_id" + ], + "isUnique": true + } + }, "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", + "project_change_sets_project_revision_id_project_revisions_id_fk": { + "name": "project_change_sets_project_revision_id_project_revisions_id_fk", + "tableFrom": "project_change_sets", + "tableTo": "project_revisions", "columnsFrom": [ - "project_id" + "project_revision_id" ], "columnsTo": [ "id" ], "onDelete": "cascade", "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" } }, "compositePrimaryKeys": {}, "uniqueConstraints": {}, "checkConstraints": {} }, - "distribution_boards": { - "name": "distribution_boards", + "project_devices": { + "name": "project_devices", "columns": { "id": { "name": "id", @@ -148,13 +1178,383 @@ "primaryKey": false, "notNull": true, "autoincrement": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "phase_type": { + "name": "phase_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'single_phase'" + }, + "connection_kind": { + "name": "connection_kind", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cost_group": { + "name": "cost_group", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "category": { + "name": "category", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "quantity": { + "name": "quantity", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "power_per_unit": { + "name": "power_per_unit", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "simultaneity_factor": { + "name": "simultaneity_factor", + "type": "real", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "cos_phi": { + "name": "cos_phi", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "voltage_v": { + "name": "voltage_v", + "type": "real", + "primaryKey": false, + "notNull": false, + "autoincrement": false } }, "indexes": {}, "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", + "project_devices_project_id_projects_id_fk": { + "name": "project_devices_project_id_projects_id_fk", + "tableFrom": "project_devices", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_history_stack_entries": { + "name": "project_history_stack_entries", + "columns": { + "change_set_id": { + "name": "change_set_id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "stack": { + "name": "stack", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "project_history_stack_entries_position_unique": { + "name": "project_history_stack_entries_position_unique", + "columns": [ + "project_id", + "stack", + "position" + ], + "isUnique": true + } + }, + "foreignKeys": { + "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { + "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", + "tableFrom": "project_history_stack_entries", + "tableTo": "project_change_sets", + "columnsFrom": [ + "change_set_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "project_history_stack_entries_project_id_projects_id_fk": { + "name": "project_history_stack_entries_project_id_projects_id_fk", + "tableFrom": "project_history_stack_entries", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": { + "project_history_stack_entries_stack_check": { + "name": "project_history_stack_entries_stack_check", + "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" + } + } + }, + "project_revisions": { + "name": "project_revisions", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "revision_number": { + "name": "revision_number", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at_iso": { + "name": "created_at_iso", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "project_revisions_project_number_unique": { + "name": "project_revisions_project_number_unique", + "columns": [ + "project_id", + "revision_number" + ], + "isUnique": true + } + }, + "foreignKeys": { + "project_revisions_project_id_projects_id_fk": { + "name": "project_revisions_project_id_projects_id_fk", + "tableFrom": "project_revisions", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "project_snapshots": { + "name": "project_snapshots", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source_revision": { + "name": "source_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "schema_version": { + "name": "schema_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'named'" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "payload_json": { + "name": "payload_json", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "payload_sha256": { + "name": "payload_sha256", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at_iso": { + "name": "created_at_iso", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_by_actor_id": { + "name": "created_by_actor_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "project_snapshots_project_created_idx": { + "name": "project_snapshots_project_created_idx", + "columns": [ + "project_id", + "created_at_iso" + ], + "isUnique": false + }, + "project_snapshots_project_kind_revision_idx": { + "name": "project_snapshots_project_kind_revision_idx", + "columns": [ + "project_id", + "kind", + "source_revision" + ], + "isUnique": false + }, + "project_snapshots_project_name_unique": { + "name": "project_snapshots_project_name_unique", + "columns": [ + "project_id", + "name" + ], + "isUnique": true + } + }, + "foreignKeys": { + "project_snapshots_project_id_projects_id_fk": { + "name": "project_snapshots_project_id_projects_id_fk", + "tableFrom": "project_snapshots", "tableTo": "projects", "columnsFrom": [ "project_id" @@ -186,6 +1586,66 @@ "primaryKey": false, "notNull": true, "autoincrement": false + }, + "internal_project_number": { + "name": "internal_project_number", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "external_project_number": { + "name": "external_project_number", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "building_owner": { + "name": "building_owner", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "single_phase_voltage_v": { + "name": "single_phase_voltage_v", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 230 + }, + "three_phase_voltage_v": { + "name": "three_phase_voltage_v", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 400 + }, + "enabled_distribution_board_supply_types": { + "name": "enabled_distribution_board_supply_types", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'[\"AV\",\"SV\",\"EV\",\"USV\",\"MSR\",\"SiBe\"]'" + }, + "current_revision": { + "name": "current_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 } }, "indexes": {}, @@ -193,6 +1653,78 @@ "compositePrimaryKeys": {}, "uniqueConstraints": {}, "checkConstraints": {} + }, + "rooms": { + "name": "rooms", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "project_id": { + "name": "project_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "floor_id": { + "name": "floor_id", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "room_number": { + "name": "room_number", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "room_name": { + "name": "room_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "rooms_project_id_projects_id_fk": { + "name": "rooms_project_id_projects_id_fk", + "tableFrom": "rooms", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "rooms_floor_id_floors_id_fk": { + "name": "rooms_floor_id_floors_id_fk", + "tableFrom": "rooms", + "tableTo": "floors", + "columnsFrom": [ + "floor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} } }, "views": {}, diff --git a/src/db/migrations/meta/0011_snapshot.json b/src/db/migrations/meta/0011_snapshot.json deleted file mode 100644 index e9d5d3a..0000000 --- a/src/db/migrations/meta/0011_snapshot.json +++ /dev/null @@ -1,1450 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "863215c4-ed6e-4ec5-8c48-161054031da2", - "prevId": "d219f155-9dd0-48e3-8fd2-8278f1f788ca", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0012_snapshot.json b/src/db/migrations/meta/0012_snapshot.json deleted file mode 100644 index 8d689f0..0000000 --- a/src/db/migrations/meta/0012_snapshot.json +++ /dev/null @@ -1,1614 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "3f69cb15-3079-4bf5-96f7-3af62c8ac7e1", - "prevId": "863215c4-ed6e-4ec5-8c48-161054031da2", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0013_snapshot.json b/src/db/migrations/meta/0013_snapshot.json deleted file mode 100644 index 9b28c31..0000000 --- a/src/db/migrations/meta/0013_snapshot.json +++ /dev/null @@ -1,1694 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "b4029fef-ed7b-47ed-a185-d151ad3f46da", - "prevId": "3f69cb15-3079-4bf5-96f7-3af62c8ac7e1", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "project_change_sets", - "columnsFrom": [ - "change_set_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0014_snapshot.json b/src/db/migrations/meta/0014_snapshot.json deleted file mode 100644 index 783e5ad..0000000 --- a/src/db/migrations/meta/0014_snapshot.json +++ /dev/null @@ -1,1805 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "bd9bc99c-0cc0-44e3-bff0-819b1cbbf8ac", - "prevId": "b4029fef-ed7b-47ed-a185-d151ad3f46da", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "project_change_sets", - "columnsFrom": [ - "change_set_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0015_snapshot.json b/src/db/migrations/meta/0015_snapshot.json deleted file mode 100644 index e5ac2bf..0000000 --- a/src/db/migrations/meta/0015_snapshot.json +++ /dev/null @@ -1,1822 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "3248cb0b-5512-43d3-8193-e7218cb8ae66", - "prevId": "bd9bc99c-0cc0-44e3-bff0-819b1cbbf8ac", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "project_change_sets", - "columnsFrom": [ - "change_set_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0016_snapshot.json b/src/db/migrations/meta/0016_snapshot.json deleted file mode 100644 index 1e43d03..0000000 --- a/src/db/migrations/meta/0016_snapshot.json +++ /dev/null @@ -1,1850 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "8502c7d2-e925-42c3-8044-3e965c170f97", - "prevId": "3248cb0b-5512-43d3-8193-e7218cb8ae66", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "project_change_sets", - "columnsFrom": [ - "change_set_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0017_snapshot.json b/src/db/migrations/meta/0017_snapshot.json deleted file mode 100644 index 1ec7207..0000000 --- a/src/db/migrations/meta/0017_snapshot.json +++ /dev/null @@ -1,1877 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "f885efbf-98a4-4977-8416-9cc890cf64df", - "prevId": "8502c7d2-e925-42c3-8044-3e965c170f97", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "supply_type": { - "name": "supply_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "distribution_boards_floor_id_floors_id_fk": { - "name": "distribution_boards_floor_id_floors_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "project_change_sets", - "columnsFrom": [ - "change_set_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0018_snapshot.json b/src/db/migrations/meta/0018_snapshot.json deleted file mode 100644 index b463316..0000000 --- a/src/db/migrations/meta/0018_snapshot.json +++ /dev/null @@ -1,1885 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "6297060c-1a3f-4f7c-867f-7c3e96c34645", - "prevId": "f885efbf-98a4-4977-8416-9cc890cf64df", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "supply_type": { - "name": "supply_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "distribution_boards_floor_id_floors_id_fk": { - "name": "distribution_boards_floor_id_floors_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "project_change_sets", - "columnsFrom": [ - "change_set_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "enabled_distribution_board_supply_types": { - "name": "enabled_distribution_board_supply_types", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'[\"AV\",\"SV\",\"EV\",\"USV\",\"MSR\",\"SiBe\"]'" - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0019_snapshot.json b/src/db/migrations/meta/0019_snapshot.json deleted file mode 100644 index 74be78e..0000000 --- a/src/db/migrations/meta/0019_snapshot.json +++ /dev/null @@ -1,1885 +0,0 @@ -{ - "id": "38fade39-c2c3-494e-ae8d-ee4677b2cbc7", - "prevId": "6297060c-1a3f-4f7c-867f-7c3e96c34645", - "version": "6", - "dialect": "sqlite", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "circuit_id" - ], - "tableTo": "circuits", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "linked_project_device_id" - ], - "tableTo": "project_devices", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "room_id" - ], - "tableTo": "rooms", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "columnsFrom": [ - "distribution_board_id" - ], - "tableTo": "distribution_boards", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "columnsFrom": [ - "section_id" - ], - "tableTo": "circuit_sections", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "distribution_board_id" - ], - "tableTo": "distribution_boards", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "project_device_id" - ], - "tableTo": "project_devices", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "room_id" - ], - "tableTo": "rooms", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "supply_type": { - "name": "supply_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "distribution_boards_floor_id_floors_id_fk": { - "name": "distribution_boards_floor_id_floors_id_fk", - "tableFrom": "distribution_boards", - "columnsFrom": [ - "floor_id" - ], - "tableTo": "floors", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_id" - ], - "tableTo": "circuits", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_device_row_id" - ], - "tableTo": "circuit_device_rows", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "columnsFrom": [ - "project_revision_id" - ], - "tableTo": "project_revisions", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "columnsFrom": [ - "change_set_id" - ], - "tableTo": "project_change_sets", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "enabled_distribution_board_supply_types": { - "name": "enabled_distribution_board_supply_types", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'[\"AV\",\"SV\",\"EV\",\"USV\",\"MSR\",\"SiBe\"]'" - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "columnsFrom": [ - "floor_id" - ], - "tableTo": "floors", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0020_snapshot.json b/src/db/migrations/meta/0020_snapshot.json deleted file mode 100644 index 73ccbae..0000000 --- a/src/db/migrations/meta/0020_snapshot.json +++ /dev/null @@ -1,1885 +0,0 @@ -{ - "id": "05a90b58-39b0-4e33-95fd-331b4dd38df0", - "prevId": "38fade39-c2c3-494e-ae8d-ee4677b2cbc7", - "version": "6", - "dialect": "sqlite", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "circuit_id" - ], - "tableTo": "circuits", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "linked_project_device_id" - ], - "tableTo": "project_devices", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "room_id" - ], - "tableTo": "rooms", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "columnsFrom": [ - "distribution_board_id" - ], - "tableTo": "distribution_boards", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "columnsFrom": [ - "section_id" - ], - "tableTo": "circuit_sections", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "distribution_board_id" - ], - "tableTo": "distribution_boards", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "project_device_id" - ], - "tableTo": "project_devices", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "room_id" - ], - "tableTo": "rooms", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "supply_type": { - "name": "supply_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "distribution_boards_floor_id_floors_id_fk": { - "name": "distribution_boards_floor_id_floors_id_fk", - "tableFrom": "distribution_boards", - "columnsFrom": [ - "floor_id" - ], - "tableTo": "floors", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_id" - ], - "tableTo": "circuits", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_device_row_id" - ], - "tableTo": "circuit_device_rows", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "columnsFrom": [ - "project_revision_id" - ], - "tableTo": "project_revisions", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "columnsFrom": [ - "change_set_id" - ], - "tableTo": "project_change_sets", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "enabled_distribution_board_supply_types": { - "name": "enabled_distribution_board_supply_types", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'[\"AV\",\"SV\",\"EV\",\"USV\",\"MSR\",\"SiBe\"]'" - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "columnsFrom": [ - "floor_id" - ], - "tableTo": "floors", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0021_snapshot.json b/src/db/migrations/meta/0021_snapshot.json deleted file mode 100644 index f0531ff..0000000 --- a/src/db/migrations/meta/0021_snapshot.json +++ /dev/null @@ -1,1885 +0,0 @@ -{ - "id": "3cdbf3c2-6946-4520-a6d0-d39c3e144a66", - "prevId": "05a90b58-39b0-4e33-95fd-331b4dd38df0", - "version": "6", - "dialect": "sqlite", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "circuit_id" - ], - "tableTo": "circuits", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "linked_project_device_id" - ], - "tableTo": "project_devices", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "room_id" - ], - "tableTo": "rooms", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "columnsFrom": [ - "distribution_board_id" - ], - "tableTo": "distribution_boards", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "columnsFrom": [ - "section_id" - ], - "tableTo": "circuit_sections", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "distribution_board_id" - ], - "tableTo": "distribution_boards", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "project_device_id" - ], - "tableTo": "project_devices", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "room_id" - ], - "tableTo": "rooms", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "supply_type": { - "name": "supply_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "distribution_boards_floor_id_floors_id_fk": { - "name": "distribution_boards_floor_id_floors_id_fk", - "tableFrom": "distribution_boards", - "columnsFrom": [ - "floor_id" - ], - "tableTo": "floors", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_id" - ], - "tableTo": "circuits", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_device_row_id" - ], - "tableTo": "circuit_device_rows", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "columnsFrom": [ - "project_revision_id" - ], - "tableTo": "project_revisions", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "columnsFrom": [ - "change_set_id" - ], - "tableTo": "project_change_sets", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "enabled_distribution_board_supply_types": { - "name": "enabled_distribution_board_supply_types", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'[\"AV\",\"SV\",\"EV\",\"USV\",\"MSR\",\"SiBe\"]'" - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "columnsFrom": [ - "floor_id" - ], - "tableTo": "floors", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0022_snapshot.json b/src/db/migrations/meta/0022_snapshot.json deleted file mode 100644 index a561905..0000000 --- a/src/db/migrations/meta/0022_snapshot.json +++ /dev/null @@ -1,1885 +0,0 @@ -{ - "id": "c9eabd70-45c9-43c3-ae63-f0685aeeb1f1", - "prevId": "3cdbf3c2-6946-4520-a6d0-d39c3e144a66", - "version": "6", - "dialect": "sqlite", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "circuit_id" - ], - "tableTo": "circuits", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "linked_project_device_id" - ], - "tableTo": "project_devices", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "columnsFrom": [ - "room_id" - ], - "tableTo": "rooms", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "columnsFrom": [ - "distribution_board_id" - ], - "tableTo": "distribution_boards", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "columnsFrom": [ - "section_id" - ], - "tableTo": "circuit_sections", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "distribution_board_id" - ], - "tableTo": "distribution_boards", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "project_device_id" - ], - "tableTo": "project_devices", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "columnsFrom": [ - "room_id" - ], - "tableTo": "rooms", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "supply_type": { - "name": "supply_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "distribution_boards_floor_id_floors_id_fk": { - "name": "distribution_boards_floor_id_floors_id_fk", - "tableFrom": "distribution_boards", - "columnsFrom": [ - "floor_id" - ], - "tableTo": "floors", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_id" - ], - "tableTo": "circuits", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_device_row_id" - ], - "tableTo": "circuit_device_rows", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "columnsFrom": [ - "circuit_list_id" - ], - "tableTo": "circuit_lists", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "columnsFrom": [ - "project_revision_id" - ], - "tableTo": "project_revisions", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "columnsFrom": [ - "change_set_id" - ], - "tableTo": "project_change_sets", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "enabled_distribution_board_supply_types": { - "name": "enabled_distribution_board_supply_types", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'[\"AV\",\"SV\",\"EV\",\"USV\",\"MSR\",\"SiBe\"]'" - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "columnsFrom": [ - "project_id" - ], - "tableTo": "projects", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "cascade" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "columnsFrom": [ - "floor_id" - ], - "tableTo": "floors", - "columnsTo": [ - "id" - ], - "onUpdate": "no action", - "onDelete": "set null" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0023_snapshot.json b/src/db/migrations/meta/0023_snapshot.json deleted file mode 100644 index 4602820..0000000 --- a/src/db/migrations/meta/0023_snapshot.json +++ /dev/null @@ -1,1893 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "f99355d0-b023-424b-870e-3ea8423497eb", - "prevId": "c9eabd70-45c9-43c3-ae63-f0685aeeb1f1", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "supply_type": { - "name": "supply_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "distribution_boards_floor_id_floors_id_fk": { - "name": "distribution_boards_floor_id_floors_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "project_change_sets", - "columnsFrom": [ - "change_set_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "enabled_distribution_board_supply_types": { - "name": "enabled_distribution_board_supply_types", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'[\"AV\",\"SV\",\"EV\",\"USV\",\"MSR\",\"SiBe\"]'" - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0024_snapshot.json b/src/db/migrations/meta/0024_snapshot.json deleted file mode 100644 index bd411ce..0000000 --- a/src/db/migrations/meta/0024_snapshot.json +++ /dev/null @@ -1,2242 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "31166943-989c-4199-a8a3-a896dab14995", - "prevId": "f99355d0-b023-424b-870e-3ea8423497eb", - "tables": { - "circuit_device_rows": { - "name": "circuit_device_rows", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "linked_project_device_id": { - "name": "linked_project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "legacy_consumer_id": { - "name": "legacy_consumer_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "level": { - "name": "level", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number_snapshot": { - "name": "room_number_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_name_snapshot": { - "name": "room_name_snapshot", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "overridden_fields": { - "name": "overridden_fields", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_device_rows_circuit_id_circuits_id_fk": { - "name": "circuit_device_rows_circuit_id_circuits_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_device_rows_linked_project_device_id_project_devices_id_fk": { - "name": "circuit_device_rows_linked_project_device_id_project_devices_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "project_devices", - "columnsFrom": [ - "linked_project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "circuit_device_rows_room_id_rooms_id_fk": { - "name": "circuit_device_rows_room_id_rooms_id_fk", - "tableFrom": "circuit_device_rows", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_list_equipment_identifiers": { - "name": "circuit_list_equipment_identifiers", - "columns": { - "owner_type": { - "name": "owner_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "owner_id": { - "name": "owner_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_list_equipment_identifiers_owner_unique": { - "name": "circuit_list_equipment_identifiers_owner_unique", - "columns": [ - "owner_type", - "owner_id" - ], - "isUnique": true - }, - "circuit_list_equipment_identifiers_list_identifier_unique": { - "name": "circuit_list_equipment_identifiers_list_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_list_equipment_identifiers_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_list_equipment_identifiers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_list_equipment_identifiers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_lists": { - "name": "circuit_lists", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "circuit_lists_distribution_board_id_unique": { - "name": "circuit_lists_distribution_board_id_unique", - "columns": [ - "distribution_board_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_lists_project_id_projects_id_fk": { - "name": "circuit_lists_project_id_projects_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuit_lists_distribution_board_id_distribution_boards_id_fk": { - "name": "circuit_lists_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "circuit_lists", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_protection_devices": { - "name": "circuit_protection_devices", - "columns": { - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "rated_current_a": { - "name": "rated_current_a", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "fuse_utilization_category": { - "name": "fuse_utilization_category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trip_characteristic": { - "name": "trip_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_type": { - "name": "rcd_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rated_residual_current_ma": { - "name": "rated_residual_current_ma", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "circuit_protection_devices_circuit_id_circuits_id_fk": { - "name": "circuit_protection_devices_circuit_id_circuits_id_fk", - "tableFrom": "circuit_protection_devices", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuit_sections": { - "name": "circuit_sections", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "key": { - "name": "key", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "prefix": { - "name": "prefix", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_number": { - "name": "group_number", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuit_sections_list_key_unique": { - "name": "circuit_sections_list_key_unique", - "columns": [ - "circuit_list_id", - "key" - ], - "isUnique": true - }, - "circuit_sections_list_prefix_unique": { - "name": "circuit_sections_list_prefix_unique", - "columns": [ - "circuit_list_id", - "prefix" - ], - "isUnique": true - }, - "circuit_sections_list_category_group_unique": { - "name": "circuit_sections_list_category_group_unique", - "columns": [ - "circuit_list_id", - "category", - "group_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuit_sections_circuit_list_id_circuit_lists_id_fk": { - "name": "circuit_sections_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuit_sections", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "circuits": { - "name": "circuits", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_length": { - "name": "cable_length", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_assignment": { - "name": "rcd_assignment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "terminal_designation": { - "name": "terminal_designation", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage": { - "name": "voltage", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "control_requirement": { - "name": "control_requirement", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "status": { - "name": "status", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_reserve": { - "name": "is_reserve", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "circuits_list_equipment_identifier_unique": { - "name": "circuits_list_equipment_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - } - }, - "foreignKeys": { - "circuits_circuit_list_id_circuit_lists_id_fk": { - "name": "circuits_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "circuits_section_id_circuit_sections_id_fk": { - "name": "circuits_section_id_circuit_sections_id_fk", - "tableFrom": "circuits", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "consumers": { - "name": "consumers", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "distribution_board_id": { - "name": "distribution_board_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "project_device_id": { - "name": "project_device_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "is_linked_to_device": { - "name": "is_linked_to_device", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "room_id": { - "name": "room_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "circuit_number": { - "name": "circuit_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "device_type": { - "name": "device_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trade_or_cost_group": { - "name": "trade_or_cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "group_name": { - "name": "group_name", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_type": { - "name": "protection_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_rated_current": { - "name": "protection_rated_current", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "protection_characteristic": { - "name": "protection_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_type": { - "name": "cable_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cable_cross_section": { - "name": "cable_cross_section", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "consumers_project_id_projects_id_fk": { - "name": "consumers_project_id_projects_id_fk", - "tableFrom": "consumers", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "consumers_distribution_board_id_distribution_boards_id_fk": { - "name": "consumers_distribution_board_id_distribution_boards_id_fk", - "tableFrom": "consumers", - "tableTo": "distribution_boards", - "columnsFrom": [ - "distribution_board_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_circuit_list_id_circuit_lists_id_fk": { - "name": "consumers_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "consumers", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_project_device_id_project_devices_id_fk": { - "name": "consumers_project_device_id_project_devices_id_fk", - "tableFrom": "consumers", - "tableTo": "project_devices", - "columnsFrom": [ - "project_device_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - }, - "consumers_room_id_rooms_id_fk": { - "name": "consumers_room_id_rooms_id_fk", - "tableFrom": "consumers", - "tableTo": "rooms", - "columnsFrom": [ - "room_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_board_component_protection_devices": { - "name": "distribution_board_component_protection_devices", - "columns": { - "component_id": { - "name": "component_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "rated_current_a": { - "name": "rated_current_a", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "fuse_utilization_category": { - "name": "fuse_utilization_category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "trip_characteristic": { - "name": "trip_characteristic", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rcd_type": { - "name": "rcd_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "rated_residual_current_ma": { - "name": "rated_residual_current_ma", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_board_component_protection_devices_component_id_distribution_board_components_id_fk": { - "name": "distribution_board_component_protection_devices_component_id_distribution_board_components_id_fk", - "tableFrom": "distribution_board_component_protection_devices", - "tableTo": "distribution_board_components", - "columnsFrom": [ - "component_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_board_components": { - "name": "distribution_board_components", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "section_id": { - "name": "section_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "equipment_identifier": { - "name": "equipment_identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "placement": { - "name": "placement", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": { - "distribution_board_components_list_identifier_unique": { - "name": "distribution_board_components_list_identifier_unique", - "columns": [ - "circuit_list_id", - "equipment_identifier" - ], - "isUnique": true - }, - "distribution_board_components_section_role_unique": { - "name": "distribution_board_components_section_role_unique", - "columns": [ - "section_id", - "role" - ], - "isUnique": true - } - }, - "foreignKeys": { - "distribution_board_components_circuit_list_id_circuit_lists_id_fk": { - "name": "distribution_board_components_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "distribution_board_components", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "distribution_board_components_section_id_circuit_sections_id_fk": { - "name": "distribution_board_components_section_id_circuit_sections_id_fk", - "tableFrom": "distribution_board_components", - "tableTo": "circuit_sections", - "columnsFrom": [ - "section_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "distribution_boards": { - "name": "distribution_boards", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "supply_type": { - "name": "supply_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - } - }, - "indexes": {}, - "foreignKeys": { - "distribution_boards_project_id_projects_id_fk": { - "name": "distribution_boards_project_id_projects_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "distribution_boards_floor_id_floors_id_fk": { - "name": "distribution_boards_floor_id_floors_id_fk", - "tableFrom": "distribution_boards", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "floors": { - "name": "floors", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "sort_order": { - "name": "sort_order", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "floors_project_id_projects_id_fk": { - "name": "floors_project_id_projects_id_fk", - "tableFrom": "floors", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "global_devices": { - "name": "global_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "installed_power_per_unit_kw": { - "name": "installed_power_per_unit_kw", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "demand_factor": { - "name": "demand_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "phase_count": { - "name": "phase_count", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "power_factor": { - "name": "power_factor", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "note": { - "name": "note", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_circuit_migrations": { - "name": "legacy_consumer_circuit_migrations", - "columns": { - "consumer_id": { - "name": "consumer_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_id": { - "name": "circuit_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_device_row_id": { - "name": "circuit_device_row_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_id_circuits_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuits", - "columnsFrom": [ - "circuit_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_device_row_id_circuit_device_rows_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_device_rows", - "columnsFrom": [ - "circuit_device_row_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_circuit_migrations_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_circuit_migrations", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "legacy_consumer_migration_reports": { - "name": "legacy_consumer_migration_reports", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "circuit_list_id": { - "name": "circuit_list_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "legacy_consumer_count": { - "name": "legacy_consumer_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_circuit_count": { - "name": "created_circuit_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_device_row_count": { - "name": "created_device_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_grouped_count": { - "name": "duplicate_grouped_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifier_count": { - "name": "generated_identifier_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "unassigned_row_count": { - "name": "unassigned_row_count", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "warnings_json": { - "name": "warnings_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "generated_identifiers_json": { - "name": "generated_identifiers_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "duplicate_groups_json": { - "name": "duplicate_groups_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "legacy_consumer_migration_reports_list_unique": { - "name": "legacy_consumer_migration_reports_list_unique", - "columns": [ - "circuit_list_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk": { - "name": "legacy_consumer_migration_reports_circuit_list_id_circuit_lists_id_fk", - "tableFrom": "legacy_consumer_migration_reports", - "tableTo": "circuit_lists", - "columnsFrom": [ - "circuit_list_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_change_sets": { - "name": "project_change_sets", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_revision_id": { - "name": "project_revision_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "command_type": { - "name": "command_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_schema_version": { - "name": "payload_schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "forward_payload_json": { - "name": "forward_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "inverse_payload_json": { - "name": "inverse_payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_change_sets_revision_unique": { - "name": "project_change_sets_revision_unique", - "columns": [ - "project_revision_id" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_change_sets_project_revision_id_project_revisions_id_fk": { - "name": "project_change_sets_project_revision_id_project_revisions_id_fk", - "tableFrom": "project_change_sets", - "tableTo": "project_revisions", - "columnsFrom": [ - "project_revision_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_devices": { - "name": "project_devices", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "display_name": { - "name": "display_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "phase_type": { - "name": "phase_type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'single_phase'" - }, - "connection_kind": { - "name": "connection_kind", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "cost_group": { - "name": "cost_group", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "category": { - "name": "category", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "quantity": { - "name": "quantity", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "power_per_unit": { - "name": "power_per_unit", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - }, - "simultaneity_factor": { - "name": "simultaneity_factor", - "type": "real", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 1 - }, - "cos_phi": { - "name": "cos_phi", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "remark": { - "name": "remark", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "voltage_v": { - "name": "voltage_v", - "type": "real", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "project_devices_project_id_projects_id_fk": { - "name": "project_devices_project_id_projects_id_fk", - "tableFrom": "project_devices", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_history_stack_entries": { - "name": "project_history_stack_entries", - "columns": { - "change_set_id": { - "name": "change_set_id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "stack": { - "name": "stack", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "position": { - "name": "position", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "project_history_stack_entries_position_unique": { - "name": "project_history_stack_entries_position_unique", - "columns": [ - "project_id", - "stack", - "position" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_history_stack_entries_change_set_id_project_change_sets_id_fk": { - "name": "project_history_stack_entries_change_set_id_project_change_sets_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "project_change_sets", - "columnsFrom": [ - "change_set_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "project_history_stack_entries_project_id_projects_id_fk": { - "name": "project_history_stack_entries_project_id_projects_id_fk", - "tableFrom": "project_history_stack_entries", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": { - "project_history_stack_entries_stack_check": { - "name": "project_history_stack_entries_stack_check", - "value": "\"project_history_stack_entries\".\"stack\" in ('undo', 'redo')" - } - } - }, - "project_revisions": { - "name": "project_revisions", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "revision_number": { - "name": "revision_number", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "actor_id": { - "name": "actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "source": { - "name": "source", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_revisions_project_number_unique": { - "name": "project_revisions_project_number_unique", - "columns": [ - "project_id", - "revision_number" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_revisions_project_id_projects_id_fk": { - "name": "project_revisions_project_id_projects_id_fk", - "tableFrom": "project_revisions", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "project_snapshots": { - "name": "project_snapshots", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "source_revision": { - "name": "source_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "schema_version": { - "name": "schema_version", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "kind": { - "name": "kind", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'named'" - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "payload_json": { - "name": "payload_json", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "payload_sha256": { - "name": "payload_sha256", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_at_iso": { - "name": "created_at_iso", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "created_by_actor_id": { - "name": "created_by_actor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": { - "project_snapshots_project_created_idx": { - "name": "project_snapshots_project_created_idx", - "columns": [ - "project_id", - "created_at_iso" - ], - "isUnique": false - }, - "project_snapshots_project_kind_revision_idx": { - "name": "project_snapshots_project_kind_revision_idx", - "columns": [ - "project_id", - "kind", - "source_revision" - ], - "isUnique": false - }, - "project_snapshots_project_name_unique": { - "name": "project_snapshots_project_name_unique", - "columns": [ - "project_id", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "project_snapshots_project_id_projects_id_fk": { - "name": "project_snapshots_project_id_projects_id_fk", - "tableFrom": "project_snapshots", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "projects": { - "name": "projects", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "internal_project_number": { - "name": "internal_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "external_project_number": { - "name": "external_project_number", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "building_owner": { - "name": "building_owner", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "single_phase_voltage_v": { - "name": "single_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 230 - }, - "three_phase_voltage_v": { - "name": "three_phase_voltage_v", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 400 - }, - "enabled_distribution_board_supply_types": { - "name": "enabled_distribution_board_supply_types", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": "'[\"AV\",\"SV\",\"EV\",\"USV\",\"MSR\",\"SiBe\"]'" - }, - "current_revision": { - "name": "current_revision", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - }, - "rooms": { - "name": "rooms", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "project_id": { - "name": "project_id", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "floor_id": { - "name": "floor_id", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "room_number": { - "name": "room_number", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "room_name": { - "name": "room_name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "rooms_project_id_projects_id_fk": { - "name": "rooms_project_id_projects_id_fk", - "tableFrom": "rooms", - "tableTo": "projects", - "columnsFrom": [ - "project_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "rooms_floor_id_floors_id_fk": { - "name": "rooms_floor_id_floors_id_fk", - "tableFrom": "rooms", - "tableTo": "floors", - "columnsFrom": [ - "floor_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "set null", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {}, - "checkConstraints": {} - } - }, - "views": {}, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index afa07cf..44a9552 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -5,176 +5,8 @@ { "idx": 0, "version": "6", - "when": 1777565414148, - "tag": "0000_bizarre_colossus", - "breakpoints": true - }, - { - "idx": 1, - "version": "6", - "when": 1777577000000, - "tag": "0001_global_devices", - "breakpoints": true - }, - { - "idx": 2, - "version": "6", - "when": 1777580000000, - "tag": "0002_project_voltage_defaults", - "breakpoints": true - }, - { - "idx": 3, - "version": "6", - "when": 1777589000000, - "tag": "0003_project_floors_rooms", - "breakpoints": true - }, - { - "idx": 4, - "version": "6", - "when": 1777594000000, - "tag": "0004_circuit_lists_and_entry_fields", - "breakpoints": true - }, - { - "idx": 5, - "version": "6", - "when": 1777597000000, - "tag": "0005_project_devices", - "breakpoints": true - }, - { - "idx": 6, - "version": "6", - "when": 1777652000000, - "tag": "0006_device_display_name", - "breakpoints": true - }, - { - "idx": 7, - "version": "6", - "when": 1777680000000, - "tag": "0007_consumer_device_link", - "breakpoints": true - }, - { - "idx": 8, - "version": "6", - "when": 1777800000000, - "tag": "0008_circuit_first_model", - "breakpoints": true - }, - { - "idx": 9, - "version": "6", - "when": 1784743200000, - "tag": "0009_project_device_circuit_fields", - "breakpoints": true - }, - { - "idx": 10, - "version": "6", - "when": 1784746800000, - "tag": "0010_circuit_control_requirement", - "breakpoints": true - }, - { - "idx": 11, - "version": "6", - "when": 1784832541202, - "tag": "0011_project_device_canonical_fields", - "breakpoints": true - }, - { - "idx": 12, - "version": "6", - "when": 1784833957929, - "tag": "0012_project_revision_foundation", - "breakpoints": true - }, - { - "idx": 13, - "version": "6", - "when": 1784835703230, - "tag": "0013_project_history_stacks", - "breakpoints": true - }, - { - "idx": 14, - "version": "6", - "when": 1785009799979, - "tag": "0014_project_snapshots", - "breakpoints": true - }, - { - "idx": 15, - "version": "6", - "when": 1785014383032, - "tag": "0015_modern_madame_masque", - "breakpoints": true - }, - { - "idx": 16, - "version": "6", - "when": 1785254079435, - "tag": "0016_dashing_darkstar", - "breakpoints": true - }, - { - "idx": 17, - "version": "6", - "when": 1785307189539, - "tag": "0017_vengeful_romulus", - "breakpoints": true - }, - { - "idx": 18, - "version": "6", - "when": 1785308458789, - "tag": "0018_fancy_argent", - "breakpoints": true - }, - { - "idx": 19, - "version": "6", - "when": 1785310907349, - "tag": "0019_normalize_project_voltages", - "breakpoints": true - }, - { - "idx": 20, - "version": "6", - "when": 1785314248007, - "tag": "0020_normalize_phase_types", - "breakpoints": true - }, - { - "idx": 21, - "version": "6", - "when": 1785314558555, - "tag": "0021_fill_missing_phase_types", - "breakpoints": true - }, - { - "idx": 22, - "version": "6", - "when": 1785314626476, - "tag": "0022_default_remaining_phase_types", - "breakpoints": true - }, - { - "idx": 23, - "version": "6", - "when": 1785343645615, - "tag": "0023_cheerful_night_thrasher", - "breakpoints": true - }, - { - "idx": 24, - "version": "6", - "when": 1785431250141, - "tag": "0024_damp_mister_sinister", + "when": 1785499119431, + "tag": "0000_whole_surge", "breakpoints": true } ] diff --git a/src/db/repositories/circuit-device-row-move-project-command.repository.ts b/src/db/repositories/circuit-device-row-move-project-command.repository.ts index 0325d73..2c5bfc9 100644 --- a/src/db/repositories/circuit-device-row-move-project-command.repository.ts +++ b/src/db/repositories/circuit-device-row-move-project-command.repository.ts @@ -382,9 +382,6 @@ export class CircuitDeviceRowMoveProjectCommandRepository equipmentIdentifier: snapshot.equipmentIdentifier, displayName: snapshot.displayName, sortOrder: snapshot.sortOrder, - protectionType: snapshot.protectionType, - protectionRatedCurrent: snapshot.protectionRatedCurrent, - protectionCharacteristic: snapshot.protectionCharacteristic, cableType: snapshot.cableType, cableCrossSection: snapshot.cableCrossSection, cableLength: snapshot.cableLength, @@ -423,11 +420,6 @@ export class CircuitDeviceRowMoveProjectCommandRepository snapshot.equipmentIdentifier || current.displayName !== snapshot.displayName || current.sortOrder !== snapshot.sortOrder || - current.protectionType !== snapshot.protectionType || - current.protectionRatedCurrent !== - snapshot.protectionRatedCurrent || - current.protectionCharacteristic !== - snapshot.protectionCharacteristic || current.cableType !== snapshot.cableType || current.cableCrossSection !== snapshot.cableCrossSection || current.cableLength !== snapshot.cableLength || diff --git a/src/db/repositories/circuit-device-row-structure-project-command.repository.ts b/src/db/repositories/circuit-device-row-structure-project-command.repository.ts index 40f0bf9..4d9532d 100644 --- a/src/db/repositories/circuit-device-row-structure-project-command.repository.ts +++ b/src/db/repositories/circuit-device-row-structure-project-command.repository.ts @@ -77,11 +77,6 @@ export class CircuitDeviceRowStructureProjectCommandRepository source: ExecuteCircuitDeviceRowStructureCommandInput["source"], row: CircuitDeviceRowSnapshot ) { - if (source === "user" && row.legacyConsumerId !== null) { - throw new Error( - "User commands cannot assign legacy consumer ids." - ); - } if (source === "user" && !isElectricalPhaseType(row.phaseType)) { throw new Error("Device-row phase type is invalid."); } diff --git a/src/db/repositories/circuit-device-row-structure.persistence.ts b/src/db/repositories/circuit-device-row-structure.persistence.ts index 09aee9f..fffaff4 100644 --- a/src/db/repositories/circuit-device-row-structure.persistence.ts +++ b/src/db/repositories/circuit-device-row-structure.persistence.ts @@ -49,7 +49,6 @@ export function toCircuitDeviceRowSnapshot( id: row.id, circuitId: row.circuitId, linkedProjectDeviceId: row.linkedProjectDeviceId, - legacyConsumerId: row.legacyConsumerId, sortOrder: row.sortOrder, name: row.name, displayName: row.displayName, diff --git a/src/db/repositories/circuit-device-row.persistence.ts b/src/db/repositories/circuit-device-row.persistence.ts index 47ae7ee..e1f9222 100644 --- a/src/db/repositories/circuit-device-row.persistence.ts +++ b/src/db/repositories/circuit-device-row.persistence.ts @@ -44,7 +44,6 @@ export interface CircuitDeviceRowPatchInput { export interface CircuitDeviceRowCreateInput extends CircuitDeviceRowUpdateInput { circuitId: string; linkedProjectDeviceId?: string; - legacyConsumerId?: string; sortOrder: number; } @@ -110,7 +109,6 @@ export function toCircuitDeviceRowCreateValues( return { id, circuitId: input.circuitId, - legacyConsumerId: input.legacyConsumerId ?? null, sortOrder: input.sortOrder, ...toCircuitDeviceRowUpdateValues(input), }; diff --git a/src/db/repositories/circuit-device-row.repository.ts b/src/db/repositories/circuit-device-row.repository.ts index dc6118d..6bdb550 100644 --- a/src/db/repositories/circuit-device-row.repository.ts +++ b/src/db/repositories/circuit-device-row.repository.ts @@ -25,7 +25,6 @@ export class CircuitDeviceRowRepository { id: circuitDeviceRows.id, circuitId: circuitDeviceRows.circuitId, linkedProjectDeviceId: circuitDeviceRows.linkedProjectDeviceId, - legacyConsumerId: circuitDeviceRows.legacyConsumerId, sortOrder: circuitDeviceRows.sortOrder, name: circuitDeviceRows.name, displayName: circuitDeviceRows.displayName, diff --git a/src/db/repositories/circuit-structure-project-command.repository.ts b/src/db/repositories/circuit-structure-project-command.repository.ts index 11e6fd6..8e76e99 100644 --- a/src/db/repositories/circuit-structure-project-command.repository.ts +++ b/src/db/repositories/circuit-structure-project-command.repository.ts @@ -133,11 +133,6 @@ export class CircuitStructureProjectCommandRepository throw new Error("Circuit device-row id already exists."); } for (const row of snapshot.deviceRows) { - if (source === "user" && row.legacyConsumerId !== null) { - throw new Error( - "User commands cannot assign legacy consumer ids." - ); - } if (source === "user" && !isElectricalPhaseType(row.phaseType)) { throw new Error("Device-row phase type is invalid."); } @@ -158,9 +153,6 @@ export class CircuitStructureProjectCommandRepository equipmentIdentifier: snapshot.equipmentIdentifier, displayName: snapshot.displayName, sortOrder: snapshot.sortOrder, - protectionType: snapshot.protectionType, - protectionRatedCurrent: snapshot.protectionRatedCurrent, - protectionCharacteristic: snapshot.protectionCharacteristic, cableType: snapshot.cableType, cableCrossSection: snapshot.cableCrossSection, cableLength: snapshot.cableLength, @@ -238,9 +230,6 @@ export class CircuitStructureProjectCommandRepository equipmentIdentifier: circuit.equipmentIdentifier, displayName: circuit.displayName, sortOrder: circuit.sortOrder, - protectionType: circuit.protectionType, - protectionRatedCurrent: circuit.protectionRatedCurrent, - protectionCharacteristic: circuit.protectionCharacteristic, cableType: circuit.cableType, cableCrossSection: circuit.cableCrossSection, cableLength: circuit.cableLength, diff --git a/src/db/repositories/circuit.persistence.ts b/src/db/repositories/circuit.persistence.ts index f14bc2c..96bde5d 100644 --- a/src/db/repositories/circuit.persistence.ts +++ b/src/db/repositories/circuit.persistence.ts @@ -4,9 +4,6 @@ export interface CircuitCreatePersistenceInput { equipmentIdentifier: string; displayName?: string; sortOrder: number; - protectionType?: string; - protectionRatedCurrent?: number; - protectionCharacteristic?: string; cableType?: string; cableCrossSection?: string; cableLength?: number; @@ -24,9 +21,6 @@ export interface CircuitPatchPersistenceInput { equipmentIdentifier?: string; displayName?: string | null; sortOrder?: number; - protectionType?: string | null; - protectionRatedCurrent?: number | null; - protectionCharacteristic?: string | null; cableType?: string | null; cableCrossSection?: string | null; cableLength?: number | null; @@ -47,9 +41,6 @@ export function toCircuitCreateValues(id: string, input: CircuitCreatePersistenc equipmentIdentifier: input.equipmentIdentifier, displayName: input.displayName ?? null, sortOrder: input.sortOrder, - protectionType: input.protectionType ?? null, - protectionRatedCurrent: input.protectionRatedCurrent ?? null, - protectionCharacteristic: input.protectionCharacteristic ?? null, cableType: input.cableType ?? null, cableCrossSection: input.cableCrossSection ?? null, cableLength: input.cableLength ?? null, @@ -74,13 +65,6 @@ export function toCircuitPatchValues(input: CircuitPatchPersistenceInput) { } if (has("displayName")) values.displayName = input.displayName ?? null; if (input.sortOrder !== undefined) values.sortOrder = input.sortOrder; - if (has("protectionType")) values.protectionType = input.protectionType ?? null; - if (has("protectionRatedCurrent")) { - values.protectionRatedCurrent = input.protectionRatedCurrent ?? null; - } - if (has("protectionCharacteristic")) { - values.protectionCharacteristic = input.protectionCharacteristic ?? null; - } if (has("cableType")) values.cableType = input.cableType ?? null; if (has("cableCrossSection")) { values.cableCrossSection = input.cableCrossSection ?? null; diff --git a/src/db/repositories/distribution-board-structure-project-command.repository.ts b/src/db/repositories/distribution-board-structure-project-command.repository.ts index 9e7ae6f..29a8f21 100644 --- a/src/db/repositories/distribution-board-structure-project-command.repository.ts +++ b/src/db/repositories/distribution-board-structure-project-command.repository.ts @@ -12,7 +12,6 @@ import { import { assertDistributionBoardUpdateProjectCommand, createDistributionBoardUpdateProjectCommand, - legacyDistributionBoardUpdateCommandSchemaVersion, type DistributionBoardUpdateField, type DistributionBoardUpdatePatch, type DistributionBoardUpdateProjectCommand, @@ -332,19 +331,10 @@ export class DistributionBoardStructureProjectCommandRepository getDistributionBoardFieldValue(current, change.field), ]) ) as DistributionBoardUpdatePatch; - const currentInverse = createDistributionBoardUpdateProjectCommand( + const inverse = createDistributionBoardUpdateProjectCommand( current.id, inversePatch ); - const inverse = - input.command.schemaVersion === - legacyDistributionBoardUpdateCommandSchemaVersion - ? ({ - ...currentInverse, - schemaVersion: - legacyDistributionBoardUpdateCommandSchemaVersion, - } as DistributionBoardUpdateProjectCommand) - : currentInverse; const updated = database .update(distributionBoards) .set(patch) diff --git a/src/db/repositories/legacy-consumer-migration.repository.ts b/src/db/repositories/legacy-consumer-migration.repository.ts deleted file mode 100644 index 2c3fa35..0000000 --- a/src/db/repositories/legacy-consumer-migration.repository.ts +++ /dev/null @@ -1,142 +0,0 @@ -import crypto from "node:crypto"; -import { eq, inArray, isNull } from "drizzle-orm"; -import type { - LegacyMigrationCircuitInput, - LegacyMigrationReportInput, -} from "../../domain/ports/legacy-consumer-migration.store.js"; -import type { AppDatabase } from "../database-context.js"; -import { circuitDeviceRows } from "../schema/circuit-device-rows.js"; -import { circuits } from "../schema/circuits.js"; -import { consumers } from "../schema/consumers.js"; -import { legacyConsumerCircuitMigrations } from "../schema/legacy-consumer-circuit-migrations.js"; -import { legacyConsumerMigrationReports } from "../schema/legacy-consumer-migration-report.js"; -import { toCircuitDeviceRowCreateValues } from "./circuit-device-row.persistence.js"; -import { toCircuitCreateValues } from "./circuit.persistence.js"; - -export class LegacyConsumerMigrationRepository { - constructor(private readonly database: AppDatabase) {} - - async listSourceConsumersByCircuitList(circuitListId: string) { - return this.database - .select() - .from(consumers) - .where(eq(consumers.circuitListId, circuitListId)); - } - - async listUnmigratedConsumers() { - return this.database - .select({ - id: consumers.id, - projectId: consumers.projectId, - circuitListId: consumers.circuitListId, - }) - .from(consumers) - .leftJoin( - legacyConsumerCircuitMigrations, - eq(legacyConsumerCircuitMigrations.consumerId, consumers.id) - ) - .where(isNull(legacyConsumerCircuitMigrations.consumerId)); - } - - async listMigratedConsumerIds(circuitListId: string) { - const rows = await this.database - .select({ consumerId: legacyConsumerCircuitMigrations.consumerId }) - .from(legacyConsumerCircuitMigrations) - .where(eq(legacyConsumerCircuitMigrations.circuitListId, circuitListId)); - return rows.map((row) => row.consumerId); - } - - persistCircuitListMigration(input: { - circuitListId: string; - circuits: LegacyMigrationCircuitInput[]; - report: LegacyMigrationReportInput; - }) { - if (input.circuits.some((entry) => entry.circuit.circuitListId !== input.circuitListId)) { - throw new Error("All migrated circuits must belong to the target circuit list."); - } - - const consumerIds = input.circuits.flatMap((entry) => - entry.deviceRows.map((row) => row.legacyConsumerId) - ); - if (new Set(consumerIds).size !== consumerIds.length) { - throw new Error("A legacy consumer may only be migrated once per operation."); - } - - const preparedCircuits = input.circuits.map((entry) => { - const circuitId = crypto.randomUUID(); - return { - circuitId, - circuitValues: toCircuitCreateValues(circuitId, entry.circuit), - rows: entry.deviceRows.map((row) => { - const rowId = crypto.randomUUID(); - return { - consumerId: row.legacyConsumerId, - rowId, - rowValues: toCircuitDeviceRowCreateValues(rowId, { - ...row, - circuitId, - }), - }; - }), - }; - }); - const createdAtIso = new Date().toISOString(); - - this.database.transaction((tx) => { - if (consumerIds.length > 0) { - const existingMappings = tx - .select({ consumerId: legacyConsumerCircuitMigrations.consumerId }) - .from(legacyConsumerCircuitMigrations) - .where(inArray(legacyConsumerCircuitMigrations.consumerId, consumerIds)) - .all(); - if (existingMappings.length > 0) { - throw new Error("A legacy consumer was migrated before this operation completed."); - } - } - - for (const preparedCircuit of preparedCircuits) { - tx.insert(circuits).values(preparedCircuit.circuitValues).run(); - for (const row of preparedCircuit.rows) { - tx.insert(circuitDeviceRows).values(row.rowValues).run(); - tx - .insert(legacyConsumerCircuitMigrations) - .values({ - consumerId: row.consumerId, - circuitId: preparedCircuit.circuitId, - circuitDeviceRowId: row.rowId, - circuitListId: input.circuitListId, - createdAtIso, - }) - .run(); - } - } - - const reportValues = { - ...input.report, - createdAtIso, - }; - const existingReport = tx - .select({ id: legacyConsumerMigrationReports.id }) - .from(legacyConsumerMigrationReports) - .where(eq(legacyConsumerMigrationReports.circuitListId, input.circuitListId)) - .limit(1) - .all(); - if (existingReport.length > 0) { - tx - .update(legacyConsumerMigrationReports) - .set(reportValues) - .where(eq(legacyConsumerMigrationReports.id, existingReport[0].id)) - .run(); - } else { - tx - .insert(legacyConsumerMigrationReports) - .values({ - id: crypto.randomUUID(), - circuitListId: input.circuitListId, - ...reportValues, - }) - .run(); - } - }); - } -} diff --git a/src/db/repositories/project-device-structure-project-command.repository.ts b/src/db/repositories/project-device-structure-project-command.repository.ts index fcbdb2c..c75f7f5 100644 --- a/src/db/repositories/project-device-structure-project-command.repository.ts +++ b/src/db/repositories/project-device-structure-project-command.repository.ts @@ -34,7 +34,6 @@ const circuitDeviceRowSnapshotFields = [ "id", "circuitId", "linkedProjectDeviceId", - "legacyConsumerId", "sortOrder", "name", "displayName", diff --git a/src/db/repositories/project-location-structure-project-command.repository.ts b/src/db/repositories/project-location-structure-project-command.repository.ts index 2368def..2a3466a 100644 --- a/src/db/repositories/project-location-structure-project-command.repository.ts +++ b/src/db/repositories/project-location-structure-project-command.repository.ts @@ -22,7 +22,6 @@ import type { } from "../../domain/ports/project-location-structure-project-command.store.js"; import type { AppDatabase } from "../database-context.js"; import { circuitDeviceRows } from "../schema/circuit-device-rows.js"; -import { consumers } from "../schema/consumers.js"; import { floors } from "../schema/floors.js"; import { distributionBoards } from "../schema/distribution-boards.js"; import { projects } from "../schema/projects.js"; @@ -216,13 +215,7 @@ export class ProjectLocationStructureProjectCommandRepository .where(eq(circuitDeviceRows.roomId, expected.id)) .limit(1) .get(); - const referencedLegacyConsumer = database - .select({ id: consumers.id }) - .from(consumers) - .where(eq(consumers.roomId, expected.id)) - .limit(1) - .get(); - if (referencedDeviceRow || referencedLegacyConsumer) { + if (referencedDeviceRow) { throw new Error( "A referenced project room cannot be removed by history." ); diff --git a/src/db/repositories/project-settings-project-command.repository.ts b/src/db/repositories/project-settings-project-command.repository.ts index a5a3621..9ff2405 100644 --- a/src/db/repositories/project-settings-project-command.repository.ts +++ b/src/db/repositories/project-settings-project-command.repository.ts @@ -2,9 +2,6 @@ import { and, eq, isNotNull } from "drizzle-orm"; import { assertProjectSettingsUpdateProjectCommand, createProjectSettingsUpdateProjectCommand, - legacyProjectSettingsUpdateCommandSchemaVersion, - normalizeProjectSettingsValues, - previousProjectSettingsUpdateCommandSchemaVersion, type ProjectSettingsValues, } from "../../domain/models/project-settings-project-command.model.js"; import type { @@ -43,49 +40,22 @@ export class ProjectSettingsProjectCommandRepository if (!current) { throw new Error("Project not found."); } - const target = normalizeProjectSettingsValues(input.command, current); + const target = input.command.payload; if (projectSettingsEqual(current, target)) { throw new Error("Project settings did not change."); } - const inverse = - input.command.schemaVersion === - legacyProjectSettingsUpdateCommandSchemaVersion - ? { - schemaVersion: legacyProjectSettingsUpdateCommandSchemaVersion, - type: input.command.type, - payload: { - singlePhaseVoltageV: current.singlePhaseVoltageV, - threePhaseVoltageV: current.threePhaseVoltageV, - }, - } - : input.command.schemaVersion === - previousProjectSettingsUpdateCommandSchemaVersion - ? { - schemaVersion: - previousProjectSettingsUpdateCommandSchemaVersion, - type: input.command.type, - payload: { - name: current.name, - internalProjectNumber: current.internalProjectNumber, - externalProjectNumber: current.externalProjectNumber, - buildingOwner: current.buildingOwner, - description: current.description, - singlePhaseVoltageV: current.singlePhaseVoltageV, - threePhaseVoltageV: current.threePhaseVoltageV, - }, - } - : createProjectSettingsUpdateProjectCommand({ - name: current.name, - internalProjectNumber: current.internalProjectNumber, - externalProjectNumber: current.externalProjectNumber, - buildingOwner: current.buildingOwner, - description: current.description, - singlePhaseVoltageV: current.singlePhaseVoltageV, - threePhaseVoltageV: current.threePhaseVoltageV, - enabledDistributionBoardSupplyTypes: - current.enabledDistributionBoardSupplyTypes, - }); + const inverse = createProjectSettingsUpdateProjectCommand({ + name: current.name, + internalProjectNumber: current.internalProjectNumber, + externalProjectNumber: current.externalProjectNumber, + buildingOwner: current.buildingOwner, + description: current.description, + singlePhaseVoltageV: current.singlePhaseVoltageV, + threePhaseVoltageV: current.threePhaseVoltageV, + enabledDistributionBoardSupplyTypes: + current.enabledDistributionBoardSupplyTypes, + }); assertDisabledSupplyTypesAreUnused(tx, input.projectId, target); const updated = tx .update(projects) diff --git a/src/db/repositories/project-snapshot.repository.ts b/src/db/repositories/project-snapshot.repository.ts index 7d645cc..5274fee 100644 --- a/src/db/repositories/project-snapshot.repository.ts +++ b/src/db/repositories/project-snapshot.repository.ts @@ -4,14 +4,8 @@ import { ProjectRevisionConflictError } from "../../domain/errors/project-revisi import { ProjectSnapshotNameConflictError } from "../../domain/errors/project-snapshot-name-conflict.error.js"; import { createProjectStateRestoreCommand } from "../../domain/models/project-state-restore-command.model.js"; import { - distributionBoardProjectStateSnapshotSchemaVersion, deserializeProjectStateSnapshot, - legacyProjectStateSnapshotSchemaVersion, - previousProjectStateSnapshotSchemaVersion, projectStateSnapshotSchemaVersion, - simultaneityFactorProjectStateSnapshotSchemaVersion, - supplyTypesProjectStateSnapshotSchemaVersion, - voltageProjectStateSnapshotSchemaVersion, } from "../../domain/models/project-state-snapshot.model.js"; import type { CreateNamedProjectSnapshotInput, @@ -144,19 +138,7 @@ export class ProjectSnapshotRepository implements ProjectSnapshotStore { if (actualChecksum !== stored.payloadSha256) { throw new Error("Project snapshot checksum verification failed."); } - if ( - stored.schemaVersion !== legacyProjectStateSnapshotSchemaVersion && - stored.schemaVersion !== previousProjectStateSnapshotSchemaVersion && - stored.schemaVersion !== - distributionBoardProjectStateSnapshotSchemaVersion && - stored.schemaVersion !== - supplyTypesProjectStateSnapshotSchemaVersion && - stored.schemaVersion !== - voltageProjectStateSnapshotSchemaVersion && - stored.schemaVersion !== - simultaneityFactorProjectStateSnapshotSchemaVersion && - stored.schemaVersion !== projectStateSnapshotSchemaVersion - ) { + if (stored.schemaVersion !== projectStateSnapshotSchemaVersion) { throw new Error("Project snapshot schema version is not supported."); } const targetState = deserializeProjectStateSnapshot(stored.payloadJson); diff --git a/src/db/repositories/project-state-restore-command.repository.ts b/src/db/repositories/project-state-restore-command.repository.ts index 2d42589..aa0f05d 100644 --- a/src/db/repositories/project-state-restore-command.repository.ts +++ b/src/db/repositories/project-state-restore-command.repository.ts @@ -18,13 +18,10 @@ import { circuitLists } from "../schema/circuit-lists.js"; import { circuitProtectionDevices } from "../schema/circuit-protection-devices.js"; import { circuitSections } from "../schema/circuit-sections.js"; import { circuits } from "../schema/circuits.js"; -import { consumers } from "../schema/consumers.js"; import { distributionBoardComponentProtectionDevices } from "../schema/distribution-board-component-protection-devices.js"; import { distributionBoardComponents } from "../schema/distribution-board-components.js"; import { distributionBoards } from "../schema/distribution-boards.js"; import { floors } from "../schema/floors.js"; -import { legacyConsumerCircuitMigrations } from "../schema/legacy-consumer-circuit-migrations.js"; -import { legacyConsumerMigrationReports } from "../schema/legacy-consumer-migration-report.js"; import { projectDevices } from "../schema/project-devices.js"; import { projectChangeSets } from "../schema/project-change-sets.js"; import { projects } from "../schema/projects.js"; @@ -186,10 +183,6 @@ function replaceProjectState( database: AppDatabase, state: ProjectStateSnapshot ) { - const upgradeOnlyData = captureUpgradeOnlyData( - database, - state.project.id - ); database .delete(distributionBoards) .where(eq(distributionBoards.projectId, state.project.id)) @@ -257,136 +250,6 @@ function replaceProjectState( circuitDeviceRows, state.circuits.flatMap((circuit) => circuit.deviceRows) ); - restoreCompatibleUpgradeOnlyData(database, state, upgradeOnlyData); -} - -function captureUpgradeOnlyData( - database: AppDatabase, - projectId: string -) { - const consumerLinks = database - .select({ - id: consumers.id, - distributionBoardId: consumers.distributionBoardId, - circuitListId: consumers.circuitListId, - projectDeviceId: consumers.projectDeviceId, - roomId: consumers.roomId, - }) - .from(consumers) - .where(eq(consumers.projectId, projectId)) - .all(); - const migrationMappings = database - .select({ - consumerId: legacyConsumerCircuitMigrations.consumerId, - circuitId: legacyConsumerCircuitMigrations.circuitId, - circuitDeviceRowId: - legacyConsumerCircuitMigrations.circuitDeviceRowId, - circuitListId: legacyConsumerCircuitMigrations.circuitListId, - createdAtIso: legacyConsumerCircuitMigrations.createdAtIso, - }) - .from(legacyConsumerCircuitMigrations) - .innerJoin( - circuitLists, - eq( - circuitLists.id, - legacyConsumerCircuitMigrations.circuitListId - ) - ) - .where(eq(circuitLists.projectId, projectId)) - .all(); - const migrationReports = database - .select({ - id: legacyConsumerMigrationReports.id, - circuitListId: legacyConsumerMigrationReports.circuitListId, - legacyConsumerCount: - legacyConsumerMigrationReports.legacyConsumerCount, - createdCircuitCount: - legacyConsumerMigrationReports.createdCircuitCount, - createdDeviceRowCount: - legacyConsumerMigrationReports.createdDeviceRowCount, - duplicateGroupedCount: - legacyConsumerMigrationReports.duplicateGroupedCount, - generatedIdentifierCount: - legacyConsumerMigrationReports.generatedIdentifierCount, - unassignedRowCount: - legacyConsumerMigrationReports.unassignedRowCount, - warningsJson: legacyConsumerMigrationReports.warningsJson, - generatedIdentifiersJson: - legacyConsumerMigrationReports.generatedIdentifiersJson, - duplicateGroupsJson: - legacyConsumerMigrationReports.duplicateGroupsJson, - createdAtIso: legacyConsumerMigrationReports.createdAtIso, - }) - .from(legacyConsumerMigrationReports) - .innerJoin( - circuitLists, - eq(circuitLists.id, legacyConsumerMigrationReports.circuitListId) - ) - .where(eq(circuitLists.projectId, projectId)) - .all(); - return { consumerLinks, migrationMappings, migrationReports }; -} - -function restoreCompatibleUpgradeOnlyData( - database: AppDatabase, - state: ProjectStateSnapshot, - data: ReturnType -) { - const boardIds = new Set( - state.distributionBoards.map((entry) => entry.id) - ); - const listIds = new Set(state.circuitLists.map((entry) => entry.id)); - const deviceIds = new Set( - state.projectDevices.map((entry) => entry.id) - ); - const roomIds = new Set(state.rooms.map((entry) => entry.id)); - const circuitIds = new Set(state.circuits.map((entry) => entry.id)); - const rowIds = new Set( - state.circuits.flatMap((circuit) => - circuit.deviceRows.map((entry) => entry.id) - ) - ); - - for (const link of data.consumerLinks) { - database - .update(consumers) - .set({ - distributionBoardId: - link.distributionBoardId && - boardIds.has(link.distributionBoardId) - ? link.distributionBoardId - : null, - circuitListId: - link.circuitListId && listIds.has(link.circuitListId) - ? link.circuitListId - : null, - projectDeviceId: - link.projectDeviceId && deviceIds.has(link.projectDeviceId) - ? link.projectDeviceId - : null, - roomId: - link.roomId && roomIds.has(link.roomId) ? link.roomId : null, - }) - .where(eq(consumers.id, link.id)) - .run(); - } - insertMany( - database, - legacyConsumerCircuitMigrations, - data.migrationMappings.filter( - (entry) => - listIds.has(entry.circuitListId) && - circuitIds.has(entry.circuitId) && - rowIds.has(entry.circuitDeviceRowId) - ) - ); - insertMany( - database, - legacyConsumerMigrationReports, - data.migrationReports.filter((entry) => - listIds.has(entry.circuitListId) - ) - ); } function insertMany[0]>( diff --git a/src/db/repositories/project-state-snapshot.persistence.ts b/src/db/repositories/project-state-snapshot.persistence.ts index ef20776..f82702c 100644 --- a/src/db/repositories/project-state-snapshot.persistence.ts +++ b/src/db/repositories/project-state-snapshot.persistence.ts @@ -145,9 +145,6 @@ export function readProjectStateSnapshot( equipmentIdentifier: circuits.equipmentIdentifier, displayName: circuits.displayName, sortOrder: circuits.sortOrder, - protectionType: circuits.protectionType, - protectionRatedCurrent: circuits.protectionRatedCurrent, - protectionCharacteristic: circuits.protectionCharacteristic, cableType: circuits.cableType, cableCrossSection: circuits.cableCrossSection, cableLength: circuits.cableLength, @@ -173,7 +170,6 @@ export function readProjectStateSnapshot( id: circuitDeviceRows.id, circuitId: circuitDeviceRows.circuitId, linkedProjectDeviceId: circuitDeviceRows.linkedProjectDeviceId, - legacyConsumerId: circuitDeviceRows.legacyConsumerId, sortOrder: circuitDeviceRows.sortOrder, name: circuitDeviceRows.name, displayName: circuitDeviceRows.displayName, diff --git a/src/db/schema/circuit-device-rows.ts b/src/db/schema/circuit-device-rows.ts index 6fefd18..805b590 100644 --- a/src/db/schema/circuit-device-rows.ts +++ b/src/db/schema/circuit-device-rows.ts @@ -11,7 +11,6 @@ export const circuitDeviceRows = sqliteTable("circuit_device_rows", { 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(), diff --git a/src/db/schema/circuits.ts b/src/db/schema/circuits.ts index 27b4683..c0c733c 100644 --- a/src/db/schema/circuits.ts +++ b/src/db/schema/circuits.ts @@ -15,9 +15,6 @@ export const circuits = sqliteTable( 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"), diff --git a/src/db/schema/consumers.ts b/src/db/schema/consumers.ts deleted file mode 100644 index a7ee83d..0000000 --- a/src/db/schema/consumers.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { integer, real, sqliteTable, text } from "drizzle-orm/sqlite-core"; -import { circuitLists } from "./circuit-lists.js"; -import { distributionBoards } from "./distribution-boards.js"; -import { projectDevices } from "./project-devices.js"; -import { projects } from "./projects.js"; -import { rooms } from "./rooms.js"; - -export const consumers = sqliteTable("consumers", { - id: text("id").primaryKey(), - projectId: text("project_id") - .notNull() - .references(() => projects.id, { onDelete: "cascade" }), - distributionBoardId: text("distribution_board_id").references(() => distributionBoards.id, { - onDelete: "set null", - }), - circuitListId: text("circuit_list_id").references(() => circuitLists.id, { - onDelete: "set null", - }), - projectDeviceId: text("project_device_id").references(() => projectDevices.id, { - onDelete: "set null", - }), - isLinkedToDevice: integer("is_linked_to_device").notNull().default(0), - roomId: text("room_id").references(() => rooms.id, { - onDelete: "set null", - }), - circuitNumber: text("circuit_number"), - description: text("description"), - name: text("name").notNull(), - category: text("category"), - deviceType: text("device_type"), - phaseType: text("phase_type"), - tradeOrCostGroup: text("trade_or_cost_group"), - group: text("group_name"), - protectionType: text("protection_type"), - protectionRatedCurrent: real("protection_rated_current"), - protectionCharacteristic: text("protection_characteristic"), - cableType: text("cable_type"), - cableCrossSection: text("cable_cross_section"), - comment: text("comment"), - quantity: integer("quantity").notNull(), - installedPowerPerUnitKw: real("installed_power_per_unit_kw").notNull(), - demandFactor: real("demand_factor").notNull(), - voltageV: real("voltage_v"), - phaseCount: integer("phase_count"), - powerFactor: real("power_factor"), - note: text("note"), -}); diff --git a/src/db/schema/legacy-consumer-circuit-migrations.ts b/src/db/schema/legacy-consumer-circuit-migrations.ts deleted file mode 100644 index 04f6bbb..0000000 --- a/src/db/schema/legacy-consumer-circuit-migrations.ts +++ /dev/null @@ -1,19 +0,0 @@ -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(), -}); - diff --git a/src/db/schema/legacy-consumer-migration-report.ts b/src/db/schema/legacy-consumer-migration-report.ts deleted file mode 100644 index 0084ef9..0000000 --- a/src/db/schema/legacy-consumer-migration-report.ts +++ /dev/null @@ -1,24 +0,0 @@ -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)] -); - diff --git a/src/domain/models/circuit-device-row-structure-project-command.model.ts b/src/domain/models/circuit-device-row-structure-project-command.model.ts index 57efbdc..a897b6b 100644 --- a/src/domain/models/circuit-device-row-structure-project-command.model.ts +++ b/src/domain/models/circuit-device-row-structure-project-command.model.ts @@ -10,7 +10,6 @@ export interface CircuitDeviceRowSnapshot { id: string; circuitId: string; linkedProjectDeviceId: string | null; - legacyConsumerId: string | null; sortOrder: number; name: string; displayName: string; @@ -101,7 +100,6 @@ export function assertCircuitDeviceRowInsertProjectCommand( assertNonEmptyString(row.id, "row.id"); assertNonEmptyString(row.circuitId, "row.circuitId"); assertNullableString(row.linkedProjectDeviceId, "row.linkedProjectDeviceId"); - assertNullableString(row.legacyConsumerId, "row.legacyConsumerId"); assertFiniteNumber(row.sortOrder, "row.sortOrder"); assertNonEmptyString(row.name, "row.name"); assertNonEmptyString(row.displayName, "row.displayName"); diff --git a/src/domain/models/circuit-device-row.model.ts b/src/domain/models/circuit-device-row.model.ts index f3adfa8..2b6c11c 100644 --- a/src/domain/models/circuit-device-row.model.ts +++ b/src/domain/models/circuit-device-row.model.ts @@ -2,7 +2,6 @@ export interface CircuitDeviceRow { id: string; circuitId: string; linkedProjectDeviceId?: string; - legacyConsumerId?: string; sortOrder: number; name: string; displayName: string; diff --git a/src/domain/models/circuit-project-command.model.ts b/src/domain/models/circuit-project-command.model.ts index 4cdaaa3..af70d2f 100644 --- a/src/domain/models/circuit-project-command.model.ts +++ b/src/domain/models/circuit-project-command.model.ts @@ -8,9 +8,6 @@ export interface CircuitUpdateValues { equipmentIdentifier: string; displayName: string | null; sortOrder: number; - protectionType: string | null; - protectionRatedCurrent: number | null; - protectionCharacteristic: string | null; cableType: string | null; cableCrossSection: string | null; cableLength: number | null; @@ -118,7 +115,6 @@ function assertCircuitUpdateFieldValue( return; } if ( - field === "protectionRatedCurrent" || field === "cableLength" || field === "voltage" ) { @@ -147,9 +143,6 @@ function isCircuitUpdateField(value: string): value is CircuitUpdateField { "equipmentIdentifier", "displayName", "sortOrder", - "protectionType", - "protectionRatedCurrent", - "protectionCharacteristic", "cableType", "cableCrossSection", "cableLength", diff --git a/src/domain/models/circuit-structure-project-command.model.ts b/src/domain/models/circuit-structure-project-command.model.ts index 9cbde65..5260c4b 100644 --- a/src/domain/models/circuit-structure-project-command.model.ts +++ b/src/domain/models/circuit-structure-project-command.model.ts @@ -21,9 +21,6 @@ export interface CircuitSnapshot { equipmentIdentifier: string; displayName: string | null; sortOrder: number; - protectionType: string | null; - protectionRatedCurrent: number | null; - protectionCharacteristic: string | null; cableType: string | null; cableCrossSection: string | null; cableLength: number | null; @@ -115,8 +112,6 @@ export function assertCircuitInsertProjectCommand( assertNullableString(circuit.displayName, "circuit.displayName"); assertFiniteNumber(circuit.sortOrder, "circuit.sortOrder"); for (const field of [ - "protectionType", - "protectionCharacteristic", "cableType", "cableCrossSection", "rcdAssignment", @@ -127,10 +122,6 @@ export function assertCircuitInsertProjectCommand( ] as const) { assertNullableString(circuit[field], `circuit.${field}`); } - assertNullableNonNegativeNumber( - circuit.protectionRatedCurrent, - "circuit.protectionRatedCurrent" - ); assertNullableNonNegativeNumber( circuit.cableLength, "circuit.cableLength" diff --git a/src/domain/models/circuit-tree.model.ts b/src/domain/models/circuit-tree.model.ts index dee49ce..37d68ca 100644 --- a/src/domain/models/circuit-tree.model.ts +++ b/src/domain/models/circuit-tree.model.ts @@ -1,7 +1,6 @@ export interface CircuitTreeDeviceRow { id: string; linkedProjectDeviceId?: string; - legacyConsumerId?: string; sortOrder: number; name: string; displayName: string; @@ -29,9 +28,6 @@ export interface CircuitTreeCircuit { equipmentIdentifier: string; displayName?: string; sortOrder: number; - protectionType?: string; - protectionRatedCurrent?: number; - protectionCharacteristic?: string; cableType?: string; cableCrossSection?: string; cableLength?: number; @@ -73,17 +69,6 @@ export interface CircuitTreeResponse { footerComponents: CircuitTreeComponent[]; } -export interface LegacyMigrationReport { - circuitListId: string; - legacyConsumerCount: number; - createdCircuitCount: number; - createdDeviceRowCount: number; - groupedDuplicateCircuitNumbers: Array<{ normalizedCircuitNumber: string; count: number }>; - generatedIdentifiers: string[]; - unassignedRows: Array<{ consumerId: string; reason: string }>; - warnings: string[]; -} - import type { CircuitGroupCategory } from "../../shared/constants/circuit-group.js"; import type { DistributionBoardComponentPlacement, diff --git a/src/domain/models/circuit.model.ts b/src/domain/models/circuit.model.ts index a0bca18..3efe12c 100644 --- a/src/domain/models/circuit.model.ts +++ b/src/domain/models/circuit.model.ts @@ -5,9 +5,6 @@ export interface Circuit { equipmentIdentifier: string; displayName?: string; sortOrder: number; - protectionType?: string; - protectionRatedCurrent?: number; - protectionCharacteristic?: string; cableType?: string; cableCrossSection?: string; cableLength?: number; diff --git a/src/domain/models/distribution-board-project-command.model.ts b/src/domain/models/distribution-board-project-command.model.ts index 8f6d4fc..a41be72 100644 --- a/src/domain/models/distribution-board-project-command.model.ts +++ b/src/domain/models/distribution-board-project-command.model.ts @@ -6,8 +6,7 @@ import type { SerializedProjectCommand } from "./project-command.model.js"; export const distributionBoardUpdateCommandType = "distribution-board.update" as const; -export const legacyDistributionBoardUpdateCommandSchemaVersion = 1 as const; -export const distributionBoardUpdateCommandSchemaVersion = 2 as const; +export const distributionBoardUpdateCommandSchemaVersion = 1 as const; export interface DistributionBoardUpdateValues { floorId: string | null; @@ -33,27 +32,17 @@ export interface DistributionBoardUpdateCommandPayload { changes: DistributionBoardUpdateFieldChange[]; } -interface CurrentDistributionBoardUpdateProjectCommand +export interface DistributionBoardUpdateProjectCommand extends SerializedProjectCommand { schemaVersion: typeof distributionBoardUpdateCommandSchemaVersion; type: typeof distributionBoardUpdateCommandType; } -interface LegacyDistributionBoardUpdateProjectCommand - extends SerializedProjectCommand { - schemaVersion: typeof legacyDistributionBoardUpdateCommandSchemaVersion; - type: typeof distributionBoardUpdateCommandType; -} - -export type DistributionBoardUpdateProjectCommand = - | CurrentDistributionBoardUpdateProjectCommand - | LegacyDistributionBoardUpdateProjectCommand; - export function createDistributionBoardUpdateProjectCommand( distributionBoardId: string, patch: DistributionBoardUpdatePatch -): CurrentDistributionBoardUpdateProjectCommand { - const command: CurrentDistributionBoardUpdateProjectCommand = { +): DistributionBoardUpdateProjectCommand { + const command: DistributionBoardUpdateProjectCommand = { schemaVersion: distributionBoardUpdateCommandSchemaVersion, type: distributionBoardUpdateCommandType, payload: { @@ -72,9 +61,7 @@ export function assertDistributionBoardUpdateProjectCommand( command: SerializedProjectCommand ): asserts command is DistributionBoardUpdateProjectCommand { if ( - (command.schemaVersion !== - legacyDistributionBoardUpdateCommandSchemaVersion && - command.schemaVersion !== distributionBoardUpdateCommandSchemaVersion) || + command.schemaVersion !== distributionBoardUpdateCommandSchemaVersion || command.type !== distributionBoardUpdateCommandType || !isPlainObject(command.payload) ) { @@ -97,9 +84,7 @@ export function assertDistributionBoardUpdateProjectCommand( !isPlainObject(change) || (change.field !== "floorId" && change.field !== "supplyType" && - (command.schemaVersion === - legacyDistributionBoardUpdateCommandSchemaVersion || - change.field !== "simultaneityFactor")) || + change.field !== "simultaneityFactor") || seen.has(change.field) ) { throw new Error( diff --git a/src/domain/models/distribution-board-structure-project-command.model.ts b/src/domain/models/distribution-board-structure-project-command.model.ts index 6553399..f461734 100644 --- a/src/domain/models/distribution-board-structure-project-command.model.ts +++ b/src/domain/models/distribution-board-structure-project-command.model.ts @@ -18,36 +18,7 @@ export const distributionBoardInsertCommandType = "distribution-board.insert" as const; export const distributionBoardDeleteCommandType = "distribution-board.delete" as const; -export const legacyDistributionBoardStructureCommandSchemaVersion = 1 as const; -export const previousDistributionBoardStructureCommandSchemaVersion = 2 as const; -export const distributionBoardStructureCommandSchemaVersion = 3 as const; - -const legacyDefaultCircuitSectionDefinitions = [ - { - key: "lighting", - displayName: "Lighting", - prefix: "-1F", - sortOrder: 10, - }, - { - key: "single_phase", - displayName: "Single-phase circuits", - prefix: "-2F", - sortOrder: 20, - }, - { - key: "three_phase", - displayName: "Three-phase circuits", - prefix: "-3F", - sortOrder: 30, - }, - { - key: "unassigned", - displayName: "Unassigned", - prefix: "-UF", - sortOrder: 90, - }, -] as const; +export const distributionBoardStructureCommandSchemaVersion = 1 as const; export const defaultCircuitSectionDefinitions = [ { @@ -76,31 +47,6 @@ export const defaultCircuitSectionDefinitions = [ }, ] as const; -interface LegacyDistributionBoardStructureSnapshot { - distributionBoard: { - id: string; - projectId: string; - name: string; - }; - circuitList: DistributionBoardStructureSnapshot["circuitList"]; - sections: LegacyCircuitSectionSnapshot[]; -} - -interface PreviousDistributionBoardStructureSnapshot { - distributionBoard: DistributionBoardStructureSnapshot["distributionBoard"]; - circuitList: DistributionBoardStructureSnapshot["circuitList"]; - sections: LegacyCircuitSectionSnapshot[]; -} - -interface LegacyCircuitSectionSnapshot { - id: string; - circuitListId: string; - key: string; - displayName: string; - prefix: string; - sortOrder: number; -} - export interface DistributionBoardStructureSnapshot { distributionBoard: { id: string; @@ -140,22 +86,15 @@ export interface DistributionBoardStructureSnapshot { export interface NormalizedDistributionBoardStructureSnapshot { distributionBoard: DistributionBoardStructureSnapshot["distributionBoard"]; circuitList: DistributionBoardStructureSnapshot["circuitList"]; - sections: Array< - LegacyCircuitSectionSnapshot & { - category: CircuitGroupCategory | null; - groupNumber: number | null; - } - >; + sections: DistributionBoardStructureSnapshot["sections"]; components: DistributionBoardStructureSnapshot["components"]; } -interface DistributionBoardStructureCommandPayload< - TStructure = DistributionBoardStructureSnapshot, -> { - structure: TStructure; +interface DistributionBoardStructureCommandPayload { + structure: DistributionBoardStructureSnapshot; } -interface CurrentDistributionBoardStructureProjectCommand +interface DistributionBoardStructureProjectCommandBase extends SerializedProjectCommand { schemaVersion: typeof distributionBoardStructureCommandSchemaVersion; type: @@ -163,41 +102,19 @@ interface CurrentDistributionBoardStructureProjectCommand | typeof distributionBoardDeleteCommandType; } -interface LegacyDistributionBoardStructureProjectCommand - extends SerializedProjectCommand< - DistributionBoardStructureCommandPayload - > { - schemaVersion: typeof legacyDistributionBoardStructureCommandSchemaVersion; - type: - | typeof distributionBoardInsertCommandType - | typeof distributionBoardDeleteCommandType; -} - -interface PreviousDistributionBoardStructureProjectCommand - extends SerializedProjectCommand< - DistributionBoardStructureCommandPayload - > { - schemaVersion: typeof previousDistributionBoardStructureCommandSchemaVersion; - type: - | typeof distributionBoardInsertCommandType - | typeof distributionBoardDeleteCommandType; -} - export interface DistributionBoardInsertProjectCommand - extends CurrentDistributionBoardStructureProjectCommand { + extends DistributionBoardStructureProjectCommandBase { type: typeof distributionBoardInsertCommandType; } export interface DistributionBoardDeleteProjectCommand - extends CurrentDistributionBoardStructureProjectCommand { + extends DistributionBoardStructureProjectCommandBase { type: typeof distributionBoardDeleteCommandType; } export type DistributionBoardStructureProjectCommand = | DistributionBoardInsertProjectCommand - | DistributionBoardDeleteProjectCommand - | PreviousDistributionBoardStructureProjectCommand - | LegacyDistributionBoardStructureProjectCommand; + | DistributionBoardDeleteProjectCommand; export function createDistributionBoardStructureSnapshot( projectId: string, @@ -296,35 +213,6 @@ export function assertDistributionBoardDeleteProjectCommand( export function normalizeDistributionBoardStructureProjectCommand( command: DistributionBoardStructureProjectCommand ): NormalizedDistributionBoardStructureSnapshot { - if ( - command.schemaVersion === - legacyDistributionBoardStructureCommandSchemaVersion - ) { - return { - distributionBoard: { - ...command.payload.structure.distributionBoard, - floorId: null, - supplyType: null, - }, - circuitList: command.payload.structure.circuitList, - sections: command.payload.structure.sections.map( - normalizeLegacySection - ), - components: [], - }; - } - if ( - command.schemaVersion === - previousDistributionBoardStructureCommandSchemaVersion - ) { - return { - ...command.payload.structure, - sections: command.payload.structure.sections.map( - normalizeLegacySection - ), - components: [], - }; - } return command.payload.structure; } @@ -340,26 +228,10 @@ export function invertDistributionBoardStructureProjectCommand( } as DistributionBoardStructureProjectCommand; } -function normalizeLegacySection( - section: LegacyCircuitSectionSnapshot -): NormalizedDistributionBoardStructureSnapshot["sections"][number] { - const category = - section.key === "lighting" || - section.key === "single_phase" || - section.key === "three_phase" - ? section.key - : null; - return { - ...section, - category, - groupNumber: category === null ? null : 1, - }; -} - export function assertDistributionBoardStructureSnapshot( structure: unknown ): asserts structure is DistributionBoardStructureSnapshot { - assertDistributionBoardStructureSnapshotVersion(structure, "current"); + assertDistributionBoardStructureSnapshotVersion(structure); } function assertDistributionBoardStructureProjectCommand( @@ -375,63 +247,36 @@ function assertDistributionBoardStructureProjectCommand( ) { throw new Error("Unsupported distribution-board structure command."); } - if ( - command.schemaVersion === - legacyDistributionBoardStructureCommandSchemaVersion - ) { - assertDistributionBoardStructureSnapshotVersion( - command.payload.structure, - "legacy" - ); - return; - } - if ( - command.schemaVersion === - previousDistributionBoardStructureCommandSchemaVersion - ) { - assertDistributionBoardStructureSnapshotVersion( - command.payload.structure, - "previous" - ); - return; - } if ( command.schemaVersion !== distributionBoardStructureCommandSchemaVersion ) { throw new Error("Unsupported distribution-board structure command."); } - assertDistributionBoardStructureSnapshotVersion( - command.payload.structure, - "current" - ); + assertDistributionBoardStructureSnapshotVersion(command.payload.structure); } function assertDistributionBoardStructureSnapshotVersion( - structure: unknown, - version: "legacy" | "previous" | "current" + structure: unknown ) { - const current = version === "current"; if ( !isPlainObject(structure) || - Object.keys(structure).length !== (current ? 4 : 3) + Object.keys(structure).length !== 4 ) { throw new Error("Distribution-board structure is invalid."); } const { distributionBoard, circuitList, sections, components } = structure; - const expectedSections = current - ? defaultCircuitSectionDefinitions - : legacyDefaultCircuitSectionDefinitions; + const expectedSections = defaultCircuitSectionDefinitions; if ( !isPlainObject(distributionBoard) || - Object.keys(distributionBoard).length !== - (version === "legacy" ? 3 : 5) || + Object.keys(distributionBoard).length !== 5 || !isPlainObject(circuitList) || Object.keys(circuitList).length !== 4 || !Array.isArray(sections) || sections.length !== expectedSections.length || - (current && (!Array.isArray(components) || components.length !== 2)) + !Array.isArray(components) || + components.length !== 2 ) { throw new Error("Distribution-board structure is incomplete."); } @@ -441,10 +286,8 @@ function assertDistributionBoardStructureSnapshotVersion( `distributionBoard.${field}` ); } - if (version !== "legacy") { - assertNullableId(distributionBoard.floorId, "distributionBoard.floorId"); - assertNullableSupplyType(distributionBoard.supplyType); - } + assertNullableId(distributionBoard.floorId, "distributionBoard.floorId"); + assertNullableSupplyType(distributionBoard.supplyType); for (const [field, value] of Object.entries(circuitList)) { assertNonEmptyString(value, `circuitList.${field}`); } @@ -462,7 +305,7 @@ function assertDistributionBoardStructureSnapshotVersion( const expected = expectedSections[index]; if ( !isPlainObject(section) || - Object.keys(section).length !== (current ? 8 : 6) + Object.keys(section).length !== 8 ) { throw new Error("Default circuit section is invalid."); } @@ -477,10 +320,8 @@ function assertDistributionBoardStructureSnapshotVersion( section.displayName !== expected.displayName || section.prefix !== expected.prefix || section.sortOrder !== expected.sortOrder || - (current && - (!("category" in expected) || - section.category !== expected.category || - section.groupNumber !== expected.groupNumber)) + section.category !== expected.category || + section.groupNumber !== expected.groupNumber ) { throw new Error( "Distribution-board structure has invalid default sections." @@ -488,9 +329,7 @@ function assertDistributionBoardStructureSnapshotVersion( } } - if (current) { - assertDefaultComponents(components, circuitList.id); - } + assertDefaultComponents(components, circuitList.id); } function assertDefaultComponents( diff --git a/src/domain/models/distribution-board-subtree-snapshot.model.ts b/src/domain/models/distribution-board-subtree-snapshot.model.ts index ba55059..be896a0 100644 --- a/src/domain/models/distribution-board-subtree-snapshot.model.ts +++ b/src/domain/models/distribution-board-subtree-snapshot.model.ts @@ -156,7 +156,6 @@ export function cloneDistributionBoardSubtree( ...row, id: createId(), circuitId, - legacyConsumerId: null, })), protectionDevice: circuit.protectionDevice === null || diff --git a/src/domain/models/project-settings-project-command.model.ts b/src/domain/models/project-settings-project-command.model.ts index c14a3cd..37bb132 100644 --- a/src/domain/models/project-settings-project-command.model.ts +++ b/src/domain/models/project-settings-project-command.model.ts @@ -6,54 +6,29 @@ import { export const projectSettingsUpdateCommandType = "project.update-settings" as const; -export const legacyProjectSettingsUpdateCommandSchemaVersion = 1 as const; -export const previousProjectSettingsUpdateCommandSchemaVersion = 2 as const; -export const projectSettingsUpdateCommandSchemaVersion = 3 as const; +export const projectSettingsUpdateCommandSchemaVersion = 1 as const; -export interface LegacyProjectSettingsValues { - singlePhaseVoltageV: number; - threePhaseVoltageV: number; -} - -export interface PreviousProjectSettingsValues extends LegacyProjectSettingsValues { +export interface ProjectSettingsValues { name: string; internalProjectNumber: string | null; externalProjectNumber: string | null; buildingOwner: string | null; description: string | null; -} - -export interface ProjectSettingsValues extends PreviousProjectSettingsValues { + singlePhaseVoltageV: number; + threePhaseVoltageV: number; enabledDistributionBoardSupplyTypes: DistributionBoardSupplyType[]; } -export interface LegacyProjectSettingsUpdateProjectCommand - extends SerializedProjectCommand { - schemaVersion: typeof legacyProjectSettingsUpdateCommandSchemaVersion; - type: typeof projectSettingsUpdateCommandType; -} - -export interface CurrentProjectSettingsUpdateProjectCommand +export interface ProjectSettingsUpdateProjectCommand extends SerializedProjectCommand { schemaVersion: typeof projectSettingsUpdateCommandSchemaVersion; type: typeof projectSettingsUpdateCommandType; } -export interface PreviousProjectSettingsUpdateProjectCommand - extends SerializedProjectCommand { - schemaVersion: typeof previousProjectSettingsUpdateCommandSchemaVersion; - type: typeof projectSettingsUpdateCommandType; -} - -export type ProjectSettingsUpdateProjectCommand = - | LegacyProjectSettingsUpdateProjectCommand - | PreviousProjectSettingsUpdateProjectCommand - | CurrentProjectSettingsUpdateProjectCommand; - export function createProjectSettingsUpdateProjectCommand( values: ProjectSettingsValues -): CurrentProjectSettingsUpdateProjectCommand { - const command: CurrentProjectSettingsUpdateProjectCommand = { +): ProjectSettingsUpdateProjectCommand { + const command: ProjectSettingsUpdateProjectCommand = { schemaVersion: projectSettingsUpdateCommandSchemaVersion, type: projectSettingsUpdateCommandType, payload: { ...values }, @@ -67,11 +42,7 @@ export function assertProjectSettingsUpdateProjectCommand( ): asserts command is ProjectSettingsUpdateProjectCommand { if ( command.type !== projectSettingsUpdateCommandType || - (command.schemaVersion !== - legacyProjectSettingsUpdateCommandSchemaVersion && - command.schemaVersion !== - previousProjectSettingsUpdateCommandSchemaVersion && - command.schemaVersion !== projectSettingsUpdateCommandSchemaVersion) + command.schemaVersion !== projectSettingsUpdateCommandSchemaVersion ) { throw new Error("Unsupported project settings update command."); } @@ -80,14 +51,6 @@ export function assertProjectSettingsUpdateProjectCommand( "Project settings update command contains invalid values." ); } - if (command.schemaVersion === legacyProjectSettingsUpdateCommandSchemaVersion) { - assertLegacyValues(command.payload); - return; - } - const expectedKeyCount = - command.schemaVersion === previousProjectSettingsUpdateCommandSchemaVersion - ? 7 - : 8; if ( !isTrimmedString(command.payload.name, 1, 200) || !isNullableTrimmedString(command.payload.internalProjectNumber, 100) || @@ -96,14 +59,13 @@ export function assertProjectSettingsUpdateProjectCommand( !isNullableTrimmedString(command.payload.description, 2000) || !isPositiveFiniteNumber(command.payload.singlePhaseVoltageV) || !isPositiveFiniteNumber(command.payload.threePhaseVoltageV) || - Object.keys(command.payload).length !== expectedKeyCount + Object.keys(command.payload).length !== 8 ) { throw new Error( "Project settings update command contains invalid values." ); } if ( - command.schemaVersion === projectSettingsUpdateCommandSchemaVersion && !isValidSupplyTypes( command.payload.enabledDistributionBoardSupplyTypes ) @@ -114,28 +76,6 @@ export function assertProjectSettingsUpdateProjectCommand( } } -export function normalizeProjectSettingsValues( - command: ProjectSettingsUpdateProjectCommand, - current: ProjectSettingsValues -): ProjectSettingsValues { - if (command.schemaVersion === legacyProjectSettingsUpdateCommandSchemaVersion) { - return { - ...current, - ...command.payload, - }; - } - if ( - command.schemaVersion === previousProjectSettingsUpdateCommandSchemaVersion - ) { - return { - ...command.payload, - enabledDistributionBoardSupplyTypes: - current.enabledDistributionBoardSupplyTypes, - }; - } - return command.payload; -} - function isValidSupplyTypes( value: unknown ): value is DistributionBoardSupplyType[] { @@ -153,20 +93,6 @@ function isValidSupplyTypes( ); } -function assertLegacyValues( - payload: Record -): asserts payload is Record & LegacyProjectSettingsValues { - if ( - !isPositiveFiniteNumber(payload.singlePhaseVoltageV) || - !isPositiveFiniteNumber(payload.threePhaseVoltageV) || - Object.keys(payload).length !== 2 - ) { - throw new Error( - "Project settings update command contains invalid voltages." - ); - } -} - function isPositiveFiniteNumber(value: unknown): value is number { return ( typeof value === "number" && diff --git a/src/domain/models/project-state-snapshot.model.ts b/src/domain/models/project-state-snapshot.model.ts index 80eb6d1..53e2ed2 100644 --- a/src/domain/models/project-state-snapshot.model.ts +++ b/src/domain/models/project-state-snapshot.model.ts @@ -1,11 +1,7 @@ import { z } from "zod"; -import { - defaultDistributionBoardSupplyTypes, - distributionBoardSupplyTypes, -} from "../../shared/constants/distribution-board.js"; +import { distributionBoardSupplyTypes } from "../../shared/constants/distribution-board.js"; import { circuitGroupCategories, - type CircuitGroupCategory, } from "../../shared/constants/circuit-group.js"; import { distributionBoardComponentPlacements, @@ -21,61 +17,38 @@ import { import { resolveCircuitPhaseType, resolveProjectVoltage, - normalizeKnownElectricalPhaseType, } from "../services/project-voltage.service.js"; -export const legacyProjectStateSnapshotSchemaVersion = 1 as const; -export const previousProjectStateSnapshotSchemaVersion = 2 as const; -export const distributionBoardProjectStateSnapshotSchemaVersion = 3 as const; -export const supplyTypesProjectStateSnapshotSchemaVersion = 4 as const; -export const voltageProjectStateSnapshotSchemaVersion = 5 as const; -export const simultaneityFactorProjectStateSnapshotSchemaVersion = 6 as const; -export const projectStateSnapshotSchemaVersion = 7 as const; +export const projectStateSnapshotSchemaVersion = 1 as const; const idSchema = z.string().trim().min(1); const nullableStringSchema = z.string().nullable(); const finiteNumberSchema = z.number().finite(); -const legacyProjectSchema = z +const projectSchema = z .object({ id: idSchema, name: z.string().trim().min(1), + internalProjectNumber: z.string().trim().min(1).max(100).nullable(), + externalProjectNumber: z.string().trim().min(1).max(100).nullable(), + buildingOwner: z.string().trim().min(1).max(200).nullable(), + description: z.string().trim().min(1).max(2000).nullable(), singlePhaseVoltageV: finiteNumberSchema.positive(), threePhaseVoltageV: finiteNumberSchema.positive(), + enabledDistributionBoardSupplyTypes: z + .array(z.enum(distributionBoardSupplyTypes)) + .min(1) + .refine((values) => new Set(values).size === values.length), }) .strict(); -const projectSchema = legacyProjectSchema.extend({ - internalProjectNumber: z.string().trim().min(1).max(100).nullable(), - externalProjectNumber: z.string().trim().min(1).max(100).nullable(), - buildingOwner: z.string().trim().min(1).max(200).nullable(), - description: z.string().trim().min(1).max(2000).nullable(), -}); - -const currentProjectSchema = projectSchema.extend({ - enabledDistributionBoardSupplyTypes: z - .array(z.enum(distributionBoardSupplyTypes)) - .min(1) - .refine((values) => new Set(values).size === values.length), -}); - -const legacyDistributionBoardSchema = z +const distributionBoardSchema = z .object({ id: idSchema, projectId: idSchema, name: z.string().trim().min(1), - }) - .strict(); - -const distributionBoardSchema = legacyDistributionBoardSchema - .extend({ floorId: idSchema.nullable(), supplyType: z.enum(distributionBoardSupplyTypes).nullable(), - }) - .strict(); - -const currentDistributionBoardSchema = distributionBoardSchema - .extend({ simultaneityFactor: finiteNumberSchema.min(0).max(1), }) .strict(); @@ -89,7 +62,7 @@ const circuitListSchema = z }) .strict(); -const legacyCircuitSectionSchema = z +const circuitSectionSchema = z .object({ id: idSchema, circuitListId: idSchema, @@ -97,11 +70,6 @@ const legacyCircuitSectionSchema = z displayName: z.string().trim().min(1), prefix: z.string().trim().min(1), sortOrder: finiteNumberSchema, - }) - .strict(); - -const circuitSectionSchema = legacyCircuitSectionSchema - .extend({ category: z.enum(circuitGroupCategories).nullable(), groupNumber: z.number().int().positive().nullable(), }) @@ -121,11 +89,10 @@ const circuitDeviceRowSchema = z id: idSchema, circuitId: idSchema, linkedProjectDeviceId: idSchema.nullable(), - legacyConsumerId: z.string().nullable(), sortOrder: finiteNumberSchema, name: z.string().trim().min(1), displayName: z.string().trim().min(1), - phaseType: nullableStringSchema, + phaseType: z.enum(["single_phase", "three_phase"]).nullable(), connectionKind: nullableStringSchema, costGroup: nullableStringSchema, category: nullableStringSchema, @@ -150,9 +117,6 @@ const circuitSchema = z equipmentIdentifier: z.string().trim().min(1), displayName: nullableStringSchema, sortOrder: finiteNumberSchema, - protectionType: nullableStringSchema, - protectionRatedCurrent: finiteNumberSchema.nonnegative().nullable(), - protectionCharacteristic: nullableStringSchema, cableType: nullableStringSchema, cableCrossSection: nullableStringSchema, cableLength: finiteNumberSchema.nonnegative().nullable(), @@ -280,18 +244,13 @@ const componentProtectionDeviceSchema = z .strict() .superRefine(validatePersistedProtectionDevice); -const legacyProjectStateSnapshotContents = { +const projectStateSnapshotContents = { circuitLists: z.array(circuitListSchema), - circuitSections: z.array(legacyCircuitSectionSchema), + circuitSections: z.array(circuitSectionSchema), circuits: z.array(circuitSchema), projectDevices: z.array(projectDeviceSchema), floors: z.array(floorSchema), rooms: z.array(roomSchema), -}; - -const currentProjectStateSnapshotContents = { - ...legacyProjectStateSnapshotContents, - circuitSections: z.array(circuitSectionSchema), distributionBoardComponents: z.array(distributionBoardComponentSchema), circuitProtectionDevices: z.array(circuitProtectionDeviceSchema), distributionBoardComponentProtectionDevices: z.array( @@ -299,64 +258,14 @@ const currentProjectStateSnapshotContents = { ), }; -const legacyProjectStateSnapshotSchema = z +export const projectStateSnapshotSchema = z .object({ - schemaVersion: z.literal(legacyProjectStateSnapshotSchemaVersion), - project: legacyProjectSchema, - distributionBoards: z.array(legacyDistributionBoardSchema), - ...legacyProjectStateSnapshotContents, - }) - .strict(); - -const previousProjectStateSnapshotSchema = z - .object({ - schemaVersion: z.literal(previousProjectStateSnapshotSchemaVersion), - project: projectSchema, - distributionBoards: z.array(legacyDistributionBoardSchema), - ...legacyProjectStateSnapshotContents, - }) - .strict(); - -const distributionBoardProjectStateSnapshotSchema = z - .object({ - schemaVersion: z.literal( - distributionBoardProjectStateSnapshotSchemaVersion - ), - project: projectSchema, - distributionBoards: z.array(distributionBoardSchema), - ...legacyProjectStateSnapshotContents, - }) - .strict(); - -const supplyTypesProjectStateSnapshotSchema = z - .object({ - schemaVersion: z.literal(supplyTypesProjectStateSnapshotSchemaVersion), - project: currentProjectSchema, - distributionBoards: z.array(distributionBoardSchema), - ...legacyProjectStateSnapshotContents, - }) - .strict(); - -const voltageProjectStateSnapshotSchema = - supplyTypesProjectStateSnapshotSchema.extend({ - schemaVersion: z.literal( - voltageProjectStateSnapshotSchemaVersion - ), - }); - -const simultaneityFactorProjectStateSnapshotSchema = - voltageProjectStateSnapshotSchema.extend({ - schemaVersion: z.literal( - simultaneityFactorProjectStateSnapshotSchemaVersion - ), - distributionBoards: z.array(currentDistributionBoardSchema), - }); - -export const projectStateSnapshotSchema = - simultaneityFactorProjectStateSnapshotSchema.extend({ schemaVersion: z.literal(projectStateSnapshotSchemaVersion), - ...currentProjectStateSnapshotContents, - }); + project: projectSchema, + distributionBoards: z.array(distributionBoardSchema), + ...projectStateSnapshotContents, + }) + .strict(); export type ProjectStateSnapshot = z.infer< typeof projectStateSnapshotSchema @@ -365,68 +274,7 @@ export type ProjectStateSnapshot = z.infer< export function parseProjectStateSnapshot( value: unknown ): ProjectStateSnapshot { - const version = isPlainObject(value) ? value.schemaVersion : undefined; - const parsedSnapshot = - version === legacyProjectStateSnapshotSchemaVersion - ? upgradeSimultaneityFactorProjectStateSnapshot( - upgradeVoltageProjectStateSnapshot( - upgradeSupplyTypesProjectStateSnapshot( - upgradeDistributionBoardProjectStateSnapshot( - upgradePreviousProjectStateSnapshot( - upgradeLegacyProjectStateSnapshot( - legacyProjectStateSnapshotSchema.parse(value) - ) - ) - ) - ) - ) - ) - : version === previousProjectStateSnapshotSchemaVersion - ? upgradeSimultaneityFactorProjectStateSnapshot( - upgradeVoltageProjectStateSnapshot( - upgradeSupplyTypesProjectStateSnapshot( - upgradeDistributionBoardProjectStateSnapshot( - upgradePreviousProjectStateSnapshot( - previousProjectStateSnapshotSchema.parse(value) - ) - ) - ) - ) - ) - : version === distributionBoardProjectStateSnapshotSchemaVersion - ? upgradeSimultaneityFactorProjectStateSnapshot( - upgradeVoltageProjectStateSnapshot( - upgradeSupplyTypesProjectStateSnapshot( - upgradeDistributionBoardProjectStateSnapshot( - distributionBoardProjectStateSnapshotSchema.parse( - value - ) - ) - ) - ) - ) - : version === supplyTypesProjectStateSnapshotSchemaVersion - ? upgradeSimultaneityFactorProjectStateSnapshot( - upgradeVoltageProjectStateSnapshot( - upgradeSupplyTypesProjectStateSnapshot( - supplyTypesProjectStateSnapshotSchema.parse(value) - ) - ) - ) - : version === voltageProjectStateSnapshotSchemaVersion - ? upgradeSimultaneityFactorProjectStateSnapshot( - upgradeVoltageProjectStateSnapshot( - voltageProjectStateSnapshotSchema.parse(value) - ) - ) - : version === - simultaneityFactorProjectStateSnapshotSchemaVersion - ? upgradeSimultaneityFactorProjectStateSnapshot( - simultaneityFactorProjectStateSnapshotSchema.parse( - value - ) - ) - : projectStateSnapshotSchema.parse(value); + const parsedSnapshot = projectStateSnapshotSchema.parse(value); const snapshot = normalizeSnapshotPhaseTypes(parsedSnapshot); assertProjectStateSnapshotRelations(snapshot); return snapshot; @@ -446,15 +294,13 @@ function normalizeSnapshotPhaseTypes( circuits: snapshot.circuits.map((circuit) => { const section = sectionById.get(circuit.sectionId); const deviceRows = circuit.deviceRows.map((row) => { - const normalizedPhaseType = - normalizeKnownElectricalPhaseType(row.phaseType); const linkedPhaseType = row.linkedProjectDeviceId ? projectDeviceById.get(row.linkedProjectDeviceId)?.phaseType : undefined; return { ...row, phaseType: - normalizedPhaseType ?? + row.phaseType ?? linkedPhaseType ?? (section?.key === "three_phase" ? "three_phase" @@ -478,132 +324,6 @@ function normalizeSnapshotPhaseTypes( }; } -function upgradeLegacyProjectStateSnapshot( - snapshot: z.infer -): z.infer { - return { - ...snapshot, - schemaVersion: previousProjectStateSnapshotSchemaVersion, - project: { - ...snapshot.project, - internalProjectNumber: null, - externalProjectNumber: null, - buildingOwner: null, - description: null, - }, - }; -} - -function upgradePreviousProjectStateSnapshot( - snapshot: z.infer -): z.infer { - return { - ...snapshot, - schemaVersion: distributionBoardProjectStateSnapshotSchemaVersion, - distributionBoards: snapshot.distributionBoards.map((board) => ({ - ...board, - floorId: null, - supplyType: null, - })), - }; -} - -function upgradeDistributionBoardProjectStateSnapshot( - snapshot: z.infer -): z.infer { - return { - ...snapshot, - schemaVersion: supplyTypesProjectStateSnapshotSchemaVersion, - project: { - ...snapshot.project, - enabledDistributionBoardSupplyTypes: [ - ...defaultDistributionBoardSupplyTypes, - ], - }, - }; -} - -function upgradeSupplyTypesProjectStateSnapshot( - snapshot: z.infer -): z.infer { - const settings = snapshot.project; - const sectionById = new Map( - snapshot.circuitSections.map((section) => [section.id, section]) - ); - return { - ...snapshot, - schemaVersion: voltageProjectStateSnapshotSchemaVersion, - projectDevices: snapshot.projectDevices.map((device) => ({ - ...device, - voltageV: resolveProjectVoltage(device.phaseType, settings), - })), - circuits: snapshot.circuits.map((circuit) => { - const section = sectionById.get(circuit.sectionId); - if (!section) { - return circuit; - } - const phaseType = resolveCircuitPhaseType( - section.key, - circuit.deviceRows.map((row) => row.phaseType) - ); - return { - ...circuit, - voltage: resolveProjectVoltage(phaseType, settings), - }; - }), - }; -} - -function upgradeVoltageProjectStateSnapshot( - snapshot: z.infer -): z.infer { - return { - ...snapshot, - schemaVersion: simultaneityFactorProjectStateSnapshotSchemaVersion, - distributionBoards: snapshot.distributionBoards.map((board) => ({ - ...board, - simultaneityFactor: 1, - })), - }; -} - -function upgradeSimultaneityFactorProjectStateSnapshot( - snapshot: z.infer -): ProjectStateSnapshot { - return { - ...snapshot, - schemaVersion: projectStateSnapshotSchemaVersion, - circuitSections: snapshot.circuitSections.map((section) => { - const category = initialCategoryBySectionKey(section.key); - return { - ...section, - category, - groupNumber: category === null ? null : 1, - }; - }), - distributionBoardComponents: [], - circuitProtectionDevices: [], - distributionBoardComponentProtectionDevices: [], - }; -} - -function initialCategoryBySectionKey( - key: string -): CircuitGroupCategory | null { - if ( - key === "lighting" || - key === "single_phase" || - key === "three_phase" - ) { - return key; - } - return null; -} - -function isPlainObject(value: unknown): value is Record { - return value !== null && typeof value === "object" && !Array.isArray(value); -} - export function serializeProjectStateSnapshot( snapshot: ProjectStateSnapshot ): string { diff --git a/src/domain/models/project-transfer.model.ts b/src/domain/models/project-transfer.model.ts index c6de1f7..47c8804 100644 --- a/src/domain/models/project-transfer.model.ts +++ b/src/domain/models/project-transfer.model.ts @@ -156,7 +156,6 @@ export function remapProjectState( row.linkedProjectDeviceId === null ? null : requiredId(deviceIds, row.linkedProjectDeviceId), - legacyConsumerId: null, roomId: row.roomId === null ? null : requiredId(roomIds, row.roomId), })), diff --git a/src/domain/ports/legacy-consumer-migration.store.ts b/src/domain/ports/legacy-consumer-migration.store.ts deleted file mode 100644 index 13d0904..0000000 --- a/src/domain/ports/legacy-consumer-migration.store.ts +++ /dev/null @@ -1,143 +0,0 @@ -export interface LegacyConsumerMigrationCircuitListReader { - findById( - projectId: string, - circuitListId: string - ): Promise<{ id: string } | null>; -} - -export interface LegacyConsumerMigrationSection { - id: string; - key: string; - prefix: string; -} - -export interface LegacyConsumerMigrationSectionStore { - createDefaults(circuitListId: string): Promise; - listByCircuitList( - circuitListId: string - ): Promise; -} - -export interface LegacyConsumerMigrationCircuitReader { - listByCircuitList(circuitListId: string): Promise< - Array<{ - sectionId: string; - equipmentIdentifier: string; - sortOrder: number; - }> - >; -} - -export interface LegacyConsumerMigrationRoomReader { - listByProject(projectId: string): Promise< - Array<{ - id: string; - roomNumber: string; - roomName: string; - }> - >; -} - -export interface LegacyConsumerSource { - id: string; - projectDeviceId: string | null; - roomId: string | null; - circuitNumber: string | null; - description: string | null; - name: string; - category: string | null; - deviceType: string | null; - phaseType: string | null; - tradeOrCostGroup: string | null; - protectionType: string | null; - protectionRatedCurrent: number | null; - protectionCharacteristic: string | null; - cableType: string | null; - cableCrossSection: string | null; - comment: string | null; - quantity: number; - installedPowerPerUnitKw: number; - demandFactor: number; - voltageV: number | null; - phaseCount: number | null; - powerFactor: number | null; - note: string | null; -} - -export interface LegacyMigrationDeviceRowInput { - linkedProjectDeviceId?: string; - legacyConsumerId: string; - sortOrder: number; - name: string; - displayName: string; - phaseType?: string; - connectionKind?: string; - costGroup?: string; - category?: string; - level?: string; - roomId?: string; - roomNumberSnapshot?: string; - roomNameSnapshot?: string; - quantity: number; - powerPerUnit: number; - simultaneityFactor: number; - cosPhi?: number; - remark?: string; - overriddenFields?: string; -} - -export interface LegacyMigrationCircuitInput { - circuit: { - circuitListId: string; - sectionId: string; - equipmentIdentifier: string; - displayName?: string; - sortOrder: number; - protectionType?: string; - protectionRatedCurrent?: number; - protectionCharacteristic?: string; - cableType?: string; - cableCrossSection?: string; - cableLength?: number; - voltage?: number; - controlRequirement?: string; - remark?: string; - rcdAssignment?: string; - terminalDesignation?: string; - status?: string; - isReserve?: boolean; - }; - deviceRows: LegacyMigrationDeviceRowInput[]; -} - -export interface LegacyMigrationReportInput { - legacyConsumerCount: number; - createdCircuitCount: number; - createdDeviceRowCount: number; - duplicateGroupedCount: number; - generatedIdentifierCount: number; - unassignedRowCount: number; - warningsJson: string; - generatedIdentifiersJson: string; - duplicateGroupsJson: string; -} - -export interface LegacyConsumerMigrationStore { - listSourceConsumersByCircuitList( - circuitListId: string - ): Promise; - listMigratedConsumerIds(circuitListId: string): Promise; - persistCircuitListMigration(input: { - circuitListId: string; - circuits: LegacyMigrationCircuitInput[]; - report: LegacyMigrationReportInput; - }): void; -} - -export interface LegacyConsumerMigrationDependencies { - circuitListReader: LegacyConsumerMigrationCircuitListReader; - sectionStore: LegacyConsumerMigrationSectionStore; - circuitReader: LegacyConsumerMigrationCircuitReader; - roomReader: LegacyConsumerMigrationRoomReader; - migrationStore: LegacyConsumerMigrationStore; -} diff --git a/src/domain/services/legacy-consumer-migration-planner.ts b/src/domain/services/legacy-consumer-migration-planner.ts deleted file mode 100644 index fce7cbb..0000000 --- a/src/domain/services/legacy-consumer-migration-planner.ts +++ /dev/null @@ -1,60 +0,0 @@ -export interface LegacyConsumerForPlanning { - id: string; - circuitNumber: string | null; - category: string | null; - phaseType: string | null; - phaseCount: number | null; -} - -// Accepts only normalized BMK-like legacy circuit numbers used for grouping. -export function normalizeCircuitNumber(value: string | null): string | null { - if (!value) { - return null; - } - const trimmed = value.trim().toUpperCase(); - if (!trimmed) { - return null; - } - if (!/^-\d+F\d+$/.test(trimmed)) { - return null; - } - return trimmed; -} - -// Best-effort fallback when no valid circuit number exists. Keeps migration deterministic -// by preferring explicit category/phase cues over random assignment. -export function inferSectionKeyFromLegacyInput(consumer: LegacyConsumerForPlanning): string | null { - const category = (consumer.category ?? "").toLowerCase(); - if (category.includes("light") || category.includes("beleuchtung")) { - return "lighting"; - } - if (consumer.phaseCount === 3) { - return "three_phase"; - } - if (consumer.phaseCount === 1) { - return "single_phase"; - } - - const phaseType = (consumer.phaseType ?? "").toLowerCase(); - if (phaseType.includes("three") || phaseType.includes("3")) { - return "three_phase"; - } - if (phaseType.includes("single") || phaseType.includes("1")) { - return "single_phase"; - } - return null; -} - -// Prefix-based section inference for already normalized equipment identifiers. -export function inferSectionKeyFromEquipmentIdentifier(equipmentIdentifier: string): string | null { - if (equipmentIdentifier.startsWith("-1F")) { - return "lighting"; - } - if (equipmentIdentifier.startsWith("-2F")) { - return "single_phase"; - } - if (equipmentIdentifier.startsWith("-3F")) { - return "three_phase"; - } - return null; -} diff --git a/src/domain/services/legacy-consumer-migration.service.ts b/src/domain/services/legacy-consumer-migration.service.ts deleted file mode 100644 index c717d00..0000000 --- a/src/domain/services/legacy-consumer-migration.service.ts +++ /dev/null @@ -1,269 +0,0 @@ -import type { LegacyMigrationReport } from "../models/circuit-tree.model.js"; -import type { - LegacyConsumerMigrationDependencies, - LegacyConsumerSource, - LegacyMigrationCircuitInput, -} from "../ports/legacy-consumer-migration.store.js"; -import { - inferSectionKeyFromEquipmentIdentifier, - inferSectionKeyFromLegacyInput, - normalizeCircuitNumber, -} from "./legacy-consumer-migration-planner.js"; - -function parseEquipmentSequence( - equipmentIdentifier: string, - prefix: string -): number | null { - if (!equipmentIdentifier.startsWith(prefix)) { - return null; - } - const suffix = equipmentIdentifier.slice(prefix.length); - if (!/^\d+$/.test(suffix)) { - return null; - } - return Number(suffix); -} - -export class LegacyConsumerMigrationService { - constructor( - private readonly dependencies: LegacyConsumerMigrationDependencies - ) {} - - async migrateCircuitList( - projectId: string, - circuitListId: string - ): Promise { - // Migration is additive: legacy consumers are preserved, and circuit-first entities are created - // with mapping records so transition remains auditable and reversible. - const list = await this.dependencies.circuitListReader.findById( - projectId, - circuitListId - ); - if (!list) { - throw new Error("Circuit list not found in project."); - } - - await this.dependencies.sectionStore.createDefaults(circuitListId); - const sections = - await this.dependencies.sectionStore.listByCircuitList(circuitListId); - const sectionByKey = new Map(sections.map((section) => [section.key, section])); - const unassignedSection = sectionByKey.get("unassigned"); - if (!unassignedSection) { - throw new Error("Unassigned section is required."); - } - - const existingCircuits = - await this.dependencies.circuitReader.listByCircuitList(circuitListId); - const usedEquipmentIdentifiers = new Set( - existingCircuits.map((circuit) => circuit.equipmentIdentifier.toUpperCase()) - ); - - const legacyConsumers = - await this.dependencies.migrationStore.listSourceConsumersByCircuitList( - circuitListId - ); - const rooms = await this.dependencies.roomReader.listByProject(projectId); - const roomById = new Map(rooms.map((room) => [room.id, room])); - - const report: LegacyMigrationReport = { - circuitListId, - legacyConsumerCount: legacyConsumers.length, - createdCircuitCount: 0, - createdDeviceRowCount: 0, - groupedDuplicateCircuitNumbers: [], - generatedIdentifiers: [], - unassignedRows: [], - warnings: [], - }; - - // Idempotency guard: skip consumers already mapped in previous migration run. - const migratedConsumerIds = new Set( - await this.dependencies.migrationStore.listMigratedConsumerIds( - circuitListId - ) - ); - const consumersToMigrate = legacyConsumers.filter((consumer) => !migratedConsumerIds.has(consumer.id)); - - // Legacy rows are grouped by normalized circuit number so duplicates become - // multiple device rows within one circuit instead of duplicate circuits. - const byNormalizedCircuitNumber = new Map(); - const withoutNormalizedCircuitNumber: LegacyConsumerSource[] = []; - for (const consumer of consumersToMigrate) { - const normalized = normalizeCircuitNumber(consumer.circuitNumber ?? null); - if (!normalized) { - withoutNormalizedCircuitNumber.push(consumer); - continue; - } - if (!byNormalizedCircuitNumber.has(normalized)) { - byNormalizedCircuitNumber.set(normalized, []); - } - byNormalizedCircuitNumber.get(normalized)!.push(consumer); - } - - // Duplicate normalized circuit numbers are expected and represented as one circuit - // with multiple circuit_device_rows. - report.groupedDuplicateCircuitNumbers = [...byNormalizedCircuitNumber.entries()] - .filter(([, grouped]) => grouped.length > 1) - .map(([normalizedCircuitNumber, grouped]) => ({ normalizedCircuitNumber, count: grouped.length })); - - const groups: Array<{ - equipmentIdentifier: string | null; - consumers: LegacyConsumerSource[]; - inferredSectionKey: string | null; - isGeneratedIdentifier: boolean; - }> = []; - - // Stable normalized circuit numbers keep existing intent where available. - for (const [normalizedCircuitNumber, grouped] of byNormalizedCircuitNumber.entries()) { - groups.push({ - equipmentIdentifier: normalizedCircuitNumber, - consumers: grouped, - inferredSectionKey: inferSectionKeyFromEquipmentIdentifier(normalizedCircuitNumber), - isGeneratedIdentifier: false, - }); - } - - // Missing/invalid circuit numbers are migrated as single-row groups with - // generated identifiers and best-effort section inference. - for (const consumer of withoutNormalizedCircuitNumber) { - groups.push({ - equipmentIdentifier: null, - consumers: [consumer], - inferredSectionKey: inferSectionKeyFromLegacyInput(consumer), - isGeneratedIdentifier: true, - }); - } - - let nextSortOrder = existingCircuits.length ? Math.max(...existingCircuits.map((circuit) => circuit.sortOrder)) + 10 : 10; - - const maxBySectionPrefix = new Map(); - for (const circuit of existingCircuits) { - const section = sections.find((entry) => entry.id === circuit.sectionId); - if (!section) { - continue; - } - const sequence = parseEquipmentSequence(circuit.equipmentIdentifier.toUpperCase(), section.prefix.toUpperCase()); - if (sequence === null) { - continue; - } - const current = maxBySectionPrefix.get(section.prefix.toUpperCase()) ?? 0; - maxBySectionPrefix.set(section.prefix.toUpperCase(), Math.max(current, sequence)); - } - - const migrationCircuits: LegacyMigrationCircuitInput[] = []; - for (const group of groups) { - const representative = group.consumers[0]; - let section = group.inferredSectionKey ? sectionByKey.get(group.inferredSectionKey) : null; - if (!section) { - section = unassignedSection; - } - - let equipmentIdentifier = group.equipmentIdentifier; - if (!equipmentIdentifier || usedEquipmentIdentifiers.has(equipmentIdentifier.toUpperCase())) { - const prefix = section.prefix.toUpperCase(); - const current = maxBySectionPrefix.get(prefix) ?? 0; - const generatedSequence = current + 1; - maxBySectionPrefix.set(prefix, generatedSequence); - equipmentIdentifier = `${section.prefix}${generatedSequence}`; - report.generatedIdentifiers.push(equipmentIdentifier); - } - - if (!group.inferredSectionKey && group.isGeneratedIdentifier) { - for (const consumer of group.consumers) { - report.unassignedRows.push({ - consumerId: consumer.id, - reason: "Missing or invalid circuit number and no section inferred from phase/category.", - }); - } - } - - usedEquipmentIdentifiers.add(equipmentIdentifier.toUpperCase()); - - const deviceRows: LegacyMigrationCircuitInput["deviceRows"] = []; - const circuitSortOrder = nextSortOrder; - nextSortOrder += 10; - - let rowSortOrder = 10; - for (const consumer of group.consumers) { - const room = consumer.roomId ? roomById.get(consumer.roomId) : undefined; - let noteRemark = consumer.note?.trim() || consumer.comment?.trim() || undefined; - if (consumer.deviceType && consumer.deviceType.trim()) { - const legacyDeviceTypeNote = `Legacy deviceType: ${consumer.deviceType.trim()}`; - noteRemark = noteRemark ? `${noteRemark} | ${legacyDeviceTypeNote}` : legacyDeviceTypeNote; - } - - deviceRows.push({ - linkedProjectDeviceId: consumer.projectDeviceId ?? undefined, - legacyConsumerId: consumer.id, - sortOrder: rowSortOrder, - name: consumer.name, - displayName: consumer.description ?? consumer.name, - phaseType: consumer.phaseType ?? undefined, - connectionKind: undefined, - costGroup: consumer.tradeOrCostGroup ?? undefined, - category: consumer.category ?? undefined, - roomId: consumer.roomId ?? undefined, - roomNumberSnapshot: room?.roomNumber, - roomNameSnapshot: room?.roomName, - quantity: consumer.quantity, - powerPerUnit: consumer.installedPowerPerUnitKw, - simultaneityFactor: consumer.demandFactor, - cosPhi: consumer.powerFactor ?? undefined, - remark: noteRemark, - }); - rowSortOrder += 10; - } - - migrationCircuits.push({ - circuit: { - circuitListId, - sectionId: section.id, - equipmentIdentifier, - displayName: representative.description ?? representative.name, - sortOrder: circuitSortOrder, - protectionType: representative.protectionType ?? undefined, - protectionRatedCurrent: representative.protectionRatedCurrent ?? undefined, - protectionCharacteristic: representative.protectionCharacteristic ?? undefined, - cableType: representative.cableType ?? undefined, - cableCrossSection: representative.cableCrossSection ?? undefined, - voltage: representative.voltageV ?? undefined, - remark: undefined, - }, - deviceRows, - }); - } - report.createdCircuitCount = migrationCircuits.length; - report.createdDeviceRowCount = migrationCircuits.reduce( - (count, entry) => count + entry.deviceRows.length, - 0 - ); - - if (consumersToMigrate.some((consumer) => Boolean(consumer.comment?.trim()))) { - report.warnings.push( - "Legacy comment field was mapped to circuit_device_rows.remark because circuit-level vs row-level intent is ambiguous." - ); - } - - for (const row of report.unassignedRows) { - report.warnings.push(`Consumer ${row.consumerId} was migrated into unassigned section.`); - } - - this.dependencies.migrationStore.persistCircuitListMigration({ - circuitListId, - circuits: migrationCircuits, - report: { - legacyConsumerCount: report.legacyConsumerCount, - createdCircuitCount: report.createdCircuitCount, - createdDeviceRowCount: report.createdDeviceRowCount, - duplicateGroupedCount: report.groupedDuplicateCircuitNumbers.length, - generatedIdentifierCount: report.generatedIdentifiers.length, - unassignedRowCount: report.unassignedRows.length, - warningsJson: JSON.stringify(report.warnings), - generatedIdentifiersJson: JSON.stringify(report.generatedIdentifiers), - duplicateGroupsJson: JSON.stringify(report.groupedDuplicateCircuitNumbers), - }, - }); - - return report; - } -} diff --git a/src/domain/services/project-voltage.service.ts b/src/domain/services/project-voltage.service.ts index 0bb10d0..d0687e0 100644 --- a/src/domain/services/project-voltage.service.ts +++ b/src/domain/services/project-voltage.service.ts @@ -6,34 +6,6 @@ export function isElectricalPhaseType( return value === "single_phase" || value === "three_phase"; } -export function normalizeKnownElectricalPhaseType( - value: string | null -): ElectricalPhaseType | null { - if (value === null) { - return null; - } - const normalized = value - .trim() - .toLocaleLowerCase("de-DE") - .replaceAll("-", "") - .replaceAll("_", ""); - if ( - ["1ph", "1phase", "1phasig", "einphasig", "singlephase"].includes( - normalized - ) - ) { - return "single_phase"; - } - if ( - ["3ph", "3phase", "3phasig", "dreiphasig", "threephase"].includes( - normalized - ) - ) { - return "three_phase"; - } - throw new Error(`Unknown electrical phase type: ${value}`); -} - export interface ProjectVoltageSettings { singlePhaseVoltageV: number; threePhaseVoltageV: number; diff --git a/src/frontend/components/circuit-tree-editor.tsx b/src/frontend/components/circuit-tree-editor.tsx index fdb6f5e..b214d60 100644 --- a/src/frontend/components/circuit-tree-editor.tsx +++ b/src/frontend/components/circuit-tree-editor.tsx @@ -30,10 +30,8 @@ import { formatPhaseTypeLabel, formatValue, getCircuitSectionLabel, - getLegacyProjectColumnLayoutStorageKey, getProjectColumnLayoutStorageKey, isGridEditorControlTarget, - migrateLegacyColumnLayout, normalizeColumnOrder, parseStoredColumnLayout, } from "../utils/circuit-grid-model"; @@ -191,9 +189,6 @@ type CircuitReorderDropIntent = | { kind: "after-circuit"; sectionId: string; targetCircuitId: string; valid: boolean } | { kind: "section-end"; sectionId: string; valid: boolean }; -const LEGACY_COLUMN_LAYOUT_STORAGE_KEY = - "circuitTreeEditor.columnLayout.v1"; - function normalizeUiError(err: unknown): string { const message = err instanceof Error ? err.message : "Der Vorgang ist fehlgeschlagen."; try { @@ -379,25 +374,11 @@ export function CircuitTreeEditor(props: { projectId: string; circuitListId: str const currentLayout = parseStoredColumnLayout( localStorage.getItem(getProjectColumnLayoutStorageKey(projectId)) ); - const legacyLayout = - parseStoredColumnLayout( - localStorage.getItem( - getLegacyProjectColumnLayoutStorageKey(projectId) - ) - ) ?? - parseStoredColumnLayout( - localStorage.getItem(LEGACY_COLUMN_LAYOUT_STORAGE_KEY) - ); - const parsed = - currentLayout ?? - (legacyLayout - ? migrateLegacyColumnLayout(legacyLayout) - : null); - if (!parsed) { + if (!currentLayout) { return; } - setColumnOrder(parsed.order); - setVisibleColumnKeys(parsed.visible); + setColumnOrder(currentLayout.order); + setVisibleColumnKeys(currentLayout.visible); } catch { // ignore invalid local storage and use defaults } finally { diff --git a/src/frontend/components/circuit-tree-preview.tsx b/src/frontend/components/circuit-tree-preview.tsx index 2e5a5d2..cd93739 100644 --- a/src/frontend/components/circuit-tree-preview.tsx +++ b/src/frontend/components/circuit-tree-preview.tsx @@ -114,11 +114,11 @@ function SectionRows(props: { section: CircuitTreeResponseDto["sections"][number {formatValue(circuit.circuitTotalPower, "circuitTotalPower")} - {circuit.protectionType ?? "-"} + {circuit.protectionDevice?.type ?? "-"} - {formatValue(circuit.protectionRatedCurrent, "protectionRatedCurrent")} + {formatValue(circuit.protectionDevice?.ratedCurrentA, "protectionRatedCurrent")} - {circuit.protectionCharacteristic ?? "-"} + {circuit.protectionDevice?.tripCharacteristic ?? circuit.protectionDevice?.fuseUtilizationCategory ?? "-"} {circuit.cableType ?? "-"} {circuit.cableCrossSection ?? "-"} {formatValue(circuit.cableLength, "cableLength")} @@ -147,11 +147,11 @@ function SectionRows(props: { section: CircuitTreeResponseDto["sections"][number {formatValue(row.cosPhi, "cosPhi")} {formatValue(row.rowTotalPower, "rowTotalPower")} - {circuit.protectionType ?? "-"} + {circuit.protectionDevice?.type ?? "-"} - {formatValue(circuit.protectionRatedCurrent, "protectionRatedCurrent")} + {formatValue(circuit.protectionDevice?.ratedCurrentA, "protectionRatedCurrent")} - {circuit.protectionCharacteristic ?? "-"} + {circuit.protectionDevice?.tripCharacteristic ?? circuit.protectionDevice?.fuseUtilizationCategory ?? "-"} {circuit.cableType ?? "-"} {circuit.cableCrossSection ?? "-"} {formatValue(circuit.cableLength, "cableLength")} @@ -169,11 +169,11 @@ function SectionRows(props: { section: CircuitTreeResponseDto["sections"][number {formatValue(circuit.circuitTotalPower, "circuitTotalPower")} - {circuit.protectionType ?? "-"} + {circuit.protectionDevice?.type ?? "-"} - {formatValue(circuit.protectionRatedCurrent, "protectionRatedCurrent")} + {formatValue(circuit.protectionDevice?.ratedCurrentA, "protectionRatedCurrent")} - {circuit.protectionCharacteristic ?? "-"} + {circuit.protectionDevice?.tripCharacteristic ?? circuit.protectionDevice?.fuseUtilizationCategory ?? "-"} {circuit.cableType ?? "-"} {circuit.cableCrossSection ?? "-"} {formatValue(circuit.cableLength, "cableLength")} diff --git a/src/frontend/types.ts b/src/frontend/types.ts index 71c832f..ee58d0d 100644 --- a/src/frontend/types.ts +++ b/src/frontend/types.ts @@ -267,7 +267,6 @@ export interface ProjectDeviceSyncCommandResultDto export interface CircuitTreeDeviceRowDto { id: string; linkedProjectDeviceId?: string; - legacyConsumerId?: string; sortOrder: number; name: string; displayName: string; @@ -316,9 +315,6 @@ export interface CircuitTreeCircuitDto { equipmentIdentifier: string; displayName?: string; sortOrder: number; - protectionType?: string; - protectionRatedCurrent?: number; - protectionCharacteristic?: string; cableType?: string; cableCrossSection?: string; cableLength?: number; @@ -347,17 +343,6 @@ export interface CircuitTreeSectionDto { circuits: CircuitTreeCircuitDto[]; } -export interface CircuitTreeMigrationReportDto { - circuitListId: string; - legacyConsumerCount: number; - createdCircuitCount: number; - createdDeviceRowCount: number; - groupedDuplicateCircuitNumbers: Array<{ normalizedCircuitNumber: string; count: number }>; - generatedIdentifiers: string[]; - unassignedRows: Array<{ consumerId: string; reason: string }>; - warnings: string[]; -} - export interface CircuitTreeResponseDto { circuitListId: string; currentRevision: number; @@ -369,7 +354,6 @@ export interface CircuitTreeResponseDto { headerComponents: CircuitTreeComponentDto[]; sections: CircuitTreeSectionDto[]; footerComponents: CircuitTreeComponentDto[]; - migrationReport?: CircuitTreeMigrationReportDto; } export interface CreateCircuitInputDto { @@ -377,9 +361,6 @@ export interface CreateCircuitInputDto { equipmentIdentifier: string; displayName?: string; sortOrder: number; - protectionType?: string; - protectionRatedCurrent?: number; - protectionCharacteristic?: string; cableType?: string; cableCrossSection?: string; cableLength?: number; diff --git a/src/frontend/utils/circuit-grid-model.ts b/src/frontend/utils/circuit-grid-model.ts index 880dbe9..47e7189 100644 --- a/src/frontend/utils/circuit-grid-model.ts +++ b/src/frontend/utils/circuit-grid-model.ts @@ -130,8 +130,6 @@ export const defaultVisibleColumnKeys = allColumns const projectColumnLayoutStoragePrefix = "circuitTreeEditor.columnLayout.v3"; -const legacyProjectColumnLayoutStoragePrefix = - "circuitTreeEditor.columnLayout.v2"; export interface CircuitColumnLayout { order: CellKey[]; @@ -164,12 +162,6 @@ export function getProjectColumnLayoutStorageKey( return `${projectColumnLayoutStoragePrefix}.${projectId}`; } -export function getLegacyProjectColumnLayoutStorageKey( - projectId: string -): string { - return `${legacyProjectColumnLayoutStoragePrefix}.${projectId}`; -} - export function normalizeColumnOrder(keys: CellKey[]): CellKey[] { const unique = [...new Set(keys)]; const allKeys = allColumns.map((column) => column.key); @@ -233,28 +225,6 @@ export function parseStoredColumnLayout( } } -export function migrateLegacyColumnLayout( - layout: CircuitColumnLayout -): CircuitColumnLayout { - const newlyVisibleKey: CellKey = "protectionSummary"; - const order = layout.order.filter( - (key) => key !== newlyVisibleKey - ) as CellKey[]; - const totalPowerIndex = order.indexOf("rowTotalPower"); - order.splice( - totalPowerIndex >= 0 ? totalPowerIndex + 1 : order.length, - 0, - newlyVisibleKey - ); - - return { - order, - visible: layout.visible.includes(newlyVisibleKey) - ? layout.visible - : [...layout.visible, newlyVisibleKey], - }; -} - const deviceOnlyColumns = new Set([ "quantity", "powerPerUnit", @@ -422,11 +392,7 @@ export function buildCircuitEditPatch( if (key === "protectionSummary" || key === "cableSummary") { return { remark: draft.trim() || null }; } - if ( - key === "protectionRatedCurrent" || - key === "cableLength" || - key === "voltage" - ) { + if (key === "cableLength" || key === "voltage") { return { [key]: parseNumeric(key, draft) ?? null }; } if (key === "isReserve") { @@ -530,23 +496,14 @@ export function getCircuitValue(circuit: CircuitTreeCircuitDto, key: CellKey): G case "protectionType": return protection ? protectionDeviceTypeLabels[protection.type] - : circuit.protectionType; + : undefined; case "protectionRatedCurrent": - return protection?.ratedCurrentA ?? circuit.protectionRatedCurrent; + return protection?.ratedCurrentA; case "protectionCharacteristic": - return protectionCharacteristic || circuit.protectionCharacteristic; + return protectionCharacteristic || undefined; case "protectionSummary": { if (!protection) { - const legacyCurrent = - circuit.protectionRatedCurrent !== undefined && - circuit.protectionRatedCurrent !== null - ? `${circuit.protectionRatedCurrent}A` - : ""; - return [ - circuit.protectionType, - legacyCurrent, - circuit.protectionCharacteristic, - ].filter(Boolean).join(" ").trim() || undefined; + return undefined; } const currentValue = protection.ratedCurrentA; diff --git a/src/frontend/utils/circuit-group-editing.ts b/src/frontend/utils/circuit-group-editing.ts index af28ee3..a8ed14d 100644 --- a/src/frontend/utils/circuit-group-editing.ts +++ b/src/frontend/utils/circuit-group-editing.ts @@ -117,11 +117,6 @@ export function buildCircuitGroupSubtreeSnapshot( equipmentIdentifier: circuit.equipmentIdentifier, displayName: circuit.displayName ?? null, sortOrder: circuit.sortOrder, - protectionType: circuit.protectionType ?? null, - protectionRatedCurrent: - circuit.protectionRatedCurrent ?? null, - protectionCharacteristic: - circuit.protectionCharacteristic ?? null, cableType: circuit.cableType ?? null, cableCrossSection: circuit.cableCrossSection ?? null, cableLength: circuit.cableLength ?? null, @@ -143,7 +138,6 @@ export function buildCircuitGroupSubtreeSnapshot( circuitId: circuit.id, linkedProjectDeviceId: row.linkedProjectDeviceId ?? null, - legacyConsumerId: row.legacyConsumerId ?? null, sortOrder: row.sortOrder, name: row.name, displayName: row.displayName, diff --git a/src/frontend/utils/circuit-structure-command.ts b/src/frontend/utils/circuit-structure-command.ts index 9113d15..582dcd8 100644 --- a/src/frontend/utils/circuit-structure-command.ts +++ b/src/frontend/utils/circuit-structure-command.ts @@ -22,7 +22,6 @@ export function buildCircuitDeviceRowInsertSnapshot(input: { id, circuitId, linkedProjectDeviceId: values.linkedProjectDeviceId ?? null, - legacyConsumerId: null, sortOrder: values.sortOrder ?? defaultSortOrder, name: values.name, displayName: values.displayName, @@ -61,9 +60,6 @@ export function buildCircuitInsertSnapshot(input: { equipmentIdentifier: values.equipmentIdentifier, displayName: values.displayName ?? null, sortOrder: values.sortOrder, - protectionType: values.protectionType ?? null, - protectionRatedCurrent: values.protectionRatedCurrent ?? null, - protectionCharacteristic: values.protectionCharacteristic ?? null, cableType: values.cableType ?? null, cableCrossSection: values.cableCrossSection ?? null, cableLength: values.cableLength ?? null, diff --git a/src/server/controllers/circuit-tree.controller.ts b/src/server/controllers/circuit-tree.controller.ts index 4957e2e..b7f0e0b 100644 --- a/src/server/controllers/circuit-tree.controller.ts +++ b/src/server/controllers/circuit-tree.controller.ts @@ -148,7 +148,6 @@ export async function getCircuitTree(req: Request, res: Response) { const deviceRows = (rowsByCircuitId.get(circuit.id) ?? []).map((row) => ({ id: row.id, linkedProjectDeviceId: row.linkedProjectDeviceId ?? undefined, - legacyConsumerId: row.legacyConsumerId ?? undefined, sortOrder: row.sortOrder, name: row.name, displayName: row.displayName, @@ -178,9 +177,6 @@ export async function getCircuitTree(req: Request, res: Response) { equipmentIdentifier: circuit.equipmentIdentifier, displayName: circuit.displayName ?? undefined, sortOrder: circuit.sortOrder, - protectionType: circuit.protectionType ?? undefined, - protectionRatedCurrent: circuit.protectionRatedCurrent ?? undefined, - protectionCharacteristic: circuit.protectionCharacteristic ?? undefined, cableType: circuit.cableType ?? undefined, cableCrossSection: circuit.cableCrossSection ?? undefined, cableLength: circuit.cableLength ?? undefined, diff --git a/tests/circuit-device-row-move-project-command.repository.test.ts b/tests/circuit-device-row-move-project-command.repository.test.ts index 448914f..0569099 100644 --- a/tests/circuit-device-row-move-project-command.repository.test.ts +++ b/tests/circuit-device-row-move-project-command.repository.test.ts @@ -180,9 +180,6 @@ function createMoveTargetSnapshot( equipmentIdentifier: "-1F4", displayName: "Neuer Stromkreis", sortOrder: 40, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: null, cableCrossSection: null, cableLength: null, diff --git a/tests/circuit-device-row-structure-project-command.repository.test.ts b/tests/circuit-device-row-structure-project-command.repository.test.ts index c16c6ed..318ef02 100644 --- a/tests/circuit-device-row-structure-project-command.repository.test.ts +++ b/tests/circuit-device-row-structure-project-command.repository.test.ts @@ -133,7 +133,6 @@ function createTestDatabase(): DatabaseContext { id: "row-1", circuitId: "circuit-1", linkedProjectDeviceId: "device-1", - legacyConsumerId: "legacy-1", sortOrder: 10, name: "Leuchte", displayName: "Leuchte lokal", @@ -163,7 +162,6 @@ function createInsertSnapshot( id: "row-new", circuitId: "circuit-reserve", linkedProjectDeviceId: "device-1", - legacyConsumerId: null, sortOrder: 10, name: "Steckdose", displayName: "Steckdose lokal", @@ -423,10 +421,6 @@ describe("circuit device-row structure project-command repository", () => { roomId: "room-foreign", }), createInsertSnapshot({ id: "row-1" }), - createInsertSnapshot({ - id: "row-legacy", - legacyConsumerId: "legacy-user-value", - }), ]) { assert.throws(() => store.execute({ diff --git a/tests/circuit-grid-model.test.ts b/tests/circuit-grid-model.test.ts index b0472b8..6dbfef8 100644 --- a/tests/circuit-grid-model.test.ts +++ b/tests/circuit-grid-model.test.ts @@ -6,14 +6,12 @@ import { buildDeviceRowEditPatch, formatValue, getCircuitSectionLabel, - getLegacyProjectColumnLayoutStorageKey, getProjectColumnLayoutStorageKey, isGridEditorControlTarget, getBlockSortValue, getCellKind, getCircuitValue, getDeviceValue, - migrateLegacyColumnLayout, parseStoredColumnLayout, parseNumeric, } from "../src/frontend/utils/circuit-grid-model.js"; @@ -41,9 +39,11 @@ const circuit: CircuitTreeCircuitDto = { equipmentIdentifier: "-1F1", displayName: "Lighting circuit", sortOrder: 10, - protectionType: "MCB", - protectionRatedCurrent: 16, - protectionCharacteristic: "B", + protectionDevice: { + type: "LS", + ratedCurrentA: 16, + tripCharacteristic: "B", + }, cableType: "NYM-J", cableCrossSection: "1.5 mm²", cableLength: 20, @@ -83,10 +83,6 @@ describe("circuit grid model", () => { getProjectColumnLayoutStorageKey("project-1"), "circuitTreeEditor.columnLayout.v3.project-1" ); - assert.equal( - getLegacyProjectColumnLayoutStorageKey("project-1"), - "circuitTreeEditor.columnLayout.v2.project-1" - ); const layout = parseStoredColumnLayout( JSON.stringify({ order: ["displayName", "equipmentIdentifier"], @@ -106,39 +102,6 @@ describe("circuit grid model", () => { assert.equal(parseStoredColumnLayout("{invalid"), null); }); - it("adds the circuit protection column to legacy project layouts", () => { - const legacyLayout = parseStoredColumnLayout( - JSON.stringify({ - order: [ - "equipmentIdentifier", - "displayName", - "rowTotalPower", - "remark", - ], - visible: [ - "equipmentIdentifier", - "displayName", - "rowTotalPower", - "remark", - ], - }) - ); - assert.ok(legacyLayout); - - const migrated = migrateLegacyColumnLayout(legacyLayout); - assert.equal( - migrated.order.indexOf("protectionSummary"), - migrated.order.indexOf("rowTotalPower") + 1 - ); - assert.deepEqual(migrated.visible, [ - "equipmentIdentifier", - "displayName", - "rowTotalPower", - "remark", - "protectionSummary", - ]); - }); - it("shows stable circuit sections with German labels", () => { assert.equal( getCircuitSectionLabel({ @@ -181,7 +144,7 @@ describe("circuit grid model", () => { it("projects circuit and device values without mixing ownership", () => { assert.equal(getDeviceValue(device, "roomSummary"), "1.01 Office"); assert.equal(getDeviceValue(device, "rowTotalPower"), 0.08); - assert.equal(getCircuitValue(circuit, "protectionSummary"), "MCB 16A B"); + assert.equal(getCircuitValue(circuit, "protectionSummary"), "LS · 16 A · B"); assert.equal( getCircuitValue( { diff --git a/tests/circuit-group-numbering.test.ts b/tests/circuit-group-numbering.test.ts index 88e291b..a63c766 100644 --- a/tests/circuit-group-numbering.test.ts +++ b/tests/circuit-group-numbering.test.ts @@ -424,7 +424,7 @@ describe("circuit group numbering", () => { }); }); - it("rejects legacy, malformed and unsupported identifiers", () => { + it("rejects outdated, malformed and unsupported identifiers", () => { for (const identifier of [ "-1F1", "1F1.1", diff --git a/tests/circuit-group-subtree-project-command.repository.test.ts b/tests/circuit-group-subtree-project-command.repository.test.ts index 2fc5469..05d7dcc 100644 --- a/tests/circuit-group-subtree-project-command.repository.test.ts +++ b/tests/circuit-group-subtree-project-command.repository.test.ts @@ -90,7 +90,6 @@ function createTestDatabase(): DatabaseContext { id: "subtree-row", circuitId: "subtree-circuit", linkedProjectDeviceId: null, - legacyConsumerId: null, sortOrder: 10, name: "Leuchte", displayName: "Leuchte", diff --git a/tests/circuit-group-subtree-snapshot.test.ts b/tests/circuit-group-subtree-snapshot.test.ts index dfe1105..f748e90 100644 --- a/tests/circuit-group-subtree-snapshot.test.ts +++ b/tests/circuit-group-subtree-snapshot.test.ts @@ -71,9 +71,6 @@ function createSnapshot(): CircuitGroupSubtreeSnapshot { equipmentIdentifier: "-1F1.1", displayName: "Beleuchtung", sortOrder: 10, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: null, cableCrossSection: null, cableLength: null, @@ -89,7 +86,6 @@ function createSnapshot(): CircuitGroupSubtreeSnapshot { id: "row-1", circuitId: "circuit-1", linkedProjectDeviceId: "device-1", - legacyConsumerId: null, sortOrder: 10, name: "Leuchte", displayName: "Leuchte Flur", diff --git a/tests/circuit-power-calculation.test.ts b/tests/circuit-power-calculation.test.ts index 157bce2..2f9c0ec 100644 --- a/tests/circuit-power-calculation.test.ts +++ b/tests/circuit-power-calculation.test.ts @@ -10,7 +10,6 @@ import { import { resolveCircuitPhaseType, resolveProjectVoltage, - normalizeKnownElectricalPhaseType, } from "../src/domain/services/project-voltage.service.js"; describe("circuit power calculation", () => { @@ -74,16 +73,5 @@ describe("project voltage derivation", () => { assert.equal(resolveCircuitPhaseType("unassigned", [null]), "single_phase"); }); - it("normalizes known legacy phase labels without guessing unknown values", () => { - assert.equal(normalizeKnownElectricalPhaseType("1phasig"), "single_phase"); - assert.equal(normalizeKnownElectricalPhaseType("1-phasig"), "single_phase"); - assert.equal(normalizeKnownElectricalPhaseType("3phase"), "three_phase"); - assert.equal(normalizeKnownElectricalPhaseType("3-phasig"), "three_phase"); - assert.equal(normalizeKnownElectricalPhaseType(null), null); - assert.throws( - () => normalizeKnownElectricalPhaseType("zweiphasig"), - /Unknown electrical phase type/ - ); - }); }); diff --git a/tests/circuit-project-command.repository.test.ts b/tests/circuit-project-command.repository.test.ts index a98d7d5..7cad141 100644 --- a/tests/circuit-project-command.repository.test.ts +++ b/tests/circuit-project-command.repository.test.ts @@ -70,7 +70,7 @@ function createTestFixture(): TestFixture { equipmentIdentifier: "-1F1", displayName: "Licht Bestand", sortOrder: 10, - protectionRatedCurrent: 10, + cableLength: 10, voltage: 230, controlRequirement: "none", isReserve: 0, @@ -112,7 +112,7 @@ describe("circuit project-command repository", () => { const store = new CircuitProjectCommandRepository(fixture.context.db); const command = createCircuitUpdateProjectCommand("circuit-1", { displayName: null, - protectionRatedCurrent: 16, + cableLength: 16, voltage: 400, controlRequirement: "DALI", isReserve: true, @@ -128,7 +128,7 @@ describe("circuit project-command repository", () => { const circuit = getCircuit(fixture.context); assert.equal(circuit.displayName, null); - assert.equal(circuit.protectionRatedCurrent, 16); + assert.equal(circuit.cableLength, 16); assert.equal(circuit.voltage, 230); assert.equal(circuit.controlRequirement, "DALI"); assert.equal(circuit.isReserve, 1); @@ -137,7 +137,7 @@ describe("circuit project-command repository", () => { circuitId: "circuit-1", changes: [ { field: "displayName", value: "Licht Bestand" }, - { field: "protectionRatedCurrent", value: 10 }, + { field: "cableLength", value: 10 }, { field: "controlRequirement", value: "none" }, { field: "isReserve", value: false }, ], @@ -152,7 +152,7 @@ describe("circuit project-command repository", () => { deserializeProjectCommand(changeSet.forwardPayloadJson), createCircuitUpdateProjectCommand("circuit-1", { displayName: null, - protectionRatedCurrent: 16, + cableLength: 16, controlRequirement: "DALI", isReserve: true, }) @@ -184,7 +184,7 @@ describe("circuit project-command repository", () => { source: "user", command: createCircuitUpdateProjectCommand("circuit-1", { displayName: "Licht Neu", - protectionRatedCurrent: 16, + cableLength: 16, }), }); @@ -199,7 +199,7 @@ describe("circuit project-command repository", () => { const circuit = getCircuit(fixture.context); assert.equal(circuit.displayName, "Licht Bestand"); - assert.equal(circuit.protectionRatedCurrent, 10); + assert.equal(circuit.cableLength, 10); assert.equal(undone.revision.revisionNumber, 2); assert.deepEqual( fixture.context.db diff --git a/tests/circuit-structure-command.test.ts b/tests/circuit-structure-command.test.ts index 2bee690..d688685 100644 --- a/tests/circuit-structure-command.test.ts +++ b/tests/circuit-structure-command.test.ts @@ -12,7 +12,7 @@ import { } from "../src/frontend/utils/api.js"; describe("circuit structure command adapters", () => { - it("builds a complete row snapshot without legacy identities", () => { + it("builds a complete row snapshot", () => { const row = buildCircuitDeviceRowInsertSnapshot({ id: "row-1", circuitId: "circuit-1", @@ -31,7 +31,6 @@ describe("circuit structure command adapters", () => { id: "row-1", circuitId: "circuit-1", linkedProjectDeviceId: "device-1", - legacyConsumerId: null, sortOrder: 20, name: "Steckdose", displayName: "Steckdose Büro", diff --git a/tests/circuit-structure-project-command.repository.test.ts b/tests/circuit-structure-project-command.repository.test.ts index acfdd02..96e8c10 100644 --- a/tests/circuit-structure-project-command.repository.test.ts +++ b/tests/circuit-structure-project-command.repository.test.ts @@ -117,9 +117,6 @@ function createTestDatabase(): TestFixture { equipmentIdentifier: "-1F1", displayName: "Bestand", sortOrder: 10, - protectionType: "LS", - protectionRatedCurrent: 16, - protectionCharacteristic: "B", cableType: "NYM-J", cableCrossSection: "3x1,5", cableLength: 18.5, @@ -139,7 +136,6 @@ function createTestDatabase(): TestFixture { id: "row-existing-1", circuitId: "circuit-existing", linkedProjectDeviceId: "device-1", - legacyConsumerId: "legacy-1", sortOrder: 10, name: "Leuchte A", displayName: "Leuchte A lokal", @@ -198,7 +194,6 @@ function createRow( id, circuitId, linkedProjectDeviceId: null, - legacyConsumerId: null, sortOrder, name: `Gerät ${id}`, displayName: `Gerät ${id}`, @@ -241,9 +236,6 @@ function createCircuitSnapshot( equipmentIdentifier: "-1F2", displayName: "Neuer Stromkreis", sortOrder: 20, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: null, cableCrossSection: null, cableLength: null, @@ -569,14 +561,6 @@ describe("circuit structure project-command repository", () => { }), ], }), - createCircuitSnapshot(fixture, { - id: "legacy-row", - deviceRows: [ - createRow("legacy-row", "row-legacy", 10, { - legacyConsumerId: "legacy-user-value", - }), - ], - }), ]; for (const snapshot of invalidSnapshots) { assert.throws(() => diff --git a/tests/distribution-board-component-schema-migration.test.ts b/tests/distribution-board-component-schema-migration.test.ts deleted file mode 100644 index a8132f9..0000000 --- a/tests/distribution-board-component-schema-migration.test.ts +++ /dev/null @@ -1,466 +0,0 @@ -import assert from "node:assert/strict"; -import fs from "node:fs"; -import path from "node:path"; -import { describe, it } from "node:test"; -import Database from "better-sqlite3"; -import { migrate } from "drizzle-orm/better-sqlite3/migrator"; -import { createDatabaseContext } from "../src/db/database-context.js"; - -const migrationPath = path.resolve( - "src", - "db", - "migrations", - "0024_damp_mister_sinister.sql" -); - -function applyComponentSchemaMigration(sqlite: Database.Database): void { - const migrationSql = fs.readFileSync(migrationPath, "utf8"); - for (const statement of migrationSql.split("--> statement-breakpoint")) { - if (statement.trim()) { - sqlite.exec(statement); - } - } -} - -function createLegacySchema(sqlite: Database.Database): void { - sqlite.pragma("foreign_keys = ON"); - sqlite.exec(` - CREATE TABLE circuit_lists ( - id text PRIMARY KEY NOT NULL - ); - CREATE TABLE circuit_sections ( - id text PRIMARY KEY NOT NULL, - circuit_list_id text NOT NULL REFERENCES circuit_lists(id) ON DELETE CASCADE, - key text NOT NULL, - display_name text NOT NULL, - prefix text NOT NULL, - sort_order integer DEFAULT 0 NOT NULL - ); - CREATE TABLE circuits ( - id text PRIMARY KEY NOT NULL, - circuit_list_id text NOT NULL REFERENCES circuit_lists(id) ON DELETE CASCADE, - equipment_identifier text NOT NULL, - protection_type text, - protection_rated_current real, - protection_characteristic text - ); - `); -} - -describe("distribution board component schema migration", () => { - it("creates the additive schema on an empty database", () => { - const context = createDatabaseContext(":memory:"); - try { - migrate(context.db, { - migrationsFolder: path.resolve("src", "db", "migrations"), - }); - - const tables = ( - context.sqlite - .prepare( - `SELECT name - FROM sqlite_master - WHERE type = 'table' - ORDER BY name` - ) - .all() as Array<{ name: string }> - ).map((table) => table.name); - - assert.equal(tables.includes("distribution_board_components"), true); - assert.equal(tables.includes("circuit_protection_devices"), true); - assert.deepEqual( - tables.includes("distribution_board_component_protection_devices"), - true - ); - assert.deepEqual( - tables.includes("circuit_list_equipment_identifiers"), - true - ); - - const sectionColumns = ( - context.sqlite - .prepare("PRAGMA table_info(circuit_sections)") - .all() as Array<{ name: string }> - ).map((column) => column.name); - assert.equal(sectionColumns.includes("category"), true); - assert.equal(sectionColumns.includes("group_number"), true); - } finally { - context.close(); - } - }); - - it("backfills groups and the BMK registry without rewriting existing planning data", () => { - const sqlite = new Database(":memory:"); - try { - createLegacySchema(sqlite); - sqlite.exec(` - INSERT INTO circuit_lists (id) VALUES ('list-1'); - INSERT INTO circuit_sections ( - id, - circuit_list_id, - key, - display_name, - prefix, - sort_order - ) VALUES - ('lighting', 'list-1', 'lighting', 'Beleuchtung', '-1F', 10), - ('single', 'list-1', 'single_phase', '1-phasig', '-2F', 20), - ('three', 'list-1', 'three_phase', '3-phasig', '-3F', 30), - ('unassigned', 'list-1', 'unassigned', 'Nicht zugeordnet', '-9F', 40); - INSERT INTO circuits ( - id, - circuit_list_id, - equipment_identifier, - protection_type, - protection_rated_current, - protection_characteristic - ) VALUES - ('circuit-1', 'list-1', '-1F1', 'legacy fuse', 13, 'legacy'), - ('circuit-2', 'list-1', '-2F4', NULL, NULL, NULL); - `); - - applyComponentSchemaMigration(sqlite); - - assert.deepEqual( - sqlite - .prepare( - `SELECT - id, - category, - group_number AS groupNumber - FROM circuit_sections - ORDER BY sort_order` - ) - .all(), - [ - { id: "lighting", category: "lighting", groupNumber: 1 }, - { id: "single", category: "single_phase", groupNumber: 1 }, - { id: "three", category: "three_phase", groupNumber: 1 }, - { id: "unassigned", category: null, groupNumber: null }, - ] - ); - assert.deepEqual( - sqlite - .prepare( - `SELECT - id, - equipment_identifier AS equipmentIdentifier, - protection_type AS protectionType, - protection_rated_current AS protectionRatedCurrent, - protection_characteristic AS protectionCharacteristic - FROM circuits - ORDER BY id` - ) - .all(), - [ - { - id: "circuit-1", - equipmentIdentifier: "-1F1", - protectionType: "legacy fuse", - protectionRatedCurrent: 13, - protectionCharacteristic: "legacy", - }, - { - id: "circuit-2", - equipmentIdentifier: "-2F4", - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, - }, - ] - ); - assert.deepEqual( - sqlite - .prepare( - `SELECT - owner_type AS ownerType, - owner_id AS ownerId, - equipment_identifier AS equipmentIdentifier - FROM circuit_list_equipment_identifiers - ORDER BY owner_id` - ) - .all(), - [ - { - ownerType: "circuit", - ownerId: "circuit-1", - equipmentIdentifier: "-1F1", - }, - { - ownerType: "circuit", - ownerId: "circuit-2", - equipmentIdentifier: "-2F4", - }, - ] - ); - assert.deepEqual( - sqlite - .prepare("SELECT count(*) AS count FROM circuit_protection_devices") - .get(), - { count: 0 } - ); - } finally { - sqlite.close(); - } - }); - - it("keeps the shared BMK registry synchronized and rejects normalized collisions", () => { - const sqlite = new Database(":memory:"); - try { - createLegacySchema(sqlite); - sqlite.exec(` - INSERT INTO circuit_lists (id) VALUES ('list-1'); - INSERT INTO circuit_sections ( - id, - circuit_list_id, - key, - display_name, - prefix - ) VALUES ('lighting', 'list-1', 'lighting', 'Beleuchtung', '-1F'); - INSERT INTO circuits ( - id, - circuit_list_id, - equipment_identifier - ) VALUES ('circuit-1', 'list-1', '-1F1'); - `); - applyComponentSchemaMigration(sqlite); - - sqlite - .prepare( - `INSERT INTO distribution_board_components ( - id, - circuit_list_id, - equipment_identifier, - name, - role, - placement, - sort_order - ) VALUES (?, ?, ?, ?, ?, ?, ?)` - ) - .run( - "main-switch", - "list-1", - "-Q0", - "Hauptschalter", - "main_switch", - "header", - 10 - ); - - assert.throws(() => - sqlite - .prepare( - `INSERT INTO distribution_board_components ( - id, - circuit_list_id, - equipment_identifier, - name, - role, - placement - ) VALUES (?, ?, ?, ?, ?, ?)` - ) - .run( - "duplicate", - "list-1", - " -q0 ", - "Duplikat", - "auxiliary", - "footer" - ) - ); - assert.throws(() => - sqlite - .prepare( - `INSERT INTO distribution_board_components ( - id, - circuit_list_id, - equipment_identifier, - name, - role, - placement - ) VALUES (?, ?, ?, ?, ?, ?)` - ) - .run( - "circuit-duplicate", - "list-1", - "-1f1", - "Duplikat", - "auxiliary", - "footer" - ) - ); - - sqlite - .prepare( - `INSERT INTO circuits ( - id, - circuit_list_id, - equipment_identifier - ) VALUES (?, ?, ?)` - ) - .run("circuit-2", "list-1", "-1F2"); - sqlite - .prepare( - `UPDATE circuits - SET equipment_identifier = ? - WHERE id = ?` - ) - .run("-1F3", "circuit-2"); - - assert.deepEqual( - sqlite - .prepare( - `SELECT equipment_identifier AS equipmentIdentifier - FROM circuit_list_equipment_identifiers - WHERE owner_type = 'circuit' AND owner_id = 'circuit-2'` - ) - .get(), - { equipmentIdentifier: "-1F3" } - ); - - assert.throws(() => - sqlite - .prepare( - `UPDATE circuits - SET equipment_identifier = ? - WHERE id = ?` - ) - .run("-q0", "circuit-2") - ); - assert.deepEqual( - sqlite - .prepare( - `SELECT equipment_identifier AS equipmentIdentifier - FROM circuits - WHERE id = 'circuit-2'` - ) - .get(), - { equipmentIdentifier: "-1F3" } - ); - - sqlite - .prepare("DELETE FROM distribution_board_components WHERE id = ?") - .run("main-switch"); - assert.deepEqual( - sqlite - .prepare( - `SELECT count(*) AS count - FROM circuit_list_equipment_identifiers - WHERE owner_type = 'distribution_board_component'` - ) - .get(), - { count: 0 } - ); - } finally { - sqlite.close(); - } - }); - - it("stores independent one-to-one circuit and component protection state", () => { - const sqlite = new Database(":memory:"); - try { - createLegacySchema(sqlite); - sqlite.exec(` - INSERT INTO circuit_lists (id) VALUES ('list-1'); - INSERT INTO circuit_sections ( - id, - circuit_list_id, - key, - display_name, - prefix - ) VALUES ('lighting', 'list-1', 'lighting', 'Beleuchtung', '-1F'); - INSERT INTO circuits ( - id, - circuit_list_id, - equipment_identifier - ) VALUES ('circuit-1', 'list-1', '-1F1'); - `); - applyComponentSchemaMigration(sqlite); - sqlite.exec(` - INSERT INTO circuit_protection_devices ( - circuit_id, - type, - rated_current_a, - trip_characteristic - ) VALUES ('circuit-1', 'LS', 10, 'B'); - INSERT INTO distribution_board_components ( - id, - circuit_list_id, - section_id, - equipment_identifier, - name, - role, - placement - ) VALUES ( - 'group-rcd', - 'list-1', - 'lighting', - '-1Q1.0', - 'Gruppen-FI', - 'group_residual_current_protection', - 'group' - ); - INSERT INTO distribution_board_component_protection_devices ( - component_id, - type, - rated_current_a, - rcd_type, - rated_residual_current_ma - ) VALUES ('group-rcd', 'FI', 40, 'A', 30); - `); - - assert.deepEqual( - sqlite - .prepare("SELECT * FROM circuit_protection_devices") - .get(), - { - circuit_id: "circuit-1", - type: "LS", - rated_current_a: 10, - fuse_utilization_category: null, - trip_characteristic: "B", - rcd_type: null, - rated_residual_current_ma: null, - } - ); - assert.deepEqual( - sqlite - .prepare( - "SELECT * FROM distribution_board_component_protection_devices" - ) - .get(), - { - component_id: "group-rcd", - type: "FI", - rated_current_a: 40, - fuse_utilization_category: null, - trip_characteristic: null, - rcd_type: "A", - rated_residual_current_ma: 30, - } - ); - - sqlite.prepare("DELETE FROM circuits WHERE id = ?").run("circuit-1"); - sqlite - .prepare("DELETE FROM distribution_board_components WHERE id = ?") - .run("group-rcd"); - assert.deepEqual( - sqlite - .prepare("SELECT count(*) AS count FROM circuit_protection_devices") - .get(), - { count: 0 } - ); - assert.deepEqual( - sqlite - .prepare( - `SELECT count(*) AS count - FROM distribution_board_component_protection_devices` - ) - .get(), - { count: 0 } - ); - } finally { - sqlite.close(); - } - }); -}); diff --git a/tests/distribution-board-structure-project-command.repository.test.ts b/tests/distribution-board-structure-project-command.repository.test.ts index 9933446..685ffe8 100644 --- a/tests/distribution-board-structure-project-command.repository.test.ts +++ b/tests/distribution-board-structure-project-command.repository.test.ts @@ -21,11 +21,9 @@ import { ProjectRevisionConflictError } from "../src/domain/errors/project-revis import { createDistributionBoardInsertProjectCommand, createDistributionBoardStructureSnapshot, - type DistributionBoardStructureProjectCommand, } from "../src/domain/models/distribution-board-structure-project-command.model.js"; import { createDistributionBoardUpdateProjectCommand, - type DistributionBoardUpdateProjectCommand, } from "../src/domain/models/distribution-board-project-command.model.js"; import { copyDistributionBoard, @@ -62,43 +60,6 @@ function getStructureCounts(context: DatabaseContext) { }; } -function legacySections(circuitListId: string) { - return [ - { - id: "legacy-lighting", - circuitListId, - key: "lighting", - displayName: "Lighting", - prefix: "-1F", - sortOrder: 10, - }, - { - id: "legacy-single-phase", - circuitListId, - key: "single_phase", - displayName: "Single-phase circuits", - prefix: "-2F", - sortOrder: 20, - }, - { - id: "legacy-three-phase", - circuitListId, - key: "three_phase", - displayName: "Three-phase circuits", - prefix: "-3F", - sortOrder: 30, - }, - { - id: "legacy-unassigned", - circuitListId, - key: "unassigned", - displayName: "Unassigned", - prefix: "-UF", - sortOrder: 90, - }, - ]; -} - describe("distribution-board structure project command", () => { it("builds the fixed setup and sends the expected frontend revision", async () => { const structure = createDistributionBoardStructureSnapshot( @@ -308,104 +269,6 @@ describe("distribution-board structure project command", () => { } }); - it("applies stored version-one setup commands with unassigned new fields", () => { - const context = createTestDatabase(); - try { - const repository = - new DistributionBoardStructureProjectCommandRepository( - context.db - ); - const current = createDistributionBoardStructureSnapshot( - "project-1", - "UV Alt", - { floorId: null, supplyType: null } - ); - const { - floorId: _floorId, - supplyType: _supplyType, - ...legacyBoard - } = current.distributionBoard; - const legacyCommand = { - schemaVersion: 1, - type: "distribution-board.insert", - payload: { - structure: { - distributionBoard: legacyBoard, - circuitList: current.circuitList, - sections: legacySections(current.circuitList.id), - }, - }, - } as unknown as DistributionBoardStructureProjectCommand; - repository.execute({ - projectId: "project-1", - expectedRevision: 0, - source: "user", - command: legacyCommand, - }); - const inserted = context.db - .select() - .from(distributionBoards) - .get(); - assert.equal(inserted?.floorId, null); - assert.equal(inserted?.supplyType, null); - assert.equal( - context.db.select().from(circuitSections).all().length, - 4 - ); - assert.equal( - context.db.select().from(distributionBoardComponents).all() - .length, - 0 - ); - } finally { - context.close(); - } - }); - - it("keeps stored version-two setup commands component-free", () => { - const context = createTestDatabase(); - try { - const repository = - new DistributionBoardStructureProjectCommandRepository( - context.db - ); - const current = createDistributionBoardStructureSnapshot( - "project-1", - "UV Version 2" - ); - const command = { - schemaVersion: 2, - type: "distribution-board.insert", - payload: { - structure: { - distributionBoard: current.distributionBoard, - circuitList: current.circuitList, - sections: legacySections(current.circuitList.id), - }, - }, - } as DistributionBoardStructureProjectCommand; - - const inserted = repository.execute({ - projectId: "project-1", - expectedRevision: 0, - source: "user", - command, - }); - assert.equal(inserted.inverse.schemaVersion, 2); - assert.equal( - context.db.select().from(circuitSections).all().length, - 4 - ); - assert.equal( - context.db.select().from(distributionBoardComponents).all() - .length, - 0 - ); - } finally { - context.close(); - } - }); - it("updates floor, supply type and simultaneity factor with persisted undo", () => { const context = createTestDatabase(); try { @@ -524,52 +387,6 @@ describe("distribution-board structure project command", () => { } }); - it("keeps stored version-one board updates executable", () => { - const context = createTestDatabase(); - try { - const repository = - new DistributionBoardStructureProjectCommandRepository( - context.db - ); - const structure = createDistributionBoardStructureSnapshot( - "project-1", - "UV Alt", - { supplyType: "AV" } - ); - repository.execute({ - projectId: "project-1", - expectedRevision: 0, - source: "user", - command: - createDistributionBoardInsertProjectCommand(structure), - }); - const legacyUpdate = { - schemaVersion: 1, - type: "distribution-board.update", - payload: { - distributionBoardId: structure.distributionBoard.id, - changes: [{ field: "supplyType", value: "SV" }], - }, - } as DistributionBoardUpdateProjectCommand; - - repository.executeUpdate({ - projectId: "project-1", - expectedRevision: 1, - source: "user", - command: legacyUpdate, - }); - - const board = context.db - .select() - .from(distributionBoards) - .get(); - assert.equal(board?.supplyType, "SV"); - assert.equal(board?.simultaneityFactor, 1); - } finally { - context.close(); - } - }); - it("sends distribution-board writes to the revision-safe API", async () => { const requests: Array<{ url: string; method: string; body: unknown }> = []; const originalFetch = globalThis.fetch; diff --git a/tests/distribution-board-subtree.test.ts b/tests/distribution-board-subtree.test.ts index 3faaa12..33d5318 100644 --- a/tests/distribution-board-subtree.test.ts +++ b/tests/distribution-board-subtree.test.ts @@ -82,9 +82,6 @@ function createSnapshot(): DistributionBoardSubtreeSnapshot { equipmentIdentifier: "-1F1.1", displayName: "Licht", sortOrder: 10, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: "NYM-J", cableCrossSection: "3x1,5 mm²", cableLength: 10, @@ -100,7 +97,6 @@ function createSnapshot(): DistributionBoardSubtreeSnapshot { id: "row-1", circuitId: "circuit-1", linkedProjectDeviceId: "device-1", - legacyConsumerId: "legacy-1", sortOrder: 10, name: "Leuchte", displayName: "Leuchte", @@ -176,7 +172,6 @@ describe("distribution-board subtree snapshot", () => { "device-1" ); assert.equal(clone.circuits[0].deviceRows[0].roomId, "room-1"); - assert.equal(clone.circuits[0].deviceRows[0].legacyConsumerId, null); assert.equal(clone.circuits[0].protectionDevice?.circuitId, "new-3"); assert.doesNotThrow(() => assertDistributionBoardSubtreeSnapshot(clone)); }); diff --git a/tests/legacy-consumer-migration-planner.test.ts b/tests/legacy-consumer-migration-planner.test.ts deleted file mode 100644 index e541e73..0000000 --- a/tests/legacy-consumer-migration-planner.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -import assert from "node:assert/strict"; -import { describe, it } from "node:test"; -import { - inferSectionKeyFromEquipmentIdentifier, - inferSectionKeyFromLegacyInput, - normalizeCircuitNumber, -} from "../src/domain/services/legacy-consumer-migration-planner.js"; - -describe("legacy consumer migration planner", () => { - it("normalizes valid circuit numbers and rejects invalid formats", () => { - assert.equal(normalizeCircuitNumber(" -2f12 "), "-2F12"); - assert.equal(normalizeCircuitNumber("2F12"), null); - assert.equal(normalizeCircuitNumber(""), null); - assert.equal(normalizeCircuitNumber(null), null); - }); - - it("infers section from equipment identifier prefix", () => { - assert.equal(inferSectionKeyFromEquipmentIdentifier("-1F4"), "lighting"); - assert.equal(inferSectionKeyFromEquipmentIdentifier("-2F8"), "single_phase"); - assert.equal(inferSectionKeyFromEquipmentIdentifier("-3F1"), "three_phase"); - assert.equal(inferSectionKeyFromEquipmentIdentifier("-9F1"), null); - }); - - it("infers section from category/phase when circuit number is missing", () => { - assert.equal( - inferSectionKeyFromLegacyInput({ - id: "1", - circuitNumber: null, - category: "Beleuchtung", - phaseType: null, - phaseCount: null, - }), - "lighting" - ); - assert.equal( - inferSectionKeyFromLegacyInput({ - id: "2", - circuitNumber: null, - category: null, - phaseType: "three-phase", - phaseCount: null, - }), - "three_phase" - ); - assert.equal( - inferSectionKeyFromLegacyInput({ - id: "3", - circuitNumber: null, - category: null, - phaseType: null, - phaseCount: null, - }), - null - ); - }); -}); - diff --git a/tests/legacy-consumer-migration.repository.test.ts b/tests/legacy-consumer-migration.repository.test.ts deleted file mode 100644 index ae4f874..0000000 --- a/tests/legacy-consumer-migration.repository.test.ts +++ /dev/null @@ -1,245 +0,0 @@ -import path from "node:path"; -import assert from "node:assert/strict"; -import { describe, it } from "node:test"; -import { eq } from "drizzle-orm"; -import { migrate } from "drizzle-orm/better-sqlite3/migrator"; -import { - createDatabaseContext, - type DatabaseContext, -} from "../src/db/database-context.js"; -import { DistributionBoardFixtureRepository } from "./support/distribution-board-fixture.js"; -import { LegacyConsumerMigrationRepository } from "../src/db/repositories/legacy-consumer-migration.repository.js"; -import { circuitDeviceRows } from "../src/db/schema/circuit-device-rows.js"; -import { circuitSections } from "../src/db/schema/circuit-sections.js"; -import { circuits } from "../src/db/schema/circuits.js"; -import { consumers } from "../src/db/schema/consumers.js"; -import { legacyConsumerCircuitMigrations } from "../src/db/schema/legacy-consumer-circuit-migrations.js"; -import { legacyConsumerMigrationReports } from "../src/db/schema/legacy-consumer-migration-report.js"; -import { projects } from "../src/db/schema/projects.js"; - -function createTestDatabase() { - const context = createDatabaseContext(":memory:"); - migrate(context.db, { - migrationsFolder: path.resolve("src", "db", "migrations"), - }); - context.db.insert(projects).values({ id: "project-1", name: "Test project" }).run(); - const board = new DistributionBoardFixtureRepository( - context.db - ).createWithCircuitListAndDefaultSections("project-1", "UV-01"); - const [section] = context.db - .select() - .from(circuitSections) - .where(eq(circuitSections.circuitListId, board.id)) - .limit(1) - .all(); - return { context, circuitListId: board.id, sectionId: section.id }; -} - -function migrationInput(circuitListId: string, sectionId: string) { - return { - circuitListId, - circuits: [ - { - circuit: { - circuitListId, - sectionId, - equipmentIdentifier: "-1F1", - displayName: "Legacy lighting", - sortOrder: 10, - }, - deviceRows: [ - { - legacyConsumerId: "consumer-1", - sortOrder: 10, - name: "Light 1", - displayName: "Light 1", - quantity: 1, - powerPerUnit: 0.1, - simultaneityFactor: 1, - }, - { - legacyConsumerId: "consumer-2", - sortOrder: 20, - name: "Light 2", - displayName: "Light 2", - quantity: 2, - powerPerUnit: 0.2, - simultaneityFactor: 0.8, - }, - ], - }, - ], - report: { - legacyConsumerCount: 2, - createdCircuitCount: 1, - createdDeviceRowCount: 2, - duplicateGroupedCount: 1, - generatedIdentifierCount: 0, - unassignedRowCount: 0, - warningsJson: "[]", - generatedIdentifiersJson: "[]", - duplicateGroupsJson: - "[{\"normalizedCircuitNumber\":\"-1F1\",\"count\":2}]", - }, - }; -} - -function assertNoMigrationWrites(context: DatabaseContext) { - assert.equal(context.db.select().from(circuits).all().length, 0); - assert.equal(context.db.select().from(circuitDeviceRows).all().length, 0); - assert.equal( - context.db.select().from(legacyConsumerCircuitMigrations).all().length, - 0 - ); - assert.equal( - context.db.select().from(legacyConsumerMigrationReports).all().length, - 0 - ); -} - -describe("legacy consumer migration repository", () => { - it("reports every consumer without a completed migration mapping", async () => { - const { context, circuitListId, sectionId } = createTestDatabase(); - try { - context.db - .insert(consumers) - .values([ - { - id: "consumer-1", - projectId: "project-1", - circuitListId, - name: "Light 1", - quantity: 1, - installedPowerPerUnitKw: 0.1, - demandFactor: 1, - }, - { - id: "consumer-2", - projectId: "project-1", - circuitListId: null, - name: "Light 2", - quantity: 1, - installedPowerPerUnitKw: 0.2, - demandFactor: 1, - }, - ]) - .run(); - const repository = new LegacyConsumerMigrationRepository(context.db); - - assert.deepEqual( - (await repository.listSourceConsumersByCircuitList(circuitListId)).map( - (consumer) => consumer.id - ), - ["consumer-1"] - ); - assert.deepEqual( - (await repository.listUnmigratedConsumers()).sort((left, right) => - left.id.localeCompare(right.id) - ), - [ - { - id: "consumer-1", - projectId: "project-1", - circuitListId, - }, - { - id: "consumer-2", - projectId: "project-1", - circuitListId: null, - }, - ] - ); - - repository.persistCircuitListMigration( - migrationInput(circuitListId, sectionId) - ); - assert.deepEqual(await repository.listUnmigratedConsumers(), []); - } finally { - context.close(); - } - }); - - it("commits circuits, rows, mappings and report together", () => { - const { context, circuitListId, sectionId } = createTestDatabase(); - try { - const repository = new LegacyConsumerMigrationRepository(context.db); - - repository.persistCircuitListMigration( - migrationInput(circuitListId, sectionId) - ); - - const persistedCircuits = context.db.select().from(circuits).all(); - const persistedRows = context.db - .select() - .from(circuitDeviceRows) - .all() - .sort((left, right) => left.sortOrder - right.sortOrder); - const persistedMappings = context.db - .select() - .from(legacyConsumerCircuitMigrations) - .all() - .sort((left, right) => left.consumerId.localeCompare(right.consumerId)); - const persistedReports = context.db - .select() - .from(legacyConsumerMigrationReports) - .all(); - - assert.equal(persistedCircuits.length, 1); - assert.equal(persistedRows.length, 2); - assert.equal(persistedMappings.length, 2); - assert.equal(persistedReports.length, 1); - assert.deepEqual( - persistedMappings.map((mapping) => [ - mapping.consumerId, - mapping.circuitId, - mapping.circuitDeviceRowId, - mapping.circuitListId, - ]), - [ - [ - "consumer-1", - persistedCircuits[0].id, - persistedRows[0].id, - circuitListId, - ], - [ - "consumer-2", - persistedCircuits[0].id, - persistedRows[1].id, - circuitListId, - ], - ] - ); - assert.equal(persistedReports[0].createdCircuitCount, 1); - assert.equal(persistedReports[0].createdDeviceRowCount, 2); - } finally { - context.close(); - } - }); - - it("rolls back all migrated entities when the final report write fails", () => { - const { context, circuitListId, sectionId } = createTestDatabase(); - try { - context.sqlite.exec(` - CREATE TRIGGER fail_migration_report - BEFORE INSERT ON legacy_consumer_migration_reports - BEGIN - SELECT RAISE(ABORT, 'forced migration report failure'); - END; - `); - const repository = new LegacyConsumerMigrationRepository(context.db); - - assert.throws( - () => - repository.persistCircuitListMigration( - migrationInput(circuitListId, sectionId) - ), - /forced migration report failure/ - ); - - assertNoMigrationWrites(context); - } finally { - context.close(); - } - }); -}); diff --git a/tests/legacy-consumer-migration.service.test.ts b/tests/legacy-consumer-migration.service.test.ts deleted file mode 100644 index b78aca7..0000000 --- a/tests/legacy-consumer-migration.service.test.ts +++ /dev/null @@ -1,130 +0,0 @@ -import assert from "node:assert/strict"; -import { describe, it } from "node:test"; -import type { - LegacyConsumerMigrationDependencies, - LegacyMigrationCircuitInput, - LegacyMigrationReportInput, -} from "../src/domain/ports/legacy-consumer-migration.store.js"; -import { LegacyConsumerMigrationService } from "../src/domain/services/legacy-consumer-migration.service.js"; - -describe("legacy consumer migration service", () => { - it("plans the migration through injected readers and persists one complete batch", async () => { - let defaultsCreatedFor: string | null = null; - let persisted: - | { - circuitListId: string; - circuits: LegacyMigrationCircuitInput[]; - report: LegacyMigrationReportInput; - } - | undefined; - const dependencies: LegacyConsumerMigrationDependencies = { - circuitListReader: { - async findById(projectId, circuitListId) { - assert.equal(projectId, "project-1"); - assert.equal(circuitListId, "list-1"); - return { id: circuitListId }; - }, - }, - sectionStore: { - async createDefaults(circuitListId) { - defaultsCreatedFor = circuitListId; - }, - async listByCircuitList() { - return [ - { id: "section-1", key: "single_phase", prefix: "-2F" }, - { id: "section-2", key: "unassigned", prefix: "-XF" }, - ]; - }, - }, - circuitReader: { - async listByCircuitList() { - return [ - { - sectionId: "section-1", - equipmentIdentifier: "-2F2", - sortOrder: 10, - }, - ]; - }, - }, - roomReader: { - async listByProject() { - return [ - { id: "room-1", roomNumber: "1.01", roomName: "Besprechung" }, - ]; - }, - }, - migrationStore: { - async listSourceConsumersByCircuitList() { - return [ - { - id: "consumer-1", - projectDeviceId: null, - roomId: "room-1", - circuitNumber: null, - description: "Steckdosen Besprechung", - name: "Steckdose", - category: null, - deviceType: null, - phaseType: null, - tradeOrCostGroup: "KG 440", - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, - cableType: null, - cableCrossSection: null, - comment: null, - quantity: 2, - installedPowerPerUnitKw: 0.2, - demandFactor: 0.8, - voltageV: 230, - phaseCount: 1, - powerFactor: 0.95, - note: "Bestand", - }, - ]; - }, - async listMigratedConsumerIds() { - return []; - }, - persistCircuitListMigration(input) { - persisted = input; - }, - }, - }; - - const report = await new LegacyConsumerMigrationService( - dependencies - ).migrateCircuitList("project-1", "list-1"); - - assert.equal(defaultsCreatedFor, "list-1"); - assert.deepEqual(report.generatedIdentifiers, ["-2F3"]); - assert.equal(report.createdCircuitCount, 1); - assert.equal(report.createdDeviceRowCount, 1); - assert.equal(persisted?.circuitListId, "list-1"); - assert.equal(persisted?.circuits[0].circuit.sectionId, "section-1"); - assert.equal( - persisted?.circuits[0].circuit.equipmentIdentifier, - "-2F3" - ); - assert.deepEqual(persisted?.circuits[0].deviceRows[0], { - linkedProjectDeviceId: undefined, - legacyConsumerId: "consumer-1", - sortOrder: 10, - name: "Steckdose", - displayName: "Steckdosen Besprechung", - phaseType: undefined, - connectionKind: undefined, - costGroup: "KG 440", - category: undefined, - roomId: "room-1", - roomNumberSnapshot: "1.01", - roomNameSnapshot: "Besprechung", - quantity: 2, - powerPerUnit: 0.2, - simultaneityFactor: 0.8, - cosPhi: 0.95, - remark: "Bestand", - }); - }); -}); diff --git a/tests/project-command.model.test.ts b/tests/project-command.model.test.ts index 1eb7c3f..9284f47 100644 --- a/tests/project-command.model.test.ts +++ b/tests/project-command.model.test.ts @@ -60,7 +60,7 @@ describe("serialized project commands", () => { circuitId: "circuit-1", changes: { displayName: "Werkstatt", - protectionRatedCurrent: 16, + cableLength: 16, isReserve: false, remark: null, }, @@ -378,7 +378,6 @@ describe("project-device structure project commands", () => { id: "row-1", circuitId: "circuit-1", linkedProjectDeviceId: null, - legacyConsumerId: null, sortOrder: 10, name: "Luminaire", displayName: "Local lighting", @@ -445,7 +444,6 @@ describe("circuit device-row structure project commands", () => { id: "row-1", circuitId: "circuit-1", linkedProjectDeviceId: null, - legacyConsumerId: null, sortOrder: 10, name: "Leuchte", displayName: "Leuchte", @@ -517,9 +515,6 @@ describe("circuit device-row move project commands", () => { equipmentIdentifier: "-1F3", displayName: "Neuer Stromkreis", sortOrder: 30, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: null, cableCrossSection: null, cableLength: null, @@ -683,7 +678,6 @@ describe("circuit structure project commands", () => { id: "row-1", circuitId: "circuit-1", linkedProjectDeviceId: null, - legacyConsumerId: null, sortOrder: 10, name: "Leuchte", displayName: "Leuchte", @@ -709,9 +703,6 @@ describe("circuit structure project commands", () => { equipmentIdentifier: "-1F1", displayName: "Beleuchtung", sortOrder: 10, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: null, cableCrossSection: null, cableLength: null, diff --git a/tests/project-command.service.test.ts b/tests/project-command.service.test.ts index 3a119e0..a96b4aa 100644 --- a/tests/project-command.service.test.ts +++ b/tests/project-command.service.test.ts @@ -555,7 +555,6 @@ describe("project command service", () => { id: "row-2", circuitId: "circuit-1", linkedProjectDeviceId: null, - legacyConsumerId: null, sortOrder: 20, name: "Steckdose", displayName: "Steckdose", @@ -623,9 +622,6 @@ describe("project command service", () => { equipmentIdentifier: "-1F2", displayName: "Reserve", sortOrder: 20, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: null, cableCrossSection: null, cableLength: null, @@ -745,9 +741,6 @@ describe("project command service", () => { equipmentIdentifier: "-1F2", displayName: "Neuer Stromkreis", sortOrder: 20, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: null, cableCrossSection: null, cableLength: null, diff --git a/tests/project-device-schema-migration.test.ts b/tests/project-device-schema-migration.test.ts deleted file mode 100644 index 62990c6..0000000 --- a/tests/project-device-schema-migration.test.ts +++ /dev/null @@ -1,98 +0,0 @@ -import assert from "node:assert/strict"; -import fs from "node:fs"; -import path from "node:path"; -import { describe, it } from "node:test"; -import Database from "better-sqlite3"; - -describe("project device canonical-field migration", () => { - it("preserves canonical values while removing transitional mirror columns", () => { - const sqlite = new Database(":memory:"); - try { - sqlite.exec(` - CREATE TABLE project_devices ( - id text PRIMARY KEY NOT NULL, - power_per_unit real NOT NULL, - simultaneity_factor real NOT NULL, - phase_type text NOT NULL, - cos_phi real, - remark text, - voltage_v real, - installed_power_per_unit_kw real NOT NULL, - demand_factor real NOT NULL, - phase_count integer, - power_factor real, - note text - ); - INSERT INTO project_devices VALUES ( - 'device-1', - 0.25, - 0.8, - 'three_phase', - 0.95, - 'Canonical remark', - 400, - 0.25, - 0.8, - 3, - 0.95, - 'Canonical remark' - ); - `); - - const migrationSql = fs.readFileSync( - path.resolve( - "src", - "db", - "migrations", - "0011_project_device_canonical_fields.sql" - ), - "utf8" - ); - for (const statement of migrationSql.split("--> statement-breakpoint")) { - if (statement.trim()) { - sqlite.exec(statement); - } - } - - const columns = ( - sqlite.prepare("PRAGMA table_info(project_devices)").all() as Array<{ - name: string; - }> - ).map((column) => column.name); - assert.deepEqual(columns, [ - "id", - "power_per_unit", - "simultaneity_factor", - "phase_type", - "cos_phi", - "remark", - "voltage_v", - ]); - assert.deepEqual( - sqlite - .prepare( - `SELECT - power_per_unit AS powerPerUnit, - simultaneity_factor AS simultaneityFactor, - phase_type AS phaseType, - cos_phi AS cosPhi, - remark, - voltage_v AS voltageV - FROM project_devices - WHERE id = ?` - ) - .get("device-1"), - { - powerPerUnit: 0.25, - simultaneityFactor: 0.8, - phaseType: "three_phase", - cosPhi: 0.95, - remark: "Canonical remark", - voltageV: 400, - } - ); - } finally { - sqlite.close(); - } - }); -}); diff --git a/tests/project-device-schema.test.ts b/tests/project-device-schema.test.ts index 55d078d..7ee2f89 100644 --- a/tests/project-device-schema.test.ts +++ b/tests/project-device-schema.test.ts @@ -30,8 +30,8 @@ describe("project device circuit-first schema", () => { it("requires the circuit-first power and phase fields", () => { const result = createProjectDeviceSchema.safeParse({ - name: "Legacy device", - displayName: "Legacy device", + name: "Test device", + displayName: "Test device", quantity: 1, installedPowerPerUnitKw: 0.1, demandFactor: 1, diff --git a/tests/project-device-sync.service.test.ts b/tests/project-device-sync.service.test.ts index e5a2191..f3fa03f 100644 --- a/tests/project-device-sync.service.test.ts +++ b/tests/project-device-sync.service.test.ts @@ -27,7 +27,6 @@ function linkedRow() { id: "row1", circuitId: "c1", linkedProjectDeviceId: "pd1", - legacyConsumerId: null, sortOrder: 10, name: "Old luminaire", displayName: "Local display name", diff --git a/tests/project-location-structure-project-command.repository.test.ts b/tests/project-location-structure-project-command.repository.test.ts index 7f7a61e..19f278b 100644 --- a/tests/project-location-structure-project-command.repository.test.ts +++ b/tests/project-location-structure-project-command.repository.test.ts @@ -9,7 +9,6 @@ import { } from "../src/db/database-context.js"; import { ProjectHistoryRepository } from "../src/db/repositories/project-history.repository.js"; import { ProjectLocationStructureProjectCommandRepository } from "../src/db/repositories/project-location-structure-project-command.repository.js"; -import { consumers } from "../src/db/schema/consumers.js"; import { distributionBoards } from "../src/db/schema/distribution-boards.js"; import { floors } from "../src/db/schema/floors.js"; import { projectRevisions } from "../src/db/schema/project-revisions.js"; @@ -423,53 +422,6 @@ describe("project-location structure project command", () => { floorContext.close(); } - const roomContext = createTestDatabase(); - try { - const repository = - new ProjectLocationStructureProjectCommandRepository( - roomContext.db - ); - const room = createProjectRoomSnapshot("project-1", { - roomNumber: "001", - roomName: "Technik", - }); - const inserted = repository.execute({ - projectId: "project-1", - expectedRevision: 0, - source: "user", - command: createProjectRoomInsertProjectCommand(room), - }); - roomContext.db - .insert(consumers) - .values({ - id: "legacy-consumer-1", - projectId: "project-1", - roomId: room.id, - name: "Bestand", - quantity: 1, - installedPowerPerUnitKw: 1, - demandFactor: 1, - }) - .run(); - const undoStep = new ProjectHistoryRepository( - roomContext.db - ).getNextCommand("project-1", "undo"); - assert.ok(undoStep); - assert.throws( - () => - repository.execute({ - projectId: "project-1", - expectedRevision: 1, - source: "undo", - historyTargetChangeSetId: undoStep.changeSetId, - command: inserted.inverse, - }), - /referenced project room/ - ); - } finally { - roomContext.close(); - } - const rollbackContext = createTestDatabase(); try { rollbackContext.sqlite.exec(` diff --git a/tests/project-settings-project-command.repository.test.ts b/tests/project-settings-project-command.repository.test.ts index dc3aada..393ba4e 100644 --- a/tests/project-settings-project-command.repository.test.ts +++ b/tests/project-settings-project-command.repository.test.ts @@ -365,37 +365,6 @@ describe("project settings project-command repository", () => { } }); - it("applies persisted version-one voltage commands without clearing metadata", () => { - const context = createTestDatabase(); - try { - const repository = new ProjectSettingsProjectCommandRepository( - context.db - ); - repository.executeUpdate({ - projectId: "project-1", - expectedRevision: 0, - source: "user", - command: { - schemaVersion: 1, - type: "project.update-settings", - payload: { - singlePhaseVoltageV: 240, - threePhaseVoltageV: 415, - }, - }, - }); - assert.deepEqual(getSettings(context), { - ...settings({ - singlePhaseVoltageV: 240, - threePhaseVoltageV: 415, - }), - currentRevision: 1, - }); - } finally { - context.close(); - } - }); - it("persists the project supply-type selection and rejects disabling an in-use type", () => { const context = createTestDatabase(); try { diff --git a/tests/project-snapshot.repository.test.ts b/tests/project-snapshot.repository.test.ts index d70dace..b062c68 100644 --- a/tests/project-snapshot.repository.test.ts +++ b/tests/project-snapshot.repository.test.ts @@ -172,18 +172,6 @@ function createTestDatabase(): DatabaseContext { return context; } -function removeVersionSevenFields(state: Record) { - delete state.distributionBoardComponents; - delete state.circuitProtectionDevices; - delete state.distributionBoardComponentProtectionDevices; - for (const section of state.circuitSections as Array< - Record - >) { - delete section.category; - delete section.groupNumber; - } -} - describe("project snapshot repository", () => { it("captures, hashes and lists a complete named logical snapshot", () => { const context = createTestDatabase(); @@ -354,41 +342,23 @@ describe("project snapshot repository", () => { ) as Record & { project: Record; }; - currentPayload.schemaVersion = 1; - removeVersionSevenFields(currentPayload); - delete currentPayload.project.internalProjectNumber; - delete currentPayload.project.externalProjectNumber; - delete currentPayload.project.buildingOwner; - delete currentPayload.project.description; - delete currentPayload.project.enabledDistributionBoardSupplyTypes; - for (const board of currentPayload.distributionBoards as Array< - Record - >) { - delete board.floorId; - delete board.supplyType; - delete board.simultaneityFactor; - } - const legacyPayloadJson = JSON.stringify(currentPayload); + currentPayload.schemaVersion = 99; + const unsupportedPayloadJson = JSON.stringify(currentPayload); context.db .update(projectSnapshots) .set({ - schemaVersion: 1, - payloadJson: legacyPayloadJson, + schemaVersion: 99, + payloadJson: unsupportedPayloadJson, payloadSha256: crypto .createHash("sha256") - .update(legacyPayloadJson) + .update(unsupportedPayloadJson) .digest("hex"), }) .where(eq(projectSnapshots.id, snapshot.id)) .run(); - const legacyPrepared = repository.prepareRestore( - "project-1", - snapshot.id - ); - assert.ok(legacyPrepared); - assert.equal( - legacyPrepared.command.payload.targetState.project.buildingOwner, - null + assert.throws( + () => repository.prepareRestore("project-1", snapshot.id), + /schema version is not supported/ ); context.db .update(projectSnapshots) @@ -474,10 +444,6 @@ describe("portable project transfer", () => { copied.state.distributionBoards[0].simultaneityFactor, 0.65 ); - assert.equal( - copied.state.circuits[0].deviceRows[0].legacyConsumerId, - null - ); } finally { context.close(); } @@ -512,52 +478,6 @@ describe("portable project transfer", () => { } }); - it("imports a checksum-valid version-two project transfer", () => { - const context = createTestDatabase(); - try { - const repository = new ProjectTransferRepository(context.db); - const current = repository.exportProject("project-1"); - assert.ok(current); - const legacyState = structuredClone( - current.projectState - ) as unknown as Record & { - distributionBoards: Array>; - }; - legacyState.schemaVersion = 2; - removeVersionSevenFields(legacyState); - delete ( - legacyState.project as Record - ).enabledDistributionBoardSupplyTypes; - for (const board of legacyState.distributionBoards) { - delete board.floorId; - delete board.supplyType; - delete board.simultaneityFactor; - } - const legacyPayloadJson = JSON.stringify(legacyState); - const duplicate = repository.importDuplicate({ - ...current, - projectState: legacyState, - payloadSha256: crypto - .createHash("sha256") - .update(legacyPayloadJson) - .digest("hex"), - }); - const copied = readProjectStateSnapshot( - context.db, - duplicate.projectId - ); - assert.ok(copied); - assert.equal(copied.state.distributionBoards[0].floorId, null); - assert.equal(copied.state.distributionBoards[0].supplyType, null); - assert.equal( - copied.state.distributionBoards[0].simultaneityFactor, - 1 - ); - } finally { - context.close(); - } - }); - it("rolls back a duplicate when a late project-state insert fails", () => { const context = createTestDatabase(); try { diff --git a/tests/project-state-restore-command.repository.test.ts b/tests/project-state-restore-command.repository.test.ts index b44d3c0..fff87e0 100644 --- a/tests/project-state-restore-command.repository.test.ts +++ b/tests/project-state-restore-command.repository.test.ts @@ -37,12 +37,9 @@ import { circuitLists } from "../src/db/schema/circuit-lists.js"; import { circuitProtectionDevices } from "../src/db/schema/circuit-protection-devices.js"; import { circuitSections } from "../src/db/schema/circuit-sections.js"; import { circuits } from "../src/db/schema/circuits.js"; -import { consumers } from "../src/db/schema/consumers.js"; import { distributionBoardComponentProtectionDevices } from "../src/db/schema/distribution-board-component-protection-devices.js"; import { distributionBoardComponents } from "../src/db/schema/distribution-board-components.js"; import { floors } from "../src/db/schema/floors.js"; -import { legacyConsumerCircuitMigrations } from "../src/db/schema/legacy-consumer-circuit-migrations.js"; -import { legacyConsumerMigrationReports } from "../src/db/schema/legacy-consumer-migration-report.js"; import { projectDevices } from "../src/db/schema/project-devices.js"; import { projectRevisions } from "../src/db/schema/project-revisions.js"; import { projectSnapshots } from "../src/db/schema/project-snapshots.js"; @@ -282,59 +279,6 @@ function changeCompleteProjectState(context: DatabaseContext) { ).createWithCircuitListAndDefaultSections("project-1", "UV-02"); } -function seedUpgradeOnlyData(context: DatabaseContext) { - const circuit = context.db - .select() - .from(circuits) - .where(eq(circuits.id, "circuit-1")) - .get(); - assert.ok(circuit); - context.db - .insert(consumers) - .values({ - id: "consumer-1", - projectId: "project-1", - distributionBoardId: - context.db.select().from(circuitLists).get()! - .distributionBoardId, - circuitListId: circuit.circuitListId, - projectDeviceId: "device-1", - roomId: "room-1", - name: "Legacy-Pumpe", - quantity: 1, - installedPowerPerUnitKw: 2.5, - demandFactor: 0.8, - }) - .run(); - context.db - .insert(legacyConsumerCircuitMigrations) - .values({ - consumerId: "consumer-1", - circuitId: "circuit-1", - circuitDeviceRowId: "row-1", - circuitListId: circuit.circuitListId, - createdAtIso: "2026-07-25T00:00:00.000Z", - }) - .run(); - context.db - .insert(legacyConsumerMigrationReports) - .values({ - id: "report-1", - circuitListId: circuit.circuitListId, - legacyConsumerCount: 1, - createdCircuitCount: 1, - createdDeviceRowCount: 1, - duplicateGroupedCount: 0, - generatedIdentifierCount: 0, - unassignedRowCount: 0, - warningsJson: "[]", - generatedIdentifiersJson: "[]", - duplicateGroupsJson: "[]", - createdAtIso: "2026-07-25T00:00:00.000Z", - }) - .run(); -} - describe("project state restore command", () => { it("undoes a remapped cross-project import using the persisted target hash", () => { const context = createTestDatabase(); @@ -360,7 +304,7 @@ describe("project state restore command", () => { description: "Projektimport wiederherstellen", command: prepared.command, }); - const legacyExpectedHash = hashProjectStatePayload( + const serializedExpectedHash = hashProjectStatePayload( serializeProjectStateSnapshot( prepared.command.payload.targetState ) @@ -372,7 +316,7 @@ describe("project state restore command", () => { .get(); assert.ok(storedChangeSet); const inverse = JSON.parse(storedChangeSet.inversePayloadJson); - inverse.payload.expectedStateSha256 = legacyExpectedHash; + inverse.payload.expectedStateSha256 = serializedExpectedHash; context.db .update(projectChangeSets) .set({ inversePayloadJson: JSON.stringify(inverse) }) @@ -397,7 +341,6 @@ describe("project state restore command", () => { const context = createTestDatabase(); try { const snapshots = new ProjectSnapshotRepository(context.db); - seedUpgradeOnlyData(context); const snapshot = snapshots.createNamed({ projectId: "project-1", expectedRevision: 0, @@ -443,28 +386,6 @@ describe("project state restore command", () => { context.db.select().from(projectSnapshots).all().length, 1 ); - assert.equal( - context.db - .select() - .from(legacyConsumerCircuitMigrations) - .all().length, - 1 - ); - assert.equal( - context.db - .select() - .from(legacyConsumerMigrationReports) - .all().length, - 1 - ); - assert.equal( - context.db - .select({ roomId: consumers.roomId }) - .from(consumers) - .where(eq(consumers.id, "consumer-1")) - .get()?.roomId, - "room-1" - ); const undone = service.undo({ projectId: "project-1", diff --git a/tests/project-state-snapshot.test.ts b/tests/project-state-snapshot.test.ts index 66aeb72..e408263 100644 --- a/tests/project-state-snapshot.test.ts +++ b/tests/project-state-snapshot.test.ts @@ -42,17 +42,6 @@ function minimalSnapshot() { }; } -function legacyMinimalSnapshot() { - const { - distributionBoardComponents: _distributionBoardComponents, - circuitProtectionDevices: _circuitProtectionDevices, - distributionBoardComponentProtectionDevices: - _distributionBoardComponentProtectionDevices, - ...snapshot - } = minimalSnapshot(); - return snapshot; -} - function protectedSnapshot() { return { ...minimalSnapshot(), @@ -94,9 +83,6 @@ function protectedSnapshot() { equipmentIdentifier: "-1F1.1", displayName: "Reserve", sortOrder: 10, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, cableType: null, cableCrossSection: null, cableLength: null, @@ -148,234 +134,26 @@ function protectedSnapshot() { } describe("project state snapshot model", () => { - it("round-trips a versioned logical project state", () => { + it("round-trips the current logical project state", () => { const snapshot = parseProjectStateSnapshot(minimalSnapshot()); assert.deepEqual( - deserializeProjectStateSnapshot( - serializeProjectStateSnapshot(snapshot) - ), + deserializeProjectStateSnapshot(serializeProjectStateSnapshot(snapshot)), snapshot ); }); - it("upgrades version-one snapshots with empty project metadata", () => { - const legacy = { - ...legacyMinimalSnapshot(), - schemaVersion: 1 as const, - project: { - id: "project-1", - name: "Altprojekt", - singlePhaseVoltageV: 230, - threePhaseVoltageV: 400, - }, - }; - const snapshot = parseProjectStateSnapshot(legacy); - assert.equal(snapshot.schemaVersion, projectStateSnapshotSchemaVersion); - assert.deepEqual(snapshot.project, { - ...legacy.project, - internalProjectNumber: null, - externalProjectNumber: null, - buildingOwner: null, - description: null, - enabledDistributionBoardSupplyTypes: [ - "AV", - "SV", - "EV", - "USV", - "MSR", - "SiBe", - ], - }); - }); - - it("upgrades version-two distribution boards without inferred assignments", () => { - const previous = { - ...legacyMinimalSnapshot(), - schemaVersion: 2 as const, - project: { - ...minimalSnapshot().project, - enabledDistributionBoardSupplyTypes: undefined, - }, - distributionBoards: [ - { - id: "board-1", - projectId: "project-1", - name: "UV 1", - }, - ], - }; - delete previous.project.enabledDistributionBoardSupplyTypes; - const snapshot = parseProjectStateSnapshot(previous); - assert.deepEqual(snapshot.distributionBoards, [ - { - ...previous.distributionBoards[0], - floorId: null, - supplyType: null, - simultaneityFactor: 1, - }, - ]); - }); - - it("upgrades version-three snapshots with all project supply types", () => { - const previous = { - ...legacyMinimalSnapshot(), - schemaVersion: 3 as const, - project: { - ...minimalSnapshot().project, - enabledDistributionBoardSupplyTypes: undefined, - }, - }; - delete previous.project.enabledDistributionBoardSupplyTypes; - const snapshot = parseProjectStateSnapshot(previous); - assert.deepEqual(snapshot.project.enabledDistributionBoardSupplyTypes, [ - "AV", - "SV", - "EV", - "USV", - "MSR", - "SiBe", - ]); - }); - - it("normalizes version-four device voltages to project settings", () => { - const previous = { - ...legacyMinimalSnapshot(), - schemaVersion: 4 as const, - projectDevices: [ - { - id: "device-1", - projectId: "project-1", - name: "Pumpe", - displayName: "Pumpe", - phaseType: "three_phase" as const, - connectionKind: null, - costGroup: null, - category: null, - quantity: 1, - powerPerUnit: 2, - simultaneityFactor: 1, - cosPhi: null, - remark: null, - voltageV: 500, - }, - ], - }; - - const snapshot = parseProjectStateSnapshot(previous); - - assert.equal(snapshot.schemaVersion, projectStateSnapshotSchemaVersion); - assert.equal(snapshot.projectDevices[0]?.voltageV, 400); - }); - - it("upgrades version-five distribution boards with a neutral factor", () => { - const previous = { - ...legacyMinimalSnapshot(), - schemaVersion: 5 as const, - distributionBoards: [ - { - id: "board-1", - projectId: "project-1", - name: "UV 1", - floorId: null, - supplyType: "AV" as const, - }, - ], - }; - - const snapshot = parseProjectStateSnapshot(previous); - - assert.equal(snapshot.schemaVersion, projectStateSnapshotSchemaVersion); - assert.equal( - snapshot.distributionBoards[0]?.simultaneityFactor, - 1 + it("rejects pre-baseline snapshot shapes", () => { + const outdated = structuredClone(minimalSnapshot()); + delete (outdated.project as Record).description; + assert.throws(() => parseProjectStateSnapshot(outdated)); + assert.throws(() => + parseProjectStateSnapshot({ ...minimalSnapshot(), schemaVersion: 7 }) ); }); - it("upgrades version-six sections without inventing component data", () => { - const previous = { - ...legacyMinimalSnapshot(), - schemaVersion: 6 as const, - circuitSections: [ - { - id: "section-lighting", - circuitListId: "list-1", - key: "lighting", - displayName: "Beleuchtung", - prefix: "-1F", - sortOrder: 10, - }, - { - id: "section-unassigned", - circuitListId: "list-1", - key: "unassigned", - displayName: "Nicht zugeordnet", - prefix: "-UF", - sortOrder: 90, - }, - ], - distributionBoards: [ - { - id: "board-1", - projectId: "project-1", - name: "UV 1", - floorId: null, - supplyType: null, - simultaneityFactor: 1, - }, - ], - circuitLists: [ - { - id: "list-1", - projectId: "project-1", - distributionBoardId: "board-1", - name: "UV 1 Stromkreisliste", - }, - ], - }; - - const snapshot = parseProjectStateSnapshot(previous); - - assert.deepEqual( - snapshot.circuitSections.map( - ({ key, category, groupNumber }) => ({ - key, - category, - groupNumber, - }) - ), - [ - { - key: "lighting", - category: "lighting", - groupNumber: 1, - }, - { - key: "unassigned", - category: null, - groupNumber: null, - }, - ] - ); - assert.deepEqual(snapshot.distributionBoardComponents, []); - assert.deepEqual(snapshot.circuitProtectionDevices, []); - assert.deepEqual( - snapshot.distributionBoardComponentProtectionDevices, - [] - ); - }); - - it("validates the complete group, component and protection graph", () => { + it("validates component, protection and equipment relations", () => { const snapshot = parseProjectStateSnapshot(protectedSnapshot()); - - assert.equal(snapshot.circuitSections[0]?.groupNumber, 1); - assert.equal( - snapshot.distributionBoardComponents[0]?.sectionId, - "section-1" - ); - assert.equal( - snapshot.circuitProtectionDevices[0]?.tripCharacteristic, - "B" - ); + assert.equal(snapshot.circuitProtectionDevices[0]?.tripCharacteristic, "B"); assert.equal( snapshot.distributionBoardComponentProtectionDevices[0] ?.ratedResidualCurrentMa, @@ -401,113 +179,27 @@ describe("project state snapshot model", () => { ); }); - it("rejects duplicate ids and cross-project ownership", () => { + it("rejects duplicate ids and invalid ownership", () => { + const duplicate = protectedSnapshot(); + duplicate.distributionBoards.push({ + ...duplicate.distributionBoards[0]!, + name: "UV 2", + }); assert.throws( - () => - parseProjectStateSnapshot({ - ...minimalSnapshot(), - distributionBoards: [ - { - id: "board-1", - projectId: "project-1", - name: "UV 1", - floorId: null, - supplyType: null, - simultaneityFactor: 1, - }, - { - id: "board-1", - projectId: "project-1", - name: "UV 2", - floorId: null, - supplyType: null, - simultaneityFactor: 1, - }, - ], - }), + () => parseProjectStateSnapshot(duplicate), /duplicate distribution board ids/ ); - assert.throws( - () => - parseProjectStateSnapshot({ - ...minimalSnapshot(), - floors: [ - { - id: "floor-1", - projectId: "project-2", - name: "EG", - sortOrder: 10, - }, - ], - }), - /floor belongs to a different project/ - ); - }); - it("rejects invalid references and inconsistent reserve circuits", () => { + const wrongOwner = minimalSnapshot(); + wrongOwner.floors.push({ + id: "floor-1", + projectId: "project-2", + name: "EG", + sortOrder: 10, + }); assert.throws( - () => - parseProjectStateSnapshot({ - ...minimalSnapshot(), - distributionBoards: [ - { - id: "board-1", - projectId: "project-1", - name: "UV 1", - floorId: "missing", - supplyType: "AV", - simultaneityFactor: 1, - }, - ], - }), - /distribution board floor reference is invalid/ - ); - assert.throws( - () => - parseProjectStateSnapshot({ - ...minimalSnapshot(), - rooms: [ - { - id: "room-1", - projectId: "project-1", - floorId: "missing", - roomNumber: "001", - roomName: "Technik", - }, - ], - }), - /room floor reference is invalid/ - ); - assert.throws( - () => - parseProjectStateSnapshot({ - ...minimalSnapshot(), - circuits: [ - { - id: "circuit-1", - circuitListId: "missing", - sectionId: "missing", - equipmentIdentifier: "-1F1", - displayName: null, - sortOrder: 10, - protectionType: null, - protectionRatedCurrent: null, - protectionCharacteristic: null, - cableType: null, - cableCrossSection: null, - cableLength: null, - rcdAssignment: null, - terminalDesignation: null, - voltage: null, - controlRequirement: null, - status: null, - isReserve: true, - remark: null, - deviceRows: [], - }, - ], - }), - /circuit list reference is invalid/ + () => parseProjectStateSnapshot(wrongOwner), + /floor belongs to a different project/ ); }); }); @@ -518,36 +210,29 @@ describe("named project snapshot request", () => { createNamedProjectSnapshotSchema.parse({ expectedRevision: 12, name: " Freigabe ", - description: " Stand vor Ausschreibung ", + description: " Stand vor Änderung ", }), { expectedRevision: 12, name: "Freigabe", - description: "Stand vor Ausschreibung", + description: "Stand vor Änderung", } ); }); it("rejects stale-shaped and excessive input", () => { - for (const input of [ - { expectedRevision: -1, name: "Stand" }, - { expectedRevision: 0, name: " " }, - { expectedRevision: 0, name: "x".repeat(101) }, - { - expectedRevision: 0, - name: "Stand", - description: "x".repeat(501), - }, - { - expectedRevision: 0, - name: "Stand", + assert.throws(() => + createNamedProjectSnapshotSchema.parse({ + expectedRevision: -1, + name: "", unexpected: true, - }, - ]) { - assert.equal( - createNamedProjectSnapshotSchema.safeParse(input).success, - false - ); - } + }) + ); + assert.throws(() => + createNamedProjectSnapshotSchema.parse({ + expectedRevision: 0, + name: "x".repeat(201), + }) + ); }); });