@bslau/hmm_prisma_schema 1.1.13 → 1.1.15

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 (30) hide show
  1. package/package.json +14 -8
  2. package/prisma/dbClient.ts +5 -0
  3. package/prisma/migrations/{20240910061111_init → 20250122012731_init}/migration.sql +74 -2
  4. package/prisma/migrations/20250127224749_test_column/migration.sql +25 -0
  5. package/prisma/migrations/20250127225625_delete_test_column/migration.sql +25 -0
  6. package/prisma/migrations/20250128232354_staion_location_models/migration.sql +85 -0
  7. package/prisma/migrations/20250129002847_staion_location_values_unique/migration.sql +29 -0
  8. package/prisma/migrations/migration_lock.toml +1 -1
  9. package/prisma/schema.prisma +33 -31
  10. package/prisma/seed.ts +545 -0
  11. package/script.ts +20 -0
  12. package/tsconfig.json +14 -0
  13. package/prisma/migrations/20240923010138_init/migration.sql +0 -32
  14. package/prisma/migrations/20240923011413_init/migration.sql +0 -37
  15. package/prisma/migrations/20240923013530_init/migration.sql +0 -32
  16. package/prisma/migrations/20240924014028_init/migration.sql +0 -27
  17. package/prisma/migrations/20241001001812_init/migration.sql +0 -19
  18. package/prisma/migrations/20241001003443_init/migration.sql +0 -28
  19. package/prisma/migrations/20241001004057_init/migration.sql +0 -29
  20. package/prisma/migrations/20241001005234_init/migration.sql +0 -28
  21. package/prisma/migrations/20241028055132_init/migration.sql +0 -46
  22. package/prisma/migrations/20241028223433_init/migration.sql +0 -52
  23. package/prisma/migrations/20241029041813_init/migration.sql +0 -55
  24. package/prisma/migrations/20241029044446_init/migration.sql +0 -78
  25. package/prisma/migrations/20241030045308_init/migration.sql +0 -19
  26. package/prisma/migrations/20241112005449_added_torpedo_properties_init/migration.sql +0 -31
  27. package/prisma/migrations/20241114030552_added_al_pucked_added/migration.sql +0 -19
  28. package/prisma/migrations/20241118235845_set_default_torpedo_status/migration.sql +0 -19
  29. package/prisma/migrations/20241119000008_set_default_torpedo_non_nullable/migration.sql +0 -25
  30. package/prisma/migrations/20241120022048_added_torpedo_comment/migration.sql +0 -20
