@bslau/hmm_prisma_schema 1.1.16 → 1.1.18

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bslau/hmm_prisma_schema",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "main": "index.js",
5
5
  "author": "CIPA Development Team",
6
6
  "license": "ISC",
@@ -0,0 +1,19 @@
1
+ BEGIN TRY
2
+
3
+ BEGIN TRAN;
4
+
5
+ -- AlterTable
6
+ ALTER TABLE [dbo].[Station] ADD [test] NVARCHAR(1000);
7
+
8
+ COMMIT TRAN;
9
+
10
+ END TRY
11
+ BEGIN CATCH
12
+
13
+ IF @@TRANCOUNT > 0
14
+ BEGIN
15
+ ROLLBACK TRAN;
16
+ END;
17
+ THROW
18
+
19
+ END CATCH
@@ -0,0 +1,25 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `test` on the `Station` table. All the data in the column will be lost.
5
+
6
+ */
7
+ BEGIN TRY
8
+
9
+ BEGIN TRAN;
10
+
11
+ -- AlterTable
12
+ ALTER TABLE [dbo].[Station] DROP COLUMN [test];
13
+
14
+ COMMIT TRAN;
15
+
16
+ END TRY
17
+ BEGIN CATCH
18
+
19
+ IF @@TRANCOUNT > 0
20
+ BEGIN
21
+ ROLLBACK TRAN;
22
+ END;
23
+ THROW
24
+
25
+ END CATCH
@@ -0,0 +1,32 @@
1
+ BEGIN TRY
2
+
3
+ BEGIN TRAN;
4
+
5
+ -- AlterTable
6
+ ALTER TABLE [dbo].[Torpedo] ADD [torpedoStateId] INT;
7
+
8
+ -- CreateTable
9
+ CREATE TABLE [dbo].[TorpedoState] (
10
+ [id] INT NOT NULL IDENTITY(1,1),
11
+ [name] NVARCHAR(1000) NOT NULL,
12
+ [label] NVARCHAR(1000) NOT NULL,
13
+ [description] NVARCHAR(1000) NOT NULL,
14
+ CONSTRAINT [TorpedoState_pkey] PRIMARY KEY CLUSTERED ([id]),
15
+ CONSTRAINT [TorpedoState_name_key] UNIQUE NONCLUSTERED ([name])
16
+ );
17
+
18
+ -- AddForeignKey
19
+ ALTER TABLE [dbo].[Torpedo] ADD CONSTRAINT [Torpedo_torpedoStateId_fkey] FOREIGN KEY ([torpedoStateId]) REFERENCES [dbo].[TorpedoState]([id]) ON DELETE SET NULL ON UPDATE CASCADE;
20
+
21
+ COMMIT TRAN;
22
+
23
+ END TRY
24
+ BEGIN CATCH
25
+
26
+ IF @@TRANCOUNT > 0
27
+ BEGIN
28
+ ROLLBACK TRAN;
29
+ END;
30
+ THROW
31
+
32
+ END CATCH
@@ -0,0 +1,21 @@
1
+ BEGIN TRY
2
+
3
+ BEGIN TRAN;
4
+
5
+ -- AlterTable
6
+ ALTER TABLE [dbo].[HotMetal] ADD [BF6WeighBridgeWeight] INT,
7
+ [consumedBy] NVARCHAR(1000),
8
+ [consumedByDate] DATETIMEOFFSET;
9
+
10
+ COMMIT TRAN;
11
+
12
+ END TRY
13
+ BEGIN CATCH
14
+
15
+ IF @@TRANCOUNT > 0
16
+ BEGIN
17
+ ROLLBACK TRAN;
18
+ END;
19
+ THROW
20
+
21
+ END CATCH
@@ -53,6 +53,44 @@ model Cast {
53
53
  hotMetalCollection HotMetal[]
54
54
  }
55
55
 
