@bslau/hmm_prisma_schema 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/prisma/migrations/20250611031241_entity_relationship_torpedo_state_and_event_torpedo_movement/migration.sql +23 -0
- package/prisma/schema.prisma +18 -16
- package/prisma/seed.ts +60 -3
- /package/prisma/migrations/{20250610015905_changing_naming_convention → 20250610041601_notification_display_mode_naming_convention_and_required_field}/migration.sql +0 -0
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
BEGIN TRY
|
|
2
|
+
|
|
3
|
+
BEGIN TRAN;
|
|
4
|
+
|
|
5
|
+
-- AlterTable
|
|
6
|
+
ALTER TABLE [dbo].[EventTorpedoMovement] DROP CONSTRAINT [EventTorpedoMovement_torpedoStateId_df];
|
|
7
|
+
ALTER TABLE [dbo].[EventTorpedoMovement] ALTER COLUMN [torpedoStateId] INT NULL;
|
|
8
|
+
|
|
9
|
+
-- AddForeignKey
|
|
10
|
+
ALTER TABLE [dbo].[EventTorpedoMovement] ADD CONSTRAINT [EventTorpedoMovement_torpedoStateId_fkey] FOREIGN KEY ([torpedoStateId]) REFERENCES [dbo].[TorpedoState]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
|
|
11
|
+
|
|
12
|
+
COMMIT TRAN;
|
|
13
|
+
|
|
14
|
+
END TRY
|
|
15
|
+
BEGIN CATCH
|
|
16
|
+
|
|
17
|
+
IF @@TRANCOUNT > 0
|
|
18
|
+
BEGIN
|
|
19
|
+
ROLLBACK TRAN;
|
|
20
|
+
END;
|
|
21
|
+
THROW
|
|
22
|
+
|
|
23
|
+
END CATCH
|
package/prisma/schema.prisma
CHANGED
|
@@ -101,7 +101,6 @@ model EventTorpedoMovement {
|
|
|
101
101
|
id Int @id @default(autoincrement())
|
|
102
102
|
torpedoId Int
|
|
103
103
|
torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId])
|
|
104
|
-
torpedoStateId Int @default(0)
|
|
105
104
|
eventTime DateTime @db.DateTimeOffset
|
|
106
105
|
originStation Station @relation(name: "originStation-movement", fields: [originStationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
|
|
107
106
|
originStationId Int
|
|
@@ -118,6 +117,8 @@ model EventTorpedoMovement {
|
|
|
118
117
|
torpedoCycleId Int?
|
|
119
118
|
torpedoTrip TorpedoTrip? @relation(fields: [torpedoTripId], references: [id])
|
|
120
119
|
torpedoTripId Int?
|
|
120
|
+
torpedoState TorpedoState? @relation(fields: [torpedoStateId], references: [id], onDelete: NoAction, onUpdate: NoAction)
|
|
121
|
+
torpedoStateId Int?
|
|
121
122
|
createdAt DateTime @default(now())
|
|
122
123
|
updatedAt DateTime @updatedAt
|
|
123
124
|
}
|
|
@@ -436,11 +437,12 @@ model TorpedoLocation {
|
|
|
436
437
|
///
|
|
437
438
|
/// Describes a valid operational _State_ that a _Torpedo_ can be assigned.
|
|
438
439
|
model TorpedoState {
|
|
439
|
-
id
|
|
440
|
-
name
|
|
441
|
-
label
|
|
442
|
-
description
|
|
443
|
-
torpedoes
|
|
440
|
+
id Int @id @default(autoincrement())
|
|
441
|
+
name String @unique
|
|
442
|
+
label String
|
|
443
|
+
description String
|
|
444
|
+
torpedoes Torpedo[]
|
|
445
|
+
eventsTorpedoMovement EventTorpedoMovement[]
|
|
444
446
|
}
|
|
445
447
|
|
|
446
448
|
/// **TORPEDO TRIP (ON LINING)**
|
|
@@ -498,11 +500,11 @@ model NotificationCategory {
|
|
|
498
500
|
///
|
|
499
501
|
/// These display modes define how these notifications are displayed to the User
|
|
500
502
|
model NotificationDisplay {
|
|
501
|
-
id
|
|
502
|
-
displayModeId
|
|
503
|
-
|
|
504
|
-
notification
|
|
505
|
-
notificationId
|
|
503
|
+
id Int @id @default(autoincrement())
|
|
504
|
+
displayModeId Int
|
|
505
|
+
notificationDisplayMode NotificationDisplayMode @relation(fields: [displayModeId], references: [id])
|
|
506
|
+
notification Notification @relation(fields: [notificationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
|
|
507
|
+
notificationId Int
|
|
506
508
|
// status Boolean @default(false) NOTES: Probably add something like this later to check for example if a notification has been acknowledged by the user
|
|
507
509
|
}
|
|
508
510
|
|
|
@@ -510,11 +512,11 @@ model NotificationDisplay {
|
|
|
510
512
|
///
|
|
511
513
|
/// These are the Defined Display Modes available to the HMM Application
|
|
512
514
|
model NotificationDisplayMode {
|
|
513
|
-
id
|
|
514
|
-
name
|
|
515
|
-
label
|
|
516
|
-
description
|
|
517
|
-
|
|
515
|
+
id Int @id @default(autoincrement())
|
|
516
|
+
name String @unique
|
|
517
|
+
label String
|
|
518
|
+
description String
|
|
519
|
+
notificationDisplays NotificationDisplay[]
|
|
518
520
|
}
|
|
519
521
|
|
|
520
522
|
/// ** HMM Notification Source **
|
package/prisma/seed.ts
CHANGED
|
@@ -2,6 +2,63 @@ import _ from "underscore";
|
|
|
2
2
|
import prisma from "./dbClient";
|
|
3
3
|
|
|
4
4
|
async function main() {
|
|
5
|
+
// SEED: Torpedos
|
|
6
|
+
if ((await prisma.torpedo.count()) > 0) {
|
|
7
|
+
console.log("SEED: Torpedo - skipped.");
|
|
8
|
+
} else {
|
|
9
|
+
console.log("SEED: Torpedo - generating...");
|
|
10
|
+
|
|
11
|
+
const createTorpedo =
|
|
12
|
+
await prisma.torpedo.createMany({
|
|
13
|
+
data: [
|
|
14
|
+
{ torpedoId: 18, name: "Torpedo 18", status: 2 },
|
|
15
|
+
{ torpedoId: 19, name: "Torpedo 19", status: 2 },
|
|
16
|
+
{ torpedoId: 20, name: "Torpedo 20", status: 2 },
|
|
17
|
+
{ torpedoId: 21, name: "Torpedo 21", status: 2 },
|
|
18
|
+
{ torpedoId: 22, name: "Torpedo 22", status: 2 },
|
|
19
|
+
{ torpedoId: 23, name: "Torpedo 23", status: 2 },
|
|
20
|
+
{ torpedoId: 24, name: "Torpedo 24", status: 2 },
|
|
21
|
+
{ torpedoId: 25, name: "Torpedo 25", status: 2 },
|
|
22
|
+
{ torpedoId: 27, name: "Torpedo 27", status: 2 },
|
|
23
|
+
{ torpedoId: 28, name: "Torpedo 28", status: 2 },
|
|
24
|
+
{ torpedoId: 29, name: "Torpedo 29", status: 2 },
|
|
25
|
+
{ torpedoId: 30, name: "Torpedo 30", status: 2 },
|
|
26
|
+
{ torpedoId: 31, name: "Torpedo 31", status: 2 },
|
|
27
|
+
{ torpedoId: 32, name: "Torpedo 32", status: 2 },
|
|
28
|
+
{ torpedoId: 33, name: "Torpedo 33", status: 2 },
|
|
29
|
+
{ torpedoId: 34, name: "Torpedo 34", status: 2 },
|
|
30
|
+
{ torpedoId: 35, name: "Torpedo 35", status: 2 },
|
|
31
|
+
{ torpedoId: 36, name: "Torpedo 36", status: 2 },
|
|
32
|
+
{ torpedoId: 37, name: "Torpedo 37", status: 2 },
|
|
33
|
+
{ torpedoId: 38, name: "Torpedo 38", status: 2 },
|
|
34
|
+
{ torpedoId: 39, name: "Torpedo 39", status: 2 },
|
|
35
|
+
{ torpedoId: 40, name: "Torpedo 40", status: 2 },
|
|
36
|
+
{ torpedoId: 41, name: "Torpedo 41", status: 2 },
|
|
37
|
+
{ torpedoId: 42, name: "Torpedo 42", status: 2 },
|
|
38
|
+
{ torpedoId: 43, name: "Torpedo 43", status: 2 },
|
|
39
|
+
{ torpedoId: 44, name: "Torpedo 44", status: 2 },
|
|
40
|
+
{ torpedoId: 45, name: "Torpedo 45", status: 2 },
|
|
41
|
+
{ torpedoId: 46, name: "Torpedo 46", status: 2 },
|
|
42
|
+
{ torpedoId: 47, name: "Torpedo 47", status: 2 },
|
|
43
|
+
{ torpedoId: 48, name: "Torpedo 48", status: 2 },
|
|
44
|
+
{ torpedoId: 49, name: "Torpedo 49", status: 2 },
|
|
45
|
+
{ torpedoId: 50, name: "Torpedo 50", status: 2 },
|
|
46
|
+
{ torpedoId: 51, name: "Torpedo 51", status: 2 },
|
|
47
|
+
{ torpedoId: 52, name: "Torpedo 52", status: 2 },
|
|
48
|
+
{ torpedoId: 54, name: "Torpedo 54", status: 2 },
|
|
49
|
+
{ torpedoId: 55, name: "Torpedo 55", status: 2 },
|
|
50
|
+
{ torpedoId: 56, name: "Torpedo 56", status: 2 },
|
|
51
|
+
{ torpedoId: 57, name: "Torpedo 57", status: 2 },
|
|
52
|
+
{ torpedoId: 58, name: "Torpedo 58", status: 2 },
|
|
53
|
+
{ torpedoId: 60, name: "Torpedo 60", status: 2 },
|
|
54
|
+
],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
console.log({
|
|
58
|
+
createTorpedo,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
5
62
|
// SEED: Station
|
|
6
63
|
if ((await prisma.station.count()) > 0) {
|
|
7
64
|
console.log("SEED: Station - skipped.");
|
|
@@ -528,7 +585,7 @@ async function main() {
|
|
|
528
585
|
for (let i: number = 0; i < remainingTorpedoes.length; i++) {
|
|
529
586
|
const randomLocation = await prisma.torpedoLocation.create({
|
|
530
587
|
data: {
|
|
531
|
-
stationId:
|
|
588
|
+
stationId: stationList[0].id,
|
|
532
589
|
position: 2 + i,
|
|
533
590
|
torpedoId: remainingTorpedoes[i].torpedoId,
|
|
534
591
|
locationId: stationList[0].locations[0].id,
|
|
@@ -650,9 +707,9 @@ async function main() {
|
|
|
650
707
|
|
|
651
708
|
// SEED: NotificationDisplay
|
|
652
709
|
if ((await prisma.notificationDisplayMode.count()) > 0) {
|
|
653
|
-
console.log("SEED:
|
|
710
|
+
console.log("SEED: NotificationDisplayMode - skipped.");
|
|
654
711
|
} else {
|
|
655
|
-
console.log("SEED:
|
|
712
|
+
console.log("SEED: NotificationDisplayMode - generating...");
|
|
656
713
|
|
|
657
714
|
const createDisplayMode = await prisma.notificationDisplayMode.createMany({
|
|
658
715
|
data: [
|