@bslau/hmm_prisma_schema 1.18.2 → 1.19.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.
- package/package.json +2 -2
- package/prisma/deleteTorpedo.ts +29 -9
- package/prisma/fillNullSegmentResponseIds.ts +22 -0
- package/prisma/migrations/20251203060958_prisma_fill_the_segment_response_id_field_with_unique_ids/migration.sql +29 -0
- package/prisma/schema.prisma +1 -1
- package/prisma/seed.ts +1 -0
package/package.json
CHANGED
package/prisma/deleteTorpedo.ts
CHANGED
|
@@ -6,7 +6,7 @@ const prisma = new PrismaClient();
|
|
|
6
6
|
async function deleteTorpedo(torpedoId: number) {
|
|
7
7
|
await prisma.$transaction(async (tx) => {
|
|
8
8
|
//
|
|
9
|
-
//
|
|
9
|
+
// COMMENTS
|
|
10
10
|
//
|
|
11
11
|
await tx.hMHComment.deleteMany({
|
|
12
12
|
where: { torpedoId },
|
|
@@ -16,21 +16,21 @@ async function deleteTorpedo(torpedoId: number) {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
//
|
|
19
|
-
//
|
|
19
|
+
// LADLE SURVEYS
|
|
20
20
|
//
|
|
21
21
|
await tx.hMHLadleSurvey.deleteMany({
|
|
22
22
|
where: { torpedoId },
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
//
|
|
26
|
-
//
|
|
26
|
+
// TORPEDO TIMER
|
|
27
27
|
//
|
|
28
28
|
await tx.torpedoTimer.deleteMany({
|
|
29
29
|
where: { torpedoId },
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
//
|
|
33
|
-
//
|
|
33
|
+
// EVENT TABLES
|
|
34
34
|
//
|
|
35
35
|
await tx.eventTorpedoCapacity.deleteMany({
|
|
36
36
|
where: { torpedoId },
|
|
@@ -49,7 +49,7 @@ async function deleteTorpedo(torpedoId: number) {
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
//
|
|
52
|
-
//
|
|
52
|
+
// TORPEDO CYCLES & TRIPS
|
|
53
53
|
//
|
|
54
54
|
await tx.torpedoCycle.deleteMany({
|
|
55
55
|
where: { torpedoId },
|
|
@@ -60,7 +60,7 @@ async function deleteTorpedo(torpedoId: number) {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
//
|
|
63
|
-
//
|
|
63
|
+
// HOT METAL + LAB RESULTS + HOT METAL POURED
|
|
64
64
|
//
|
|
65
65
|
const hotMetals = await tx.hotMetal.findMany({
|
|
66
66
|
where: { torpedoId },
|
|
@@ -84,21 +84,41 @@ async function deleteTorpedo(torpedoId: number) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
//
|
|
87
|
-
//
|
|
87
|
+
// TORPEDO CAMPAIGNS
|
|
88
88
|
//
|
|
89
89
|
await tx.torpedoCampaign.deleteMany({
|
|
90
90
|
where: { torpedoId },
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
//
|
|
94
|
-
//
|
|
94
|
+
// TORPEDO LOCATION
|
|
95
95
|
//
|
|
96
96
|
await tx.torpedoLocation.deleteMany({
|
|
97
97
|
where: { torpedoId },
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
//
|
|
101
|
-
//
|
|
101
|
+
// NOTIFICATION + NOTIFICATION DISPLAY
|
|
102
|
+
//
|
|
103
|
+
const notifications = await tx.notification.findMany({
|
|
104
|
+
where: { torpedoId },
|
|
105
|
+
select: { id: true },
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const notificationIds = notifications.map((n) => n.id);
|
|
109
|
+
|
|
110
|
+
if (notificationIds.length > 0) {
|
|
111
|
+
await tx.notificationDisplay.deleteMany({
|
|
112
|
+
where: { notificationId: { in: notificationIds } },
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
await tx.notification.deleteMany({
|
|
116
|
+
where: { torpedoId },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
//
|
|
121
|
+
// DELETE TORPEDO LAST
|
|
102
122
|
//
|
|
103
123
|
await tx.torpedo.delete({
|
|
104
124
|
where: { torpedoId: torpedoId },
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import prisma from "./dbClient";
|
|
2
|
+
|
|
3
|
+
async function fillNullSegmentResponseIds() {
|
|
4
|
+
const resultFillSegmentResponseId = await prisma.$executeRaw`
|
|
5
|
+
UPDATE [HotMetal]
|
|
6
|
+
SET [segmentResponseId] = [id]
|
|
7
|
+
WHERE [segmentResponseId] IS null
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
console.log(`Row updated: ${resultFillSegmentResponseId}`)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
fillNullSegmentResponseIds()
|
|
14
|
+
.then(async () => {
|
|
15
|
+
await prisma.$disconnect()
|
|
16
|
+
})
|
|
17
|
+
.catch(async (e) => {
|
|
18
|
+
console.error("❌ Error:", e)
|
|
19
|
+
await prisma.$disconnect()
|
|
20
|
+
process.exit(1)
|
|
21
|
+
})
|
|
22
|
+
.finally(() => prisma.$disconnect());
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Warnings:
|
|
3
|
+
|
|
4
|
+
- A unique constraint covering the columns `[segmentResponseId]` on the table `HotMetal` will be added. If there are existing duplicate values, this will fail.
|
|
5
|
+
- Made the column `segmentResponseId` on table `HotMetal` required. This step will fail if there are existing NULL values in that column.
|
|
6
|
+
|
|
7
|
+
*/
|
|
8
|
+
BEGIN TRY
|
|
9
|
+
|
|
10
|
+
BEGIN TRAN;
|
|
11
|
+
|
|
12
|
+
-- AlterTable
|
|
13
|
+
ALTER TABLE [dbo].[HotMetal] ALTER COLUMN [segmentResponseId] NVARCHAR(1000) NOT NULL;
|
|
14
|
+
|
|
15
|
+
-- CreateIndex
|
|
16
|
+
ALTER TABLE [dbo].[HotMetal] ADD CONSTRAINT [HotMetal_segmentResponseId_key] UNIQUE NONCLUSTERED ([segmentResponseId]);
|
|
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
|
package/prisma/schema.prisma
CHANGED
|
@@ -268,7 +268,7 @@ model HotMetal {
|
|
|
268
268
|
alPucksAdded Boolean @default(false)
|
|
269
269
|
integrationStage Int @default(0)
|
|
270
270
|
pourStatus Int @default(0)
|
|
271
|
-
segmentResponseId String
|
|
271
|
+
segmentResponseId String @unique
|
|
272
272
|
hotMetalState HotMetalState? @relation(fields: [hotMetalStateId], references: [id])
|
|
273
273
|
hotMetalStateId Int?
|
|
274
274
|
hotMetalPouredCollection HotMetalPoured[]
|