@bslau/hmm_prisma_schema 1.1.14 → 1.1.16

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,10 +1,13 @@
1
1
  {
2
2
  "name": "@bslau/hmm_prisma_schema",
3
- "version": "1.1.14",
3
+ "version": "1.1.16",
4
4
  "main": "index.js",
5
5
  "author": "CIPA Development Team",
6
6
  "license": "ISC",
7
7
  "description": "HMM PRISMA Schema",
8
+ "prisma": {
9
+ "seed": "ts-node prisma/seed.ts"
10
+ },
8
11
  "scripts": {
9
12
  "generate": "npx prisma generate",
10
13
  "postinstall": "npm run generate",
@@ -12,9 +15,13 @@
12
15
  },
13
16
  "types": "./index.d.ts",
14
17
  "devDependencies": {
15
- "prisma": "^6.2.1"
16
- },
17
- "dependencies": {
18
- "@prisma/client": "^6.2.1"
18
+ "@prisma/client": "^6.2.1",
19
+ "@types/node": "^22.12.0",
20
+ "@types/underscore": "^1.13.0",
21
+ "prisma": "^6.2.1",
22
+ "ts-node": "^10.9.2",
23
+ "tsx": "^4.19.2",
24
+ "typescript": "^5.7.3",
25
+ "underscore": "^1.13.7"
19
26
  }
20
27
  }