56
+ model EventTorpedoMovement {
57
+ id Int @id @default(autoincrement())
58
+ torpedoId Int
59
+ torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId])
60
+ eventTime DateTime @db.DateTimeOffset
61
+ originStation Station @relation(name: "originStation-movement", fields: [originStationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
62
+ originStationId Int
63
+ originLocation Location @relation(name: "originLocation-movement", fields: [originLocationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
64
+ originLocationId Int
65
+ destinationStation Station @relation(name: "destinationStation-movement", fields: [destinationStationId], references: [id], onDelete: NoAction, onUpdate: NoAction)
66
+ destinationStationId Int
67
+ destinationLocation Location @relation(name: "destinationLocation-movement", fields: [destinationLocationId], references: [id], onDelete: NoAction, onUpdate: NoAction)
68
+ destinationLocationId Int
69
+ event EventTracker @relation(fields: [eventId], references: [id])
70
+ eventId Int @unique
71
+ userId String?
72
+ createdAt DateTime @default(now())
73
+ updatedAt DateTime @updatedAt
74
+ }
75
+
76
+ model EventTracker {
77
+ id Int @id @default(autoincrement())
78
+ eventTime DateTime @db.DateTimeOffset
79
+ eventType String
80
+ userId String?
81
+ torpedoMovement EventTorpedoMovement?
82
+ }
83
+
84
+ model HMHComment {
85
+ id Int @id @default(autoincrement())
86
+ torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId], onDelete: NoAction, onUpdate: Cascade)
87
+ torpedoId Int
88
+ comment String
89
+ isRemoved Boolean @default(false)
90
+ createdAt DateTime @default(now())
91
+ updatedAt DateTime? @updatedAt
92
+ }
93
+
56
94
  model HotMetal {
57
95
  id Int @id @default(autoincrement())
58
96
  mesId Int?
@@ -66,6 +104,9 @@ model HotMetal {
66
104
  identityBlastFurnace Int
67
105
  noPosnTldlTapHole Int
68
106
  temperatureHotMetal Int?
107
+ BF6WeighBridgeWeight Int?
108
+ consumedBy String?
109
+ consumedByDate DateTime? @db.DateTimeOffset
69
110
  dpLevelTldlAuto Int?
70
111
  dpLevelTldlManual Int?
71
112
  capacity Int?
@@ -113,48 +154,6 @@ model HotMetal {
113
154
  @@unique(name: "cast_torpedo_id", [castSequence, torpedoId])
114
155
  }
115
156
 
116
- model Torpedo {
117
- id Int @id @default(autoincrement())
118
- torpedoId Int @unique(sort: Desc)
119
- name String?
120
- description String?
121
- futureLocation String?
122
- addAlPucksFlag Boolean @default(false)
123
- heatUpFlag Boolean @default(false)
124
- heatUpStartTime DateTime? @db.DateTimeOffset
125
- onGasFlag Boolean @default(false)
126
- onGasEndDate DateTime? @db.DateTimeOffset
127
- hmhSixPitRestrictionFlag Boolean @default(false)
128
- sixPitRestrictionFlag Boolean @default(false)
129
- sixPitRestrictionEndTime DateTime? @db.DateTimeOffset
130
- status Int @default(2)
131
- // sixPitStart DateTime?
132
- // capacityDynamic Float?
133
- // capacityNominal Float?
134
- // comments String?
135
- // emptyWeight Float?
136
- // gasStart DateTime?
137
- hotMetalCollection HotMetal[]
138
- torpedoLocation TorpedoLocation?
139
- torpedoComments TorpedoComment[]
140
- hmhComments HMHComment[]
141
- eventsTorpedoMovement EventTorpedoMovement[]
142
- createdAt DateTime @default(now())
143
- updatedAt DateTime @updatedAt
144
- }
145
-
146
- model Station {
147
- id Int @id @default(autoincrement())
148
- name String
149
- value String @unique
150
- createdAt DateTime @default(now())
151
- updatedAt DateTime @updatedAt
152
- torpedoLocations TorpedoLocation[]
153
- locations Location[]
154
- eventsTorpedoMovementOrigin EventTorpedoMovement[] @relation(name: "originStation-movement")
155
- eventsTorpedoMovementDestination EventTorpedoMovement[] @relation(name: "destinationStation-movement")
156
- }
157
-
158
157
  model HotMetalLabResult {
159
158
  id Int @id @default(autoincrement())
160
159
  testSampleId String @unique(sort: Desc)
@@ -190,18 +189,48 @@ model Location {
190
189
  torpedoLocations TorpedoLocation[]
191
190
  }
192
191
 
193
- model TorpedoLocation {
194
- stationId Int
195
- station Station @relation(fields: [stationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
196
- position Int
197
- torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId], onDelete: NoAction, onUpdate: Cascade)
198
- torpedoId Int @unique
199
- locationId Int
200
- location Location @relation(fields: [locationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
201
- createdAt DateTime @default(now())
202
- updatedAt DateTime @updatedAt
192
+ model Station {
193
+ id Int @id @default(autoincrement())
194
+ name String
195
+ value String @unique
196
+ createdAt DateTime @default(now())
197
+ updatedAt DateTime @updatedAt
198
+ torpedoLocations TorpedoLocation[]
199
+ locations Location[]
200
+ eventsTorpedoMovementOrigin EventTorpedoMovement[] @relation(name: "originStation-movement")
201
+ eventsTorpedoMovementDestination EventTorpedoMovement[] @relation(name: "destinationStation-movement")
202
+ }
203
203
 
204
- @@id([stationId, position])
204
+ model Torpedo {
205
+ id Int @id @default(autoincrement())
206
+ torpedoId Int @unique(sort: Desc)
207
+ name String?
208
+ description String?
209
+ futureLocation String?
210
+ addAlPucksFlag Boolean @default(false)
211
+ heatUpFlag Boolean @default(false)
212
+ heatUpStartTime DateTime? @db.DateTimeOffset
213
+ onGasFlag Boolean @default(false)
214
+ onGasEndDate DateTime? @db.DateTimeOffset
215
+ hmhSixPitRestrictionFlag Boolean @default(false)
216
+ sixPitRestrictionFlag Boolean @default(false)
217
+ sixPitRestrictionEndTime DateTime? @db.DateTimeOffset
218
+ status Int @default(2)
219
+ // sixPitStart DateTime?
220
+ // capacityDynamic Float?
221
+ // capacityNominal Float?
222
+ // comments String?
223
+ // emptyWeight Float?
224
+ // gasStart DateTime?
225
+ hotMetalCollection HotMetal[]
226
+ torpedoLocation TorpedoLocation?
227
+ torpedoComments TorpedoComment[]
228
+ hmhComments HMHComment[]
229
+ eventsTorpedoMovement EventTorpedoMovement[]
230
+ torpedoState TorpedoState? @relation(fields: [torpedoStateId], references: [id])
231
+ torpedoStateId Int?
232
+ createdAt DateTime @default(now())
233
+ updatedAt DateTime @updatedAt
205
234
  }
206
235
 
207
236
  model TorpedoComment {
@@ -214,40 +243,24 @@ model TorpedoComment {
214
243
  updatedAt DateTime? @updatedAt
215
244
  }
216
245
 
217
- model HMHComment {
218
- id Int @id @default(autoincrement())
219
- torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId], onDelete: NoAction, onUpdate: Cascade)
220
- torpedoId Int
221
- comment String
222
- isRemoved Boolean @default(false)
223
- createdAt DateTime @default(now())
224
- updatedAt DateTime? @updatedAt
225
- }
246
+ model TorpedoLocation {
247
+ stationId Int
248
+ station Station @relation(fields: [stationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
249
+ position Int
250
+ torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId], onDelete: NoAction, onUpdate: Cascade)
251
+ torpedoId Int @unique
252
+ locationId Int
253
+ location Location @relation(fields: [locationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
254
+ createdAt DateTime @default(now())
255
+ updatedAt DateTime @updatedAt
226
256
 
227
- model EventTracker {
228
- id Int @id @default(autoincrement())
229
- eventTime DateTime @db.DateTimeOffset
230
- eventType String
231
- userId String?
232
- torpedoMovement EventTorpedoMovement?
257
+ @@id([stationId, position])
233
258
  }
234
259
 
235
- model EventTorpedoMovement {
236
- id Int @id @default(autoincrement())
237
- torpedoId Int
238
- torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId])
239
- eventTime DateTime @db.DateTimeOffset
240
- originStation Station @relation(name: "originStation-movement", fields: [originStationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
241
- originStationId Int
242
- originLocation Location @relation(name: "originLocation-movement", fields: [originLocationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
243
- originLocationId Int
244
- destinationStation Station @relation(name: "destinationStation-movement", fields: [destinationStationId], references: [id], onDelete: NoAction, onUpdate: NoAction)
245
- destinationStationId Int
246
- destinationLocation Location @relation(name: "destinationLocation-movement", fields: [destinationLocationId], references: [id], onDelete: NoAction, onUpdate: NoAction)
247
- destinationLocationId Int
248
- event EventTracker @relation(fields: [eventId], references: [id])
249
- eventId Int @unique
250
- userId String?
251
- createdAt DateTime @default(now())
252
- updatedAt DateTime @updatedAt
260
+ model TorpedoState {
261
+ id Int @id @default(autoincrement())
262
+ name String @unique
263
+ label String
264
+ description String
265
+ torpedoes Torpedo[]
253
266
  }
package/prisma/seed.ts CHANGED
@@ -1,537 +1,567 @@
1
-
2
1
  import _ from "underscore";
3
2
  import prisma from "./dbClient";
4
3
 
5
4
  async function main() {
6
- const createHolding = await prisma.station.create({
7
- data: {
8
- value: "HOLDING",
9
- name: "Holding",
10
- locations: {
11
- connectOrCreate: [
12
- {
13
- where: {
14
- value: "WPR",
15
- },
16
- create: {
17
- value: "WPR",
18
- name: "Woodpecker Repair Lines",
5
+ // SEED: Station
6
+ if (await prisma.station.count() > 0) {
7
+ console.log("SEED: Station - skipped.");
8
+ } else {
9
+ console.log("SEED: Station - generating...");
19
10
 
20
- }
21
- },
22
- {
23
- where: {
24
- value: "5OL",
25
- },
26
- create: {
27
- value: "5OL",
28
- name: "5 Outside Loop",
29
- }
30
- },
31
- {
32
- where: {
33
- value: "5BF",
34
- },
35
- create: {
36
- value: "5BF",
37
- name: "5 Blast Furnace",
38
- }
39
- },
40
- {
41
- where: {
42
- value: "OPM",
43
- },
44
- create: {
45
- value: "OPM",
46
- name: "Old Plug Mill",
47
- }
48
- },
49
- {
50
- where: {
51
- value: "XOVR",
52
- },
53
- create: {
54
- value: "XOVR",
55
- name: "Short Cross Over",
56
- }
57
- },
58
- {
59
- where: {
60
- value: "5ML",
61
- },
62
- create: {
63
- value: "5ML",
64
- name: "5 BF Middle Loop",
65
- }
66
- },
67
- {
68
- where: {
69
- value: "6BF",
70
- },
71
- create: {
72
- value: "6BF",
73
- name: "6 Blast Furnace",
74
- }
75
- },
76
- {
77
- where: {
78
- value: "DSML",
79
- },
80
- create: {
81
- value: "DSML",
82
- name: "Desulph Main Line",
83
- }
84
- },
85
- ],
86
- }
87
- }
88
- })
89
- const create5BFE = await prisma.station.create({
90
- data: {
91
- value: "5BFE",
92
- name: "5 Blast Furnace - East",
93
- locations: {
94
- connectOrCreate: [
95
- {
96
- where: {
97
- value: "5BFE",
98
- },
99
- create:
100
- {
101
- value: "5BFE",
102
- name: "5 Blast Furnace - East",
103
- }
104
- },
105
- ]
11
+ const createHolding = await prisma.station.create({
12
+ data: {
13
+ value: "HOLDING",
14
+ name: "Holding",
15
+ locations: {
16
+ connectOrCreate: [
17
+ {
18
+ where: {
19
+ value: "WPR",
20
+ },
21
+ create: {
22
+ value: "WPR",
23
+ name: "Woodpecker Repair Lines",
106
24
 
25
+ }
26
+ },
27
+ {
28
+ where: {
29
+ value: "5OL",
30
+ },
31
+ create: {
32
+ value: "5OL",
33
+ name: "5 Outside Loop",
34
+ }
35
+ },
36
+ {
37
+ where: {
38
+ value: "5BF",
39
+ },
40
+ create: {
41
+ value: "5BF",
42
+ name: "5 Blast Furnace",
43
+ }
44
+ },
45
+ {
46
+ where: {
47
+ value: "OPM",
48
+ },
49
+ create: {
50
+ value: "OPM",
51
+ name: "Old Plug Mill",
52
+ }
53
+ },
54
+ {
55
+ where: {
56
+ value: "XOVR",
57
+ },
58
+ create: {
59
+ value: "XOVR",
60
+ name: "Short Cross Over",
61
+ }
62
+ },
63
+ {
64
+ where: {
65
+ value: "5ML",
66
+ },
67
+ create: {
68
+ value: "5ML",
69
+ name: "5 BF Middle Loop",
70
+ }
71
+ },
72
+ {
73
+ where: {
74
+ value: "6BF",
75
+ },
76
+ create: {
77
+ value: "6BF",
78
+ name: "6 Blast Furnace",
79
+ }
80
+ },
81
+ {
82
+ where: {
83
+ value: "DSML",
84
+ },
85
+ create: {
86
+ value: "DSML",
87
+ name: "Desulph Main Line",
88
+ }
89
+ },
90
+ ],
91
+ }
107
92
  }
108
- }
109
- })
110
- const create5BFN = await prisma.station.create({
111
- data: {
112
- value: "5BFN",
113
- name: "5 Blast Furnace - North",
114
- locations: {
115
- connectOrCreate: [
116
- {
117
- where: {
118
- value: "5BFN",
119
- },
120
- create: {
121
- value: "5BFN",
122
- name: "5 Blast Furnace - North",
123
- }
124
- },
125
- ]
126
- }
127
- },
128
- })
129
- const create5BFW = await prisma.station.create({
130
- data: {
131
- value: "5BFW",
132
- name: "5 Blast Furnace - West",
133
- locations: {
134
- connectOrCreate: [
135
- {
136
- where: {
137
- value: "5BFW",
138
- },
139
- create: {
140
- value: "5BFW",
141
- name: "5 Blast Furnace - West",
142
- }
143
- },
144
- ]
145
- }
146
- },
147
- })
148
- const createDES1 = await prisma.station.create({
149
- data: {
150
- value: "DES1",
151
- name: "Desulphurisation 1",
152
- locations: {
153
- connectOrCreate: [
154
- {
155
- where: {
156
- value: "DES1",
157
- },
158
- create: {
159
- value: "DES1",
160
- name: "Desulphurisation 1",
161
- }
162
- },
163
- ]
164
- }
165
- },
166
- })
167
- const createDES2 = await prisma.station.create({
168
- data: {
169
- value: "DES2",
170
- name: "Desulphurisation 2",
171
- locations: {
172
- connectOrCreate: [
173
- {
174
- where: {
175
- value: "DES2",
176
- },
177
- create: {
178
- value: "DES2",
179
- name: "Desulphurisation 2",
180
- }
181
- },
182
- ]
183
- }
184
- },
185
- })
186
- const create6PIT = await prisma.station.create({
187
- data: {
188
- value: "6PIT",
189
- name: "6 Pit",
190
- locations: {
191
- connectOrCreate: [
192
- {
193
- where: {
194
- value: "6PIT",
195
- },
196
- create: {
197
- value: "6PIT",
198
- name: "6 Pit",
199
- }
200
- },
201
- ]
202
- }
203
- },
204
- })
205
- const createWB1 = await prisma.station.create({
206
- data: {
207
- value: "WB1",
208
- name: "Weighbridge 1",
209
- locations: {
210
- connectOrCreate: [
211
- {
212
- where: {
213
- value: "WB1",
214
- },
215
- create: {
216
- value: "WB1",
217
- name: "Weighbridge 1",
218
- }
219
- },
220
- ]
221
- }
222
- },
223
- })
224
- const createWB2 = await prisma.station.create({
225
- data: {
226
- value: "WB2",
227
- name: "Weighbridge 2",
228
- locations: {
229
- connectOrCreate: [
230
- {
231
- where: {
232
- value: "WB2",
233
- },
234
- create: {
235
- value: "WB2",
236
- name: "Weighbridge 2",
237
- }
238
- },
239
- ]
240
- }
241
- },
242
- })
243
- const create21D = await prisma.station.create({
244
- data: {
245
- value: "21D",
246
- name: "Dump",
247
- locations: {
248
- connectOrCreate: [
249
- {
250
- where: {
251
- value: "21D",
252
- },
253
- create: {
254
- value: "21D",
255
- name: "Dump",
256
- }
257
- },
258
- ]
259
- }
260
- },
261
- })
262
- const createWB1H = await prisma.station.create({
263
- data: {
264
- value: "WB1H",
265
- name: "Weighbridge 1 - Holding",
266
- locations: {
267
- connectOrCreate: [
268
- {
269
- where: {
270
- value: "WB1H",
271
- },
272
- create: {
273
- value: "WB1H",
274
- name: "Weighbridge 1 - Holding",
275
- }
276
- },
277
- ]
278
- }
279
- },
280
- })
281
- const createWB2H = await prisma.station.create({
282
- data: {
283
- value: "WB2H",
284
- name: "Weighbridge 2 - Holding",
285
- locations: {
286
- connectOrCreate: [
287
- {
288
- where: {
289
- value: "WB2H",
290
- },
291
- create: {
292
- value: "WB2H",
293
- name: "Weighbridge 2 - Holding",
294
- }
295
- },
296
- ]
297
- }
298
- },
299
- })
300
- const createGAS = await prisma.station.create({
301
- data: {
302
- value: "GAS",
303
- name: "On Gas",
304
- locations: {
305
- connectOrCreate: [
306
- {
307
- where: {
308
- value: "GASL",
309
- },
310
- create: {
311
- value: "GASL",
312
- name: "Gasline",
313
- }
314
- },
315
- {
316
- where: {
317
- value: "COOL"
318
- },
319
- create: {
320
- value: "COOL",
321
- name: "Cooling Station",
322
- }
323
- },
324
- {
325
- where: {
326
- value: "5BFHL",
327
- },
328
- create: {
329
- value: "5BFHL",
330
- name: "No.5 Blast Furnace Heating line",
331
- }
332
- }
333
- ]
334
- }
335
- },
336
- })
337
- const createOOS = await prisma.station.create({
338
- data: {
339
- value: "OOS",
340
- name: "Out Of Service",
341
- locations: {
342
- connectOrCreate: [
343
- {
344
- where: {
345
- value: "GASL",
346
- },
347
- create: {
348
- value: "GASL",
349
- name: "Gasline",
350
- }
351
- },
352
- {
353
- where: {
354
- value: "COOL"
355
- },
356
- create: {
357
- value: "COOL",
358
- name: "Cooling Station",
359
- }
360
- },
361
- {
362
- where: {
363
- value: "5BFHL",
364
- },
365
- create: {
366
- value: "5BFHL",
367
- name: "No.5 Blast Furnace Heating line",
368
- }
369
- },
370
- {
371
- where: {
372
- value: "5FDRY",
373
- },
374
- create: {
375
- value: "5FDRY",
376
- name: "No.5 position Foundry",
377
- }
378
- },
379
- {
380
- where: {
381
- value: "GUNR",
382
- },
383
- create: {
384
- value: "GUNR",
385
- name: "Gunning Road",
386
- }
387
- },
388
- {
389
- where: {
390
- value: "AWNR",
391
- },
392
- create: {
393
- value: "AWNR",
394
- name: "Awning Road",
395
- }
396
- },
397
- {
398
- where: {
399
- value: "REBS",
400
- },
401
- create: {
402
- value: "REBS",
403
- name: "Rebrick shed",
404
- }
405
- },
406
- {
407
- where: {
408
- value: "LRS1",
409
- },
410
- create: {
411
- value: "LRS1",
412
- name: "Ladle Repair shop road 1",
413
- }
414
- },
415
- {
416
- where: {
417
- value: "LRS2",
418
- },
419
- create: {
420
- value: "LRS2",
421
- name: "Ladle Repair shop road 2",
422
- }
423
- },
424
- {
425
- where: {
426
- value: "KLO",
427
- },
428
- create: {
429
- value: "KLO",
430
- name: "Klondu",
431
- }
432
- }
433
- ]
93
+ })
94
+ const create5BFE = await prisma.station.create({
95
+ data: {
96
+ value: "5BFE",
97
+ name: "5 Blast Furnace - East",
98
+ locations: {
99
+ connectOrCreate: [
100
+ {
101
+ where: {
102
+ value: "5BFE",
103
+ },
104
+ create:
105
+ {
106
+ value: "5BFE",
107
+ name: "5 Blast Furnace - East",
108
+ }
109
+ },
110
+ ]
111
+
112
+ }
434
113
  }
435
- },
436
- })
437
- const createRM = await prisma.station.create({
438
- data:
439
- {
440
- value: "R+M",
441
- name: "R+M / Break",
442
- locations: {
443
- connectOrCreate: [
444
- {
445
- where: {
446
- value: "LRS1",
447
- },
448
- create: {
449
- value: "LRS1",
450
- name: "Ladle Repair shop road 1",
451
- }
452
- },
453
- {
454
- where: {
455
- value: "LRS2",
456
- },
457
- create: {
458
- value: "LRS2",
459
- name: "Ladle Repair shop road 2",
460
- }
461
- },
462
- ]
114
+ })
115
+ const create5BFN = await prisma.station.create({
116
+ data: {
117
+ value: "5BFN",
118
+ name: "5 Blast Furnace - North",
119
+ locations: {
120
+ connectOrCreate: [
121
+ {
122
+ where: {
123
+ value: "5BFN",
124
+ },
125
+ create: {
126
+ value: "5BFN",
127
+ name: "5 Blast Furnace - North",
128
+ }
129
+ },
130
+ ]
131
+ }
132
+ },
133
+ })
134
+ const create5BFW = await prisma.station.create({
135
+ data: {
136
+ value: "5BFW",
137
+ name: "5 Blast Furnace - West",
138
+ locations: {
139
+ connectOrCreate: [
140
+ {
141
+ where: {
142
+ value: "5BFW",
143
+ },
144
+ create: {
145
+ value: "5BFW",
146
+ name: "5 Blast Furnace - West",
147
+ }
148
+ },
149
+ ]
150
+ }
151
+ },
152
+ })
153
+ const createDES1 = await prisma.station.create({
154
+ data: {
155
+ value: "DES1",
156
+ name: "Desulphurisation 1",
157
+ locations: {
158
+ connectOrCreate: [
159
+ {
160
+ where: {
161
+ value: "DES1",
162
+ },
163
+ create: {
164
+ value: "DES1",
165
+ name: "Desulphurisation 1",
166
+ }
167
+ },
168
+ ]
169
+ }
170
+ },
171
+ })
172
+ const createDES2 = await prisma.station.create({
173
+ data: {
174
+ value: "DES2",
175
+ name: "Desulphurisation 2",
176
+ locations: {
177
+ connectOrCreate: [
178
+ {
179
+ where: {
180
+ value: "DES2",
181
+ },
182
+ create: {
183
+ value: "DES2",
184
+ name: "Desulphurisation 2",
185
+ }
186
+ },
187
+ ]
188
+ }
189
+ },
190
+ })
191
+ const create6PIT = await prisma.station.create({
192
+ data: {
193
+ value: "6PIT",
194
+ name: "6 Pit",
195
+ locations: {
196
+ connectOrCreate: [
197
+ {
198
+ where: {
199
+ value: "6PIT",
200
+ },
201
+ create: {
202
+ value: "6PIT",
203
+ name: "6 Pit",
204
+ }
205
+ },
206
+ ]
207
+ }
208
+ },
209
+ })
210
+ const createWB1 = await prisma.station.create({
211
+ data: {
212
+ value: "WB1",
213
+ name: "Weighbridge 1",
214
+ locations: {
215
+ connectOrCreate: [
216
+ {
217
+ where: {
218
+ value: "WB1",
219
+ },
220
+ create: {
221
+ value: "WB1",
222
+ name: "Weighbridge 1",
223
+ }
224
+ },
225
+ ]
226
+ }
227
+ },
228
+ })
229
+ const createWB2 = await prisma.station.create({
230
+ data: {
231
+ value: "WB2",
232
+ name: "Weighbridge 2",
233
+ locations: {
234
+ connectOrCreate: [
235
+ {
236
+ where: {
237
+ value: "WB2",
238
+ },
239
+ create: {
240
+ value: "WB2",
241
+ name: "Weighbridge 2",
242
+ }
243
+ },
244
+ ]
245
+ }
246
+ },
247
+ })
248
+ const create21D = await prisma.station.create({
249
+ data: {
250
+ value: "21D",
251
+ name: "Dump",
252
+ locations: {
253
+ connectOrCreate: [
254
+ {
255
+ where: {
256
+ value: "21D",
257
+ },
258
+ create: {
259
+ value: "21D",
260
+ name: "Dump",
261
+ }
262
+ },
263
+ ]
264
+ }
265
+ },
266
+ })
267
+ const createWB1H = await prisma.station.create({
268
+ data: {
269
+ value: "WB1H",
270
+ name: "Weighbridge 1 - Holding",
271
+ locations: {
272
+ connectOrCreate: [
273
+ {
274
+ where: {
275
+ value: "WB1H",
276
+ },
277
+ create: {
278
+ value: "WB1H",
279
+ name: "Weighbridge 1 - Holding",
280
+ }
281
+ },
282
+ ]
283
+ }
284
+ },
285
+ })
286
+ const createWB2H = await prisma.station.create({
287
+ data: {
288
+ value: "WB2H",
289
+ name: "Weighbridge 2 - Holding",
290
+ locations: {
291
+ connectOrCreate: [
292
+ {
293
+ where: {
294
+ value: "WB2H",
295
+ },
296
+ create: {
297
+ value: "WB2H",
298
+ name: "Weighbridge 2 - Holding",
299
+ }
300
+ },
301
+ ]
302
+ }
303
+ },
304
+ })
305
+ const createGAS = await prisma.station.create({
306
+ data: {
307
+ value: "GAS",
308
+ name: "On Gas",
309
+ locations: {
310
+ connectOrCreate: [
311
+ {
312
+ where: {
313
+ value: "GASL",
314
+ },
315
+ create: {
316
+ value: "GASL",
317
+ name: "Gasline",
318
+ }
319
+ },
320
+ {
321
+ where: {
322
+ value: "COOL"
323
+ },
324
+ create: {
325
+ value: "COOL",
326
+ name: "Cooling Station",
327
+ }
328
+ },
329
+ {
330
+ where: {
331
+ value: "5BFHL",
332
+ },
333
+ create: {
334
+ value: "5BFHL",
335
+ name: "No.5 Blast Furnace Heating line",
336
+ }
337
+ }
338
+ ]
339
+ }
340
+ },
341
+ })
342
+ const createOOS = await prisma.station.create({
343
+ data: {
344
+ value: "OOS",
345
+ name: "Out Of Service",
346
+ locations: {
347
+ connectOrCreate: [
348
+ {
349
+ where: {
350
+ value: "GASL",
351
+ },
352
+ create: {
353
+ value: "GASL",
354
+ name: "Gasline",
355
+ }
356
+ },
357
+ {
358
+ where: {
359
+ value: "COOL"
360
+ },
361
+ create: {
362
+ value: "COOL",
363
+ name: "Cooling Station",
364
+ }
365
+ },
366
+ {
367
+ where: {
368
+ value: "5BFHL",
369
+ },
370
+ create: {
371
+ value: "5BFHL",
372
+ name: "No.5 Blast Furnace Heating line",
373
+ }
374
+ },
375
+ {
376
+ where: {
377
+ value: "5FDRY",
378
+ },
379
+ create: {
380
+ value: "5FDRY",
381
+ name: "No.5 position Foundry",
382
+ }
383
+ },
384
+ {
385
+ where: {
386
+ value: "GUNR",
387
+ },
388
+ create: {
389
+ value: "GUNR",
390
+ name: "Gunning Road",
391
+ }
392
+ },
393
+ {
394
+ where: {
395
+ value: "AWNR",
396
+ },
397
+ create: {
398
+ value: "AWNR",
399
+ name: "Awning Road",
400
+ }
401
+ },
402
+ {
403
+ where: {
404
+ value: "REBS",
405
+ },
406
+ create: {
407
+ value: "REBS",
408
+ name: "Rebrick shed",
409
+ }
410
+ },
411
+ {
412
+ where: {
413
+ value: "LRS1",
414
+ },
415
+ create: {
416
+ value: "LRS1",
417
+ name: "Ladle Repair shop road 1",
418
+ }
419
+ },
420
+ {
421
+ where: {
422
+ value: "LRS2",
423
+ },
424
+ create: {
425
+ value: "LRS2",
426
+ name: "Ladle Repair shop road 2",
427
+ }
428
+ },
429
+ {
430
+ where: {
431
+ value: "KLO",
432
+ },
433
+ create: {
434
+ value: "KLO",
435
+ name: "Klondu",
436
+ }
437
+ }
438
+ ]
439
+ }
440
+ },
441
+ })
442
+ const createRM = await prisma.station.create({
443
+ data:
444
+ {
445
+ value: "R+M/BREAK",
446
+ name: "R+M / Break",
447
+ locations: {
448
+ connectOrCreate: [
449
+ {
450
+ where: {
451
+ value: "LRS1",
452
+ },
453
+ create: {
454
+ value: "LRS1",
455
+ name: "Ladle Repair shop road 1",
456
+ }
457
+ },
458
+ {
459
+ where: {
460
+ value: "LRS2",
461
+ },
462
+ create: {
463
+ value: "LRS2",
464
+ name: "Ladle Repair shop road 2",
465
+ }
466
+ },
467
+ ]
468
+ }
463
469
  }
464
- }
465
- });
466
- console.log({
467
- create21D,
468
- create5BFE,
469
- create5BFN,
470
- create5BFW,
471
- create6PIT,
472
- createDES1,
473
- createDES2,
474
- createGAS,
475
- createHolding,
476
- createOOS,
477
- createRM,
478
- createWB1,
479
- createWB1H,
480
- createWB2,
481
- createWB2H
482
- });
483
- const torpedoIdList = await prisma.torpedo.findMany({
484
- select: {
485
- torpedoId: true,
486
- },
487
- });
470
+ });
488
471
 
489
- const stationList = await prisma.station.findMany({
490
- select: {
491
- id: true,
492
- locations: true,
493
- },
494
- orderBy: {
495
- id: "asc"
496
- }
497
- });
472
+ console.log({
473
+ create21D,
474
+ create5BFE,
475
+ create5BFN,
476
+ create5BFW,
477
+ create6PIT,
478
+ createDES1,
479
+ createDES2,
480
+ createGAS,
481
+ createHolding,
482
+ createOOS,
483
+ createRM,
484
+ createWB1,
485
+ createWB1H,
486
+ createWB2,
487
+ createWB2H,
488
+ });
498
489
 
499
- const randomtorpedoList = _.sample(torpedoIdList, stationList.length * 2);
500
- let locationsArray =[]
501
- for (let i = 0; i < stationList.length; i++) {
502
- console.log(i)
503
- const location1 = await prisma.torpedoLocation.create({
504
- data: {
505
- stationId: stationList[i].id,
506
- position: 0,
507
- torpedoId: randomtorpedoList[2 * i].torpedoId,
508
- locationId: stationList[i].locations[0].id,
490
+ const torpedoIdList = await prisma.torpedo.findMany({
491
+ select: {
492
+ torpedoId: true,
509
493
  },
510
494
  });
511
- locationsArray.push(location1)
512
- const location2 = await prisma.torpedoLocation.create({
513
- data: {
514
- stationId: stationList[i].id,
515
- position: 1,
516
- torpedoId: randomtorpedoList[2 * i + 1].torpedoId,
517
- locationId: stationList[i].locations[0].id,
495
+ const stationList = await prisma.station.findMany({
496
+ select: {
497
+ id: true,
498
+ locations: true,
518
499
  },
500
+ orderBy: {
501
+ id: "asc"
502
+ }
519
503
  });
520
- locationsArray.push(location2)
504
+
505
+ const randomtorpedoList = _.sample(torpedoIdList, stationList.length * 2);
506
+ let locationsArray = [];
507
+ for (let i = 0; i < stationList.length; i++) {
508
+ console.log(i);
509
+ const location1 = await prisma.torpedoLocation.create({
510
+ data: {
511
+ stationId: stationList[i].id,
512
+ position: 0,
513
+ torpedoId: randomtorpedoList[2 * i].torpedoId,
514
+ locationId: stationList[i].locations[0].id,
515
+ },
516
+ });
517
+ locationsArray.push(location1);
518
+ const location2 = await prisma.torpedoLocation.create({
519
+ data: {
520
+ stationId: stationList[i].id,
521
+ position: 1,
522
+ torpedoId: randomtorpedoList[2 * i + 1].torpedoId,
523
+ locationId: stationList[i].locations[0].id,
524
+ },
525
+ });
526
+ locationsArray.push(location2);
527
+ }
528
+
529
+ const remainingTorpedoes = torpedoIdList.filter((a) => !randomtorpedoList.some((b) => b.torpedoId === a.torpedoId));
530
+ for (let i: number = 0; i < remainingTorpedoes.length; i++) {
531
+ const randomLocation = await prisma.torpedoLocation.create({
532
+ data: {
533
+ stationId: 1,
534
+ position: 2 + i,
535
+ torpedoId: remainingTorpedoes[i].torpedoId,
536
+ locationId: stationList[0].locations[0].id
537
+ },
538
+ });
539
+ locationsArray.push(randomLocation);
540
+ }
541
+ console.log(locationsArray);
521
542
  }
522
- const remainingTorpedoes = torpedoIdList.filter((a) => !randomtorpedoList.some((b) => b.torpedoId === a.torpedoId));
523
- for (let i: number = 0; i < remainingTorpedoes.length; i++) {
524
- const randomLocation = await prisma.torpedoLocation.create({
525
- data: {
526
- stationId: 1,
527
- position: 2 + i,
528
- torpedoId: remainingTorpedoes[i].torpedoId,
529
- locationId: stationList[0].locations[0].id
530
- },
543
+
544
+ // SEED: TorpedoState
545
+ if (await prisma.torpedoState.count() > 0) {
546
+ console.log("SEED: TorpedoState - skipped.");
547
+ } else {
548
+ console.log("SEED: TorpedoState - generating...");
549
+
550
+ const createTorpedoState = await prisma.torpedoState.createMany({
551
+ data: [
552
+ { name: "OPR", label: "Operational", description: "Carrying metal" },
553
+ { name: "AVE", label: "Available & Empty", description: "Empty & not in Gas, OOS, LRS" },
554
+ { name: "SBY", label: "On Gas", description: "Stand by", },
555
+ { name: "RM", label: "Routine Maintenance", description: "R+M/Break for R+M" },
556
+ { name: "BR", label: "Breakdown", description: "R+M/Break for Breakdown" },
557
+ { name: "OOS", label: "Out of service", description: "Out of service" },
558
+ ],
559
+ });
560
+
561
+ console.log({
562
+ createTorpedoState,
531
563
  });
532
- locationsArray.push(randomLocation)
533
564
  }
534
- console.log(locationsArray)
535
565
  }
536
566
 
537
567
  main()
@@ -542,4 +572,4 @@ main()
542
572
  console.error(e)
543
573
  await prisma.$disconnect()
544
574
  process.exit(1)
545
- })
575
+ })