package/prisma/seed.ts ADDED
@@ -0,0 +1,545 @@
1
+
2
+ import _ from "underscore";
3
+ import prisma from "./dbClient";
4
+
5
+ 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",
19
+
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
+ ]
106
+
107
+ }
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
+ ]
434
+ }
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
+ ]
463
+ }
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
+ });
488
+
489
+ const stationList = await prisma.station.findMany({
490
+ select: {
491
+ id: true,
492
+ locations: true,
493
+ },
494
+ orderBy: {
495
+ id: "asc"
496
+ }
497
+ });
498
+
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,
509
+ },
510
+ });
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,
518
+ },
519
+ });
520
+ locationsArray.push(location2)
521
+ }
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
+ },
531
+ });
532
+ locationsArray.push(randomLocation)
533
+ }
534
+ console.log(locationsArray)
535
+ }
536
+
537
+ main()
538
+ .then(async () => {
539
+ await prisma.$disconnect()
540
+ })
541
+ .catch(async (e) => {
542
+ console.error(e)
543
+ await prisma.$disconnect()
544
+ process.exit(1)
545
+ })
package/script.ts ADDED
@@ -0,0 +1,20 @@
1
+ import prisma from "./prisma/dbClient";
2
+
3
+ async function main() {
4
+ const getStationsAndLocations = await prisma.station.findMany({
5
+ include: {
6
+ locations: true
7
+ }
8
+ })
9
+ console.log(JSON.stringify(getStationsAndLocations,null,2));
10
+ }
11
+
12
+ main()
13
+ .then(async () => {
14
+ await prisma.$disconnect()
15
+ })
16
+ .catch(async (e) => {
17
+ console.error(e)
18
+ await prisma.$disconnect()
19
+ process.exit(1)
20
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "CommonJS",
5
+ "lib": ["ES2022"],
6
+ "allowJs": true,
7
+ "outDir": "build",
8
+ "strict": true,
9
+ "noImplicitAny": true,
10
+ "esModuleInterop": true,
11
+ "resolveJsonModule": true
12
+ },
13
+ "exclude": ["build"]
14
+ }
@@ -1,32 +0,0 @@
1
- /*
2
- Warnings:
3
-
4
- - You are about to drop the column `sampleType` on the `HotMetalLabResult` table. All the data in the column will be lost.
5
-
6
- */
7
- BEGIN TRY
8
-
9
- BEGIN TRAN;
10
-
11
- -- DropIndex
12
- ALTER TABLE [dbo].[HotMetalLabResult] DROP CONSTRAINT [HotMetalLabResult_hotMetalId_key];
13
-
14
- -- AlterTable
15
- ALTER TABLE [dbo].[HotMetalLabResult] DROP COLUMN [sampleType];
16
- ALTER TABLE [dbo].[HotMetalLabResult] ADD [description] NVARCHAR(1000),
17
- [testLocation] NVARCHAR(1000),
18
- [testSampleType] NVARCHAR(1000),
19
- [testSamplingLocation] NVARCHAR(1000);
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
@@ -1,37 +0,0 @@
1
- /*
2
- Warnings:
3
-
4
- - You are about to drop the column `description` on the `HotMetalLabResult` table. All the data in the column will be lost.
5
- - You are about to drop the column `testLocation` on the `HotMetalLabResult` table. All the data in the column will be lost.
6
- - You are about to drop the column `testSampleType` on the `HotMetalLabResult` table. All the data in the column will be lost.
7
- - You are about to drop the column `testSamplingLocation` on the `HotMetalLabResult` table. All the data in the column will be lost.
8
- - A unique constraint covering the columns `[hotMetalId]` on the table `HotMetalLabResult` will be added. If there are existing duplicate values, this will fail.
9
- - Added the required column `sampleType` to the `HotMetalLabResult` table without a default value. This is not possible if the table is not empty.
10
-
11
- */
12
- BEGIN TRY
13
-
14
- BEGIN TRAN;
15
-
16
- -- AlterTable
17
- ALTER TABLE [dbo].[HotMetalLabResult] DROP COLUMN [description],
18
- [testLocation],
19
- [testSampleType],
20
- [testSamplingLocation];
21
- ALTER TABLE [dbo].[HotMetalLabResult] ADD [sampleType] NVARCHAR(1000) NOT NULL;
22
-
23
- -- CreateIndex
24
- ALTER TABLE [dbo].[HotMetalLabResult] ADD CONSTRAINT [HotMetalLabResult_hotMetalId_key] UNIQUE NONCLUSTERED ([hotMetalId]);
25
-
26
- COMMIT TRAN;
27
-
28
- END TRY
29
- BEGIN CATCH
30
-
31
- IF @@TRANCOUNT > 0
32
- BEGIN
33
- ROLLBACK TRAN;
34
- END;
35
- THROW
36
-
37
- END CATCH
@@ -1,32 +0,0 @@
1
- /*
2
- Warnings:
3
-
4
- - You are about to drop the column `sampleType` on the `HotMetalLabResult` table. All the data in the column will be lost.
5
-
6
- */
7
- BEGIN TRY
8
-
9
- BEGIN TRAN;
10
-
11
- -- DropIndex
12
- ALTER TABLE [dbo].[HotMetalLabResult] DROP CONSTRAINT [HotMetalLabResult_hotMetalId_key];
13
-
14
- -- AlterTable
15
- ALTER TABLE [dbo].[HotMetalLabResult] DROP COLUMN [sampleType];
16
- ALTER TABLE [dbo].[HotMetalLabResult] ADD [description] NVARCHAR(1000),
17
- [testLocation] NVARCHAR(1000),
18
- [testSampleType] NVARCHAR(1000),
19
- [testSamplingLocation] NVARCHAR(1000);
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
@@ -1,27 +0,0 @@
1
- /*
2
- Warnings:
3
-
4
- - You are about to drop the column `testLocation` on the `HotMetalLabResult` table. All the data in the column will be lost.
5
- - You are about to drop the column `testSampleType` on the `HotMetalLabResult` table. All the data in the column will be lost.
6
-
7
- */
8
- BEGIN TRY
9
-
10
- BEGIN TRAN;
11
-
12
- -- AlterTable
13
- ALTER TABLE [dbo].[HotMetalLabResult] DROP COLUMN [testLocation],
14
- [testSampleType];
15
-
16
- COMMIT TRAN;
17
-
18
- END TRY
19
- BEGIN CATCH
20
-
21
- IF @@TRANCOUNT > 0
22
- BEGIN
23
- ROLLBACK TRAN;
24
- END;
25
- THROW
26
-
27
- END CATCH
@@ -1,19 +0,0 @@
1
- BEGIN TRY
2
-
3
- BEGIN TRAN;
4
-
5
- -- AlterTable
6
- ALTER TABLE [dbo].[HotMetalLabResult] ADD [testId] NVARCHAR(1000) NOT NULL CONSTRAINT [HotMetalLabResult_testId_df] DEFAULT '';
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