@@ -0,0 +1,5 @@
1
+ import { PrismaClient } from "@prisma/client";
2
+
3
+ const prisma = new PrismaClient();
4
+
5
+ export default prisma;
@@ -0,0 +1,85 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `destinationSidingId` on the `EventTorpedoMovement` table. All the data in the column will be lost.
5
+ - You are about to drop the column `originSidingId` on the `EventTorpedoMovement` table. All the data in the column will be lost.
6
+ - You are about to drop the column `sidingId` on the `TorpedoLocation` table. All the data in the column will be lost.
7
+ - You are about to drop the `Siding` table. If the table is not empty, all the data it contains will be lost.
8
+ - Added the required column `destinationLocationId` to the `EventTorpedoMovement` table without a default value. This is not possible if the table is not empty.
9
+ - Added the required column `originLocationId` to the `EventTorpedoMovement` table without a default value. This is not possible if the table is not empty.
10
+ - Added the required column `locationId` to the `TorpedoLocation` table without a default value. This is not possible if the table is not empty.
11
+
12
+ */
13
+ BEGIN TRY
14
+
15
+ BEGIN TRAN;
16
+
17
+ -- DropForeignKey
18
+ ALTER TABLE [dbo].[EventTorpedoMovement] DROP CONSTRAINT [EventTorpedoMovement_destinationSidingId_fkey];
19
+
20
+ -- DropForeignKey
21
+ ALTER TABLE [dbo].[EventTorpedoMovement] DROP CONSTRAINT [EventTorpedoMovement_originSidingId_fkey];
22
+
23
+ -- DropForeignKey
24
+ ALTER TABLE [dbo].[TorpedoLocation] DROP CONSTRAINT [TorpedoLocation_sidingId_fkey];
25
+
26
+ -- AlterTable
27
+ ALTER TABLE [dbo].[EventTorpedoMovement] DROP COLUMN [destinationSidingId],
28
+ [originSidingId];
29
+ ALTER TABLE [dbo].[EventTorpedoMovement] ADD [destinationLocationId] INT NOT NULL,
30
+ [originLocationId] INT NOT NULL;
31
+
32
+ -- AlterTable
33
+ ALTER TABLE [dbo].[TorpedoLocation] DROP COLUMN [sidingId];
34
+ ALTER TABLE [dbo].[TorpedoLocation] ADD [locationId] INT NOT NULL;
35
+
36
+ -- DropTable
37
+ DROP TABLE [dbo].[Siding];
38
+
39
+ -- CreateTable
40
+ CREATE TABLE [dbo].[Location] (
41
+ [id] INT NOT NULL IDENTITY(1,1),
42
+ [name] NVARCHAR(1000) NOT NULL,
43
+ [value] NVARCHAR(1000) NOT NULL,
44
+ [createdAt] DATETIME2 NOT NULL CONSTRAINT [Location_createdAt_df] DEFAULT CURRENT_TIMESTAMP,
45
+ [updatedAt] DATETIME2 NOT NULL,
46
+ CONSTRAINT [Location_pkey] PRIMARY KEY CLUSTERED ([id])
47
+ );
48
+
49
+ -- CreateTable
50
+ CREATE TABLE [dbo].[_LocationToStation] (
51
+ [A] INT NOT NULL,
52
+ [B] INT NOT NULL,
53
+ CONSTRAINT [_LocationToStation_AB_unique] UNIQUE NONCLUSTERED ([A],[B])
54
+ );
55
+
56
+ -- CreateIndex
57
+ CREATE NONCLUSTERED INDEX [_LocationToStation_B_index] ON [dbo].[_LocationToStation]([B]);
58
+
59
+ -- AddForeignKey
60
+ ALTER TABLE [dbo].[TorpedoLocation] ADD CONSTRAINT [TorpedoLocation_locationId_fkey] FOREIGN KEY ([locationId]) REFERENCES [dbo].[Location]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;
61
+
62
+ -- AddForeignKey
63
+ ALTER TABLE [dbo].[EventTorpedoMovement] ADD CONSTRAINT [EventTorpedoMovement_originLocationId_fkey] FOREIGN KEY ([originLocationId]) REFERENCES [dbo].[Location]([id]) ON DELETE NO ACTION ON UPDATE CASCADE;
64
+
65
+ -- AddForeignKey
66
+ ALTER TABLE [dbo].[EventTorpedoMovement] ADD CONSTRAINT [EventTorpedoMovement_destinationLocationId_fkey] FOREIGN KEY ([destinationLocationId]) REFERENCES [dbo].[Location]([id]) ON DELETE NO ACTION ON UPDATE NO ACTION;
67
+
68
+ -- AddForeignKey
69
+ ALTER TABLE [dbo].[_LocationToStation] ADD CONSTRAINT [_LocationToStation_A_fkey] FOREIGN KEY ([A]) REFERENCES [dbo].[Location]([id]) ON DELETE CASCADE ON UPDATE CASCADE;
70
+
71
+ -- AddForeignKey
72
+ ALTER TABLE [dbo].[_LocationToStation] ADD CONSTRAINT [_LocationToStation_B_fkey] FOREIGN KEY ([B]) REFERENCES [dbo].[Station]([id]) ON DELETE CASCADE ON UPDATE CASCADE;
73
+
74
+ COMMIT TRAN;
75
+
76
+ END TRY
77
+ BEGIN CATCH
78
+
79
+ IF @@TRANCOUNT > 0
80
+ BEGIN
81
+ ROLLBACK TRAN;
82
+ END;
83
+ THROW
84
+
85
+ END CATCH
@@ -0,0 +1,29 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - A unique constraint covering the columns `[value]` on the table `Location` will be added. If there are existing duplicate values, this will fail.
5
+ - A unique constraint covering the columns `[value]` on the table `Station` will be added. If there are existing duplicate values, this will fail.
6
+
7
+ */
8
+ BEGIN TRY
9
+
10
+ BEGIN TRAN;
11
+
12
+ -- CreateIndex
13
+ ALTER TABLE [dbo].[Location] ADD CONSTRAINT [Location_value_key] UNIQUE NONCLUSTERED ([value]);
14
+
15
+ -- CreateIndex
16
+ ALTER TABLE [dbo].[Station] ADD CONSTRAINT [Station_value_key] UNIQUE NONCLUSTERED ([value]);
17
+
18
+ COMMIT TRAN;
19
+
20
+ END TRY
21
+ BEGIN CATCH
22
+
23
+ IF @@TRANCOUNT > 0
24
+ BEGIN
25
+ ROLLBACK TRAN;
26
+ END;
27
+ THROW
28
+
29
+ END CATCH
@@ -0,0 +1,33 @@
1
+ BEGIN TRY
2
+
3
+ BEGIN TRAN;
4
+
5
+ -- AlterTable
6
+ ALTER TABLE [dbo].[Torpedo] ADD [hmhSixPitRestrictionFlag] BIT NOT NULL CONSTRAINT [Torpedo_hmhSixPitRestrictionFlag_df] DEFAULT 0;
7
+
8
+ -- CreateTable
9
+ CREATE TABLE [dbo].[HMHComment] (
10
+ [id] INT NOT NULL IDENTITY(1,1),
11
+ [torpedoId] INT NOT NULL,
12
+ [comment] NVARCHAR(1000) NOT NULL,
13
+ [isRemoved] BIT NOT NULL CONSTRAINT [HMHComment_isRemoved_df] DEFAULT 0,
14
+ [createdAt] DATETIME2 NOT NULL CONSTRAINT [HMHComment_createdAt_df] DEFAULT CURRENT_TIMESTAMP,
15
+ [updatedAt] DATETIME2,
16
+ CONSTRAINT [HMHComment_pkey] PRIMARY KEY CLUSTERED ([id])
17
+ );
18
+
19
+ -- AddForeignKey
20
+ ALTER TABLE [dbo].[HMHComment] ADD CONSTRAINT [HMHComment_torpedoId_fkey] FOREIGN KEY ([torpedoId]) REFERENCES [dbo].[Torpedo]([torpedoId]) ON DELETE NO ACTION ON UPDATE CASCADE;
21
+
22
+ COMMIT TRAN;
23
+
24
+ END TRY
25
+ BEGIN CATCH
26
+
27
+ IF @@TRANCOUNT > 0
28
+ BEGIN
29
+ ROLLBACK TRAN;
30
+ END;
31
+ THROW
32
+
33
+ END CATCH
@@ -124,6 +124,7 @@ model Torpedo {
124
124
  heatUpStartTime DateTime? @db.DateTimeOffset
125
125
  onGasFlag Boolean @default(false)
126
126
  onGasEndDate DateTime? @db.DateTimeOffset
127
+ hmhSixPitRestrictionFlag Boolean @default(false)
127
128
  sixPitRestrictionFlag Boolean @default(false)
128
129
  sixPitRestrictionEndTime DateTime? @db.DateTimeOffset
129
130
  status Int @default(2)
@@ -136,6 +137,7 @@ model Torpedo {
136
137
  hotMetalCollection HotMetal[]
137
138
  torpedoLocation TorpedoLocation?
138
139
  torpedoComments TorpedoComment[]
140
+ hmhComments HMHComment[]
139
141
  eventsTorpedoMovement EventTorpedoMovement[]
140
142
  createdAt DateTime @default(now())
141
143
  updatedAt DateTime @updatedAt
@@ -144,10 +146,11 @@ model Torpedo {
144
146
  model Station {
145
147
  id Int @id @default(autoincrement())
146
148
  name String
147
- value String
149
+ value String @unique
148
150
  createdAt DateTime @default(now())
149
151
  updatedAt DateTime @updatedAt
150
152
  torpedoLocations TorpedoLocation[]
153
+ locations Location[]
151
154
  eventsTorpedoMovementOrigin EventTorpedoMovement[] @relation(name: "originStation-movement")
152
155
  eventsTorpedoMovementDestination EventTorpedoMovement[] @relation(name: "destinationStation-movement")
153
156
  }
@@ -175,27 +178,28 @@ model HotMetalLabResult {
175
178
  updatedAt DateTime @updatedAt
176
179
  }
177
180
 
178
- model Siding {
181
+ model Location {
179
182
  id Int @id @default(autoincrement())
180
183
  name String
181
- value String
184
+ value String @unique
182
185
  createdAt DateTime @default(now())
183
186
  updatedAt DateTime @updatedAt
184
- eventsTorpedoMovementOrigin EventTorpedoMovement[] @relation(name: "originSiding-movement")
185
- eventsTorpedoMovementDestination EventTorpedoMovement[] @relation(name: "destinationSiding-movement")
187
+ eventsTorpedoMovementOrigin EventTorpedoMovement[] @relation(name: "originLocation-movement")
188
+ eventsTorpedoMovementDestination EventTorpedoMovement[] @relation(name: "destinationLocation-movement")
189
+ stations Station[]
186
190
  torpedoLocations TorpedoLocation[]
187
191
  }
188
192
 
189
193
  model TorpedoLocation {
190
- stationId Int
191
- station Station @relation(fields: [stationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
192
- position Int
193
- torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId], onDelete: NoAction, onUpdate: Cascade)
194
- torpedoId Int @unique
195
- sidingId Int?
196
- siding Siding? @relation(fields: [sidingId], references: [id], onDelete: NoAction, onUpdate: Cascade)
197
- createdAt DateTime @default(now())
198
- updatedAt DateTime @updatedAt
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
199
203
 
200
204
  @@id([stationId, position])
201
205
  }
@@ -210,6 +214,16 @@ model TorpedoComment {
210
214
  updatedAt DateTime? @updatedAt
211
215
  }
212
216
 
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
+ }
226
+
213
227
  model EventTracker {
214
228
  id Int @id @default(autoincrement())
215
229
  eventTime DateTime @db.DateTimeOffset
@@ -219,21 +233,21 @@ model EventTracker {
219
233
  }
220
234
 
221
235
  model EventTorpedoMovement {
222
- id Int @id @default(autoincrement())
223
- torpedoId Int
224
- torpedo Torpedo @relation(fields: [torpedoId], references: [torpedoId])
225
- eventTime DateTime @db.DateTimeOffset
226
- originStation Station @relation(name: "originStation-movement", fields: [originStationId], references: [id], onDelete: NoAction, onUpdate: Cascade)
227
- originStationId Int
228
- originSiding Siding? @relation(name: "originSiding-movement", fields: [originSidingId], references: [id], onDelete: NoAction, onUpdate: Cascade)
229
- originSidingId Int?
230
- destinationStation Station @relation(name: "destinationStation-movement", fields: [destinationStationId], references: [id], onDelete: NoAction, onUpdate: NoAction)
231
- destinationStationId Int
232
- destinationSiding Siding? @relation(name: "destinationSiding-movement", fields: [destinationSidingId], references: [id], onDelete: NoAction, onUpdate: NoAction)
233
- destinationSidingId Int?
234
- event EventTracker @relation(fields: [eventId], references: [id])
235
- eventId Int @unique
236
- userId String?
237
- createdAt DateTime @default(now())
238
- updatedAt DateTime @updatedAt
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
239
253
  }
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
+ }