@bslau/hmm_prisma_schema 1.8.2 → 1.9.1

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/prisma/seed.ts +165 -368
package/README.md CHANGED
@@ -4,7 +4,7 @@ The general workflow will follow these steps:
4
4
 
5
5
  - Create and checkout a new working branch.
6
6
  - Edit `schema.prisma` as needed.
7
- - Run automated formatting: `npx prisma format`
7
+ - Run automated formatting: `npm run prisma:format`
8
8
  - Prepare database changes (as needed):
9
9
  - create (preview) migration: `npm run prisma:create` or;
10
10
  - create and apply migration: `npm run prisma:apply`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bslau/hmm_prisma_schema",
3
- "version": "1.8.2",
3
+ "version": "1.9.1",
4
4
  "main": "index.js",
5
5
  "author": "CIPA Development Team",
6
6
  "license": "ISC",
package/prisma/seed.ts CHANGED
@@ -1,8 +1,40 @@
1
1
  import _ from "underscore";
2
2
  import prisma from "./dbClient";
3
3
 
4
+ // SEED: Function to add Locations to Stations
5
+ async function addLocationsToStation(
6
+ stationValue: string,
7
+ locations: { value: string; name: string }[]
8
+ ) {
9
+ for (const loc of locations) {
10
+ // Ensure the location exists and has the correct name
11
+ await prisma.location.upsert({
12
+ where: { value: loc.value },
13
+ update: {
14
+ name: loc.name, // Updates name if changed
15
+ },
16
+ create: {
17
+ value: loc.value,
18
+ name: loc.name,
19
+ },
20
+ });
21
+
22
+ // Connect the location to the specified station
23
+ await prisma.station.update({
24
+ where: { value: stationValue },
25
+ data: {
26
+ locations: {
27
+ connect: { value: loc.value },
28
+ },
29
+ },
30
+ });
31
+
32
+ console.log(`Location ${loc.value} connected to station ${stationValue}`);
33
+ }
34
+ }
35
+
4
36
  async function main() {
5
- // SEED: Torpedos
37
+ // SEED: Torpedoes
6
38
  if ((await prisma.torpedo.count()) > 0) {
7
39
  console.log("SEED: Torpedo - skipped.");
8
40
  } else {
@@ -47,7 +79,6 @@ async function main() {
47
79
  { torpedoId: 54, name: "Torpedo 54", status: 2, capacityNominal: 250 },
48
80
  { torpedoId: 55, name: "Torpedo 55", status: 2, capacityNominal: 180 },
49
81
  { torpedoId: 56, name: "Torpedo 56", status: 2, capacityNominal: 250 },
50
- { torpedoId: 57, name: "Torpedo 57", status: 2, capacityNominal: 250 },
51
82
  { torpedoId: 58, name: "Torpedo 58", status: 2, capacityNominal: 240 },
52
83
  { torpedoId: 60, name: "Torpedo 60", status: 2, capacityNominal: 250 },
53
84
  ],
@@ -64,460 +95,123 @@ async function main() {
64
95
  } else {
65
96
  console.log("SEED: Station - generating...");
66
97
 
98
+ // Holding
67
99
  const createHolding = await prisma.station.create({
68
100
  data: {
69
101
  value: "HOLDING",
70
102
  name: "Holding",
71
- locations: {
72
- connectOrCreate: [
73
- {
74
- where: {
75
- value: "WPR",
76
- },
77
- create: {
78
- value: "WPR",
79
- name: "Woodpecker Repair Lines",
80
- },
81
- },
82
- {
83
- where: {
84
- value: "5OL",
85
- },
86
- create: {
87
- value: "5OL",
88
- name: "5 Outside Loop",
89
- },
90
- },
91
- {
92
- where: {
93
- value: "5BF",
94
- },
95
- create: {
96
- value: "5BF",
97
- name: "5 Blast Furnace",
98
- },
99
- },
100
- {
101
- where: {
102
- value: "OPM",
103
- },
104
- create: {
105
- value: "OPM",
106
- name: "Old Plug Mill",
107
- },
108
- },
109
- {
110
- where: {
111
- value: "XOVR",
112
- },
113
- create: {
114
- value: "XOVR",
115
- name: "Short Cross Over",
116
- },
117
- },
118
- {
119
- where: {
120
- value: "5ML",
121
- },
122
- create: {
123
- value: "5ML",
124
- name: "5 BF Middle Loop",
125
- },
126
- },
127
- {
128
- where: {
129
- value: "6BF",
130
- },
131
- create: {
132
- value: "6BF",
133
- name: "6 Blast Furnace",
134
- },
135
- },
136
- {
137
- where: {
138
- value: "DSML",
139
- },
140
- create: {
141
- value: "DSML",
142
- name: "Desulph Main Line",
143
- },
144
- },
145
- ],
146
- },
147
103
  },
148
104
  });
105
+
106
+ // 5BFE
149
107
  const create5BFE = await prisma.station.create({
150
108
  data: {
151
109
  value: "5BFE",
152
110
  name: "5 Blast Furnace - East",
153
- locations: {
154
- connectOrCreate: [
155
- {
156
- where: {
157
- value: "5BFE",
158
- },
159
- create: {
160
- value: "5BFE",
161
- name: "5 Blast Furnace - East",
162
- },
163
- },
164
- ],
165
- },
166
111
  },
167
112
  });
113
+
114
+ // 5BFN
168
115
  const create5BFN = await prisma.station.create({
169
116
  data: {
170
117
  value: "5BFN",
171
118
  name: "5 Blast Furnace - North",
172
- locations: {
173
- connectOrCreate: [
174
- {
175
- where: {
176
- value: "5BFN",
177
- },
178
- create: {
179
- value: "5BFN",
180
- name: "5 Blast Furnace - North",
181
- },
182
- },
183
- ],
184
- },
185
119
  },
186
120
  });
121
+
122
+ // 5BFW
187
123
  const create5BFW = await prisma.station.create({
188
124
  data: {
189
125
  value: "5BFW",
190
126
  name: "5 Blast Furnace - West",
191
- locations: {
192
- connectOrCreate: [
193
- {
194
- where: {
195
- value: "5BFW",
196
- },
197
- create: {
198
- value: "5BFW",
199
- name: "5 Blast Furnace - West",
200
- },
201
- },
202
- ],
203
- },
204
127
  },
205
128
  });
129
+
130
+ // Desulph 1
206
131
  const createDES1 = await prisma.station.create({
207
132
  data: {
208
133
  value: "DES1",
209
134
  name: "Desulphurisation 1",
210
- locations: {
211
- connectOrCreate: [
212
- {
213
- where: {
214
- value: "DES1",
215
- },
216
- create: {
217
- value: "DES1",
218
- name: "Desulphurisation 1",
219
- },
220
- },
221
- ],
222
- },
223
135
  },
224
136
  });
137
+
138
+ // Desulph 2
225
139
  const createDES2 = await prisma.station.create({
226
140
  data: {
227
141
  value: "DES2",
228
142
  name: "Desulphurisation 2",
229
- locations: {
230
- connectOrCreate: [
231
- {
232
- where: {
233
- value: "DES2",
234
- },
235
- create: {
236
- value: "DES2",
237
- name: "Desulphurisation 2",
238
- },
239
- },
240
- ],
241
- },
242
143
  },
243
144
  });
145
+
146
+ // 6PIT
244
147
  const create6PIT = await prisma.station.create({
245
148
  data: {
246
149
  value: "6PIT",
247
150
  name: "6 Pit",
248
- locations: {
249
- connectOrCreate: [
250
- {
251
- where: {
252
- value: "6PIT",
253
- },
254
- create: {
255
- value: "6PIT",
256
- name: "6 Pit",
257
- },
258
- },
259
- ],
260
- },
261
151
  },
262
152
  });
153
+
154
+ // WB1
263
155
  const createWB1 = await prisma.station.create({
264
156
  data: {
265
157
  value: "WB1",
266
158
  name: "Weighbridge 1",
267
- locations: {
268
- connectOrCreate: [
269
- {
270
- where: {
271
- value: "WB1",
272
- },
273
- create: {
274
- value: "WB1",
275
- name: "Weighbridge 1",
276
- },
277
- },
278
- ],
279
- },
280
159
  },
281
160
  });
161
+
162
+ // WB2
282
163
  const createWB2 = await prisma.station.create({
283
164
  data: {
284
165
  value: "WB2",
285
166
  name: "Weighbridge 2",
286
- locations: {
287
- connectOrCreate: [
288
- {
289
- where: {
290
- value: "WB2",
291
- },
292
- create: {
293
- value: "WB2",
294
- name: "Weighbridge 2",
295
- },
296
- },
297
- ],
298
- },
299
167
  },
300
168
  });
169
+
170
+ // 21 Dump
301
171
  const create21D = await prisma.station.create({
302
172
  data: {
303
173
  value: "21D",
304
174
  name: "Dump",
305
- locations: {
306
- connectOrCreate: [
307
- {
308
- where: {
309
- value: "21D",
310
- },
311
- create: {
312
- value: "21D",
313
- name: "Dump",
314
- },
315
- },
316
- ],
317
- },
318
175
  },
319
176
  });
177
+
178
+ // WB1 Holding
320
179
  const createWB1H = await prisma.station.create({
321
180
  data: {
322
181
  value: "WB1H",
323
182
  name: "Weighbridge 1 - Holding",
324
- locations: {
325
- connectOrCreate: [
326
- {
327
- where: {
328
- value: "WB1H",
329
- },
330
- create: {
331
- value: "WB1H",
332
- name: "Weighbridge 1 - Holding",
333
- },
334
- },
335
- ],
336
- },
337
183
  },
338
184
  });
185
+
186
+ // WB2 Holding
339
187
  const createWB2H = await prisma.station.create({
340
188
  data: {
341
189
  value: "WB2H",
342
190
  name: "Weighbridge 2 - Holding",
343
- locations: {
344
- connectOrCreate: [
345
- {
346
- where: {
347
- value: "WB2H",
348
- },
349
- create: {
350
- value: "WB2H",
351
- name: "Weighbridge 2 - Holding",
352
- },
353
- },
354
- ],
355
- },
356
191
  },
357
192
  });
193
+
194
+ // On Gas
358
195
  const createGAS = await prisma.station.create({
359
196
  data: {
360
197
  value: "GAS",
361
198
  name: "On Gas",
362
- locations: {
363
- connectOrCreate: [
364
- {
365
- where: {
366
- value: "GASL",
367
- },
368
- create: {
369
- value: "GASL",
370
- name: "Gasline",
371
- },
372
- },
373
- {
374
- where: {
375
- value: "COOL",
376
- },
377
- create: {
378
- value: "COOL",
379
- name: "Cooling Station",
380
- },
381
- },
382
- {
383
- where: {
384
- value: "5BFHL",
385
- },
386
- create: {
387
- value: "5BFHL",
388
- name: "No.5 Blast Furnace Heating line",
389
- },
390
- },
391
- ],
392
- },
393
199
  },
394
200
  });
201
+
202
+ // OOS
395
203
  const createOOS = await prisma.station.create({
396
204
  data: {
397
205
  value: "OOS",
398
206
  name: "Out Of Service",
399
- locations: {
400
- connectOrCreate: [
401
- {
402
- where: {
403
- value: "GASL",
404
- },
405
- create: {
406
- value: "GASL",
407
- name: "Gasline",
408
- },
409
- },
410
- {
411
- where: {
412
- value: "COOL",
413
- },
414
- create: {
415
- value: "COOL",
416
- name: "Cooling Station",
417
- },
418
- },
419
- {
420
- where: {
421
- value: "5BFHL",
422
- },
423
- create: {
424
- value: "5BFHL",
425
- name: "No.5 Blast Furnace Heating line",
426
- },
427
- },
428
- {
429
- where: {
430
- value: "5FDRY",
431
- },
432
- create: {
433
- value: "5FDRY",
434
- name: "No.5 position Foundry",
435
- },
436
- },
437
- {
438
- where: {
439
- value: "GUNR",
440
- },
441
- create: {
442
- value: "GUNR",
443
- name: "Gunning Road",
444
- },
445
- },
446
- {
447
- where: {
448
- value: "AWNR",
449
- },
450
- create: {
451
- value: "AWNR",
452
- name: "Awning Road",
453
- },
454
- },
455
- {
456
- where: {
457
- value: "REBS",
458
- },
459
- create: {
460
- value: "REBS",
461
- name: "Rebrick shed",
462
- },
463
- },
464
- {
465
- where: {
466
- value: "LRS1",
467
- },
468
- create: {
469
- value: "LRS1",
470
- name: "Ladle Repair shop road 1",
471
- },
472
- },
473
- {
474
- where: {
475
- value: "LRS2",
476
- },
477
- create: {
478
- value: "LRS2",
479
- name: "Ladle Repair shop road 2",
480
- },
481
- },
482
- {
483
- where: {
484
- value: "KLO",
485
- },
486
- create: {
487
- value: "KLO",
488
- name: "Klondu",
489
- },
490
- },
491
- ],
492
- },
493
207
  },
494
208
  });
209
+
210
+ // R+M Break
495
211
  const createRM = await prisma.station.create({
496
212
  data: {
497
213
  value: "R+M/BREAK",
498
214
  name: "R+M / Break",
499
- locations: {
500
- connectOrCreate: [
501
- {
502
- where: {
503
- value: "LRS1",
504
- },
505
- create: {
506
- value: "LRS1",
507
- name: "Ladle Repair shop road 1",
508
- },
509
- },
510
- {
511
- where: {
512
- value: "LRS2",
513
- },
514
- create: {
515
- value: "LRS2",
516
- name: "Ladle Repair shop road 2",
517
- },
518
- },
519
- ],
520
- },
521
215
  },
522
216
  });
523
217
 
@@ -538,7 +232,110 @@ async function main() {
538
232
  createWB2,
539
233
  createWB2H,
540
234
  });
235
+ }
236
+
237
+ // SEED: Connect the locations to stations
238
+ const holdingLocations: { value: string; name: string }[] = [
239
+ { value: "WPR", name: "Woodpecker Repair Lines" },
240
+ { value: "5OL", name: "5 Outside Loop" },
241
+ { value: "5BF", name: "5 Blast Furnace" },
242
+ { value: "OPM", name: "Old Plug Mill" },
243
+ { value: "XOVR", name: "Short Cross Over" },
244
+ { value: "5ML", name: "5 BF Middle Loop" },
245
+ { value: "6BF", name: "6 Blast Furnace" },
246
+ { value: "DSML", name: "Desulph Main Line" },
247
+ { value: "SPUR", name: "Stripper Spur" },
248
+ ];
249
+ await addLocationsToStation("HOLDING", holdingLocations);
250
+
251
+ const _5BFELocations: { value: string; name: string }[] = [
252
+ { value: "5BFE", name: "5 Blast Furnace - East" },
253
+ ];
254
+ await addLocationsToStation("5BFE", _5BFELocations);
255
+
256
+ const _5BFNLocations: { value: string; name: string }[] = [
257
+ { value: "5BFN", name: "5 Blast Furnace - North" },
258
+ ];
259
+ await addLocationsToStation("5BFN", _5BFNLocations);
260
+
261
+ const _5BFWLocations: { value: string; name: string }[] = [
262
+ { value: "5BFW", name: "5 Blast Furnace - West" },
263
+ ];
264
+ await addLocationsToStation("5BFW", _5BFWLocations);
265
+
266
+ const DES1Locations: { value: string; name: string }[] = [
267
+ { value: "DES1", name: "Desulphurisation 1" },
268
+ ];
269
+ await addLocationsToStation("DES1", DES1Locations);
270
+
271
+ const DES2Locations: { value: string; name: string }[] = [
272
+ { value: "DES2", name: "Desulphurisation 2" },
273
+ ];
274
+ await addLocationsToStation("DES2", DES2Locations);
275
+
276
+ const _6PITLocations: { value: string; name: string }[] = [
277
+ { value: "6PIT", name: "6 Pit" },
278
+ ];
279
+ await addLocationsToStation("6PIT", _6PITLocations);
280
+
281
+ const WB1Locations: { value: string; name: string }[] = [
282
+ { value: "WB1", name: "Weighbridge 1" },
283
+ ];
284
+ await addLocationsToStation("WB1", WB1Locations);
541
285
 
286
+ const WB2Locations: { value: string; name: string }[] = [
287
+ { value: "WB2", name: "Weighbridge 2" },
288
+ ];
289
+ await addLocationsToStation("WB2", WB2Locations);
290
+
291
+ const _21DumpLocations: { value: string; name: string }[] = [
292
+ { value: "21D", name: "Dump" },
293
+ ];
294
+ await addLocationsToStation("21D", _21DumpLocations);
295
+
296
+ const WB1HLocations: { value: string; name: string }[] = [
297
+ { value: "WB1H", name: "Weighbridge 1 - Holding" },
298
+ ];
299
+ await addLocationsToStation("WB1H", WB1HLocations);
300
+
301
+ const WB2HLocations: { value: string; name: string }[] = [
302
+ { value: "WB2H", name: "Weighbridge 2 - Holding" },
303
+ ];
304
+ await addLocationsToStation("WB2H", WB2HLocations);
305
+
306
+ const GASLocations: { value: string; name: string }[] = [
307
+ { value: "GASL", name: "Gasline" },
308
+ { value: "COOL", name: "Cooling Station" },
309
+ { value: "5BFHL", name: "No.5 Blast Furnace Heating line" },
310
+ ];
311
+ await addLocationsToStation("GAS", GASLocations);
312
+
313
+ const OOSLocations: { value: string; name: string }[] = [
314
+ { value: "GASL", name: "Gasline" },
315
+ { value: "COOL", name: "Cooling Station" },
316
+ { value: "5BFHL", name: "No.5 Blast Furnace Heating line" },
317
+ { value: "5FDRY", name: "No.5 position Foundry" },
318
+ { value: "GUNR", name: "Gunning Road" },
319
+ { value: "AWNR", name: "Awning Road" },
320
+ { value: "REBS", name: "Rebrick shed" },
321
+ { value: "LRS1", name: "Ladle Repair shop road 1" },
322
+ { value: "LRS2", name: "Ladle Repair shop road 2" },
323
+ { value: "KLO", name: "Klondu" },
324
+ { value: "WPR", name: "Woodpecker Repair Lines" },
325
+ { value: "SPUR", name: "Stripper Spur" },
326
+ ];
327
+ await addLocationsToStation("OOS", OOSLocations);
328
+
329
+ const RMLocations: { value: string; name: string }[] = [
330
+ { value: "LRS1", name: "Ladle Repair shop road 1" },
331
+ { value: "LRS2", name: "Ladle Repair shop road 2" },
332
+ ];
333
+ await addLocationsToStation("R+M/BREAK", RMLocations);
334
+
335
+ // Set Random Stations and Locations for Torpedoes
336
+ if ((await prisma.torpedoLocation.count()) > 0) {
337
+ console.log("SEED: Station - skipped.");
338
+ } else {
542
339
  const torpedoIdList = await prisma.torpedo.findMany({
543
340
  select: {
544
341
  torpedoId: true,