@bslau/hmm_prisma_schema 1.18.0 → 1.18.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bslau/hmm_prisma_schema",
3
- "version": "1.18.0",
3
+ "version": "1.18.1",
4
4
  "main": "index.js",
5
5
  "author": "CIPA Development Team",
6
6
  "license": "ISC",
@@ -0,0 +1,134 @@
1
+ // deleteTorpedo.ts
2
+ import { PrismaClient } from "@prisma/client";
3
+
4
+ const prisma = new PrismaClient();
5
+
6
+ async function deleteTorpedo(torpedoId: number) {
7
+ await prisma.$transaction(async (tx) => {
8
+ //
9
+ // 1️⃣ COMMENTS
10
+ //
11
+ await tx.hMHComment.deleteMany({
12
+ where: { torpedoId },
13
+ });
14
+ await tx.torpedoComment.deleteMany({
15
+ where: { torpedoId },
16
+ });
17
+
18
+ //
19
+ // 2️⃣ LADLE SURVEYS
20
+ //
21
+ await tx.hMHLadleSurvey.deleteMany({
22
+ where: { torpedoId },
23
+ });
24
+
25
+ //
26
+ // 3️⃣ TORPEDO TIMER
27
+ //
28
+ await tx.torpedoTimer.deleteMany({
29
+ where: { torpedoId },
30
+ });
31
+
32
+ //
33
+ // 4️⃣ EVENT TABLES
34
+ //
35
+ await tx.eventTorpedoCapacity.deleteMany({
36
+ where: { torpedoId },
37
+ });
38
+ await tx.eventTorpedoMovement.deleteMany({
39
+ where: { torpedoId },
40
+ });
41
+ await tx.eventTorpedoMaintenance.deleteMany({
42
+ where: { torpedoId },
43
+ });
44
+ await tx.eventTorpedoOnGas.deleteMany({
45
+ where: { torpedoId },
46
+ });
47
+ await tx.eventTorpedoState.deleteMany({
48
+ where: { torpedoId },
49
+ });
50
+
51
+ //
52
+ // 5️⃣ TORPEDO CYCLES & TRIPS
53
+ //
54
+ await tx.torpedoCycle.deleteMany({
55
+ where: { torpedoId },
56
+ });
57
+
58
+ await tx.torpedoTrip.deleteMany({
59
+ where: { torpedoId },
60
+ });
61
+
62
+ //
63
+ // 6️⃣ HOT METAL + LAB RESULTS + HOT METAL POURED
64
+ //
65
+ const hotMetals = await tx.hotMetal.findMany({
66
+ where: { torpedoId },
67
+ select: { id: true },
68
+ });
69
+
70
+ const hotMetalIds = hotMetals.map((hm) => hm.id);
71
+
72
+ if (hotMetalIds.length > 0) {
73
+ await tx.hotMetalPoured.deleteMany({
74
+ where: { hotMetalId: { in: hotMetalIds } },
75
+ });
76
+
77
+ await tx.hotMetalLabResult.deleteMany({
78
+ where: { hotMetalId: { in: hotMetalIds } },
79
+ });
80
+
81
+ await tx.hotMetal.deleteMany({
82
+ where: { id: { in: hotMetalIds } },
83
+ });
84
+ }
85
+
86
+ //
87
+ // 7️⃣ TORPEDO CAMPAIGNS
88
+ //
89
+ await tx.torpedoCampaign.deleteMany({
90
+ where: { torpedoId },
91
+ });
92
+
93
+ //
94
+ // 8️⃣ TORPEDO LOCATION
95
+ //
96
+ await tx.torpedoLocation.deleteMany({
97
+ where: { torpedoId },
98
+ });
99
+
100
+ //
101
+ // 9️⃣ DELETE TORPEDO LAST
102
+ //
103
+ await tx.torpedo.delete({
104
+ where: { id: torpedoId },
105
+ });
106
+ });
107
+
108
+ console.log(`✔ Torpedo ${torpedoId} and all related data deleted successfully`);
109
+ }
110
+
111
+ async function main() {
112
+ const param = process.argv[2]; // <-- argument from CLI
113
+
114
+ if (!param) {
115
+ console.error("❌ Please provide a torpedo number.");
116
+ console.error("Usage: npx tsx functions/deleteTorpedo.ts <torpedoNumber>");
117
+ process.exit(1);
118
+ }
119
+
120
+ const torpedoNumber = parseInt(param, 10);
121
+
122
+ await deleteTorpedo(torpedoNumber); // delete torpedo safely - one torpedo at a time
123
+ }
124
+
125
+ main()
126
+ .then(async () => {
127
+ await prisma.$disconnect()
128
+ })
129
+ .catch(async (e) => {
130
+ console.error("❌ Error:", e)
131
+ await prisma.$disconnect()
132
+ process.exit(1)
133
+ })
134
+ .finally(() => prisma.$disconnect());
package/prisma/seed.ts CHANGED
@@ -43,28 +43,20 @@ async function main() {
43
43
  const createTorpedo = await prisma.torpedo.createMany({
44
44
  data: [
45
45
  { torpedoId: 18, name: "Torpedo 18", status: 2, capacityNominal: 250 },
46
- { torpedoId: 19, name: "Torpedo 19", status: 2, capacityNominal: 250 },
47
46
  { torpedoId: 20, name: "Torpedo 20", status: 2, capacityNominal: 250 },
48
47
  { torpedoId: 21, name: "Torpedo 21", status: 2, capacityNominal: 220 },
49
48
  { torpedoId: 22, name: "Torpedo 22", status: 2, capacityNominal: 250 },
50
49
  { torpedoId: 23, name: "Torpedo 23", status: 2, capacityNominal: 250 },
51
50
  { torpedoId: 24, name: "Torpedo 24", status: 2, capacityNominal: 250 },
52
51
  { torpedoId: 25, name: "Torpedo 25", status: 2, capacityNominal: 250 },
53
- { torpedoId: 27, name: "Torpedo 27", status: 2, capacityNominal: 200 },
54
52
  { torpedoId: 28, name: "Torpedo 28", status: 2, capacityNominal: 250 },
55
- { torpedoId: 29, name: "Torpedo 29", status: 2, capacityNominal: 200 },
56
53
  { torpedoId: 30, name: "Torpedo 30", status: 2, capacityNominal: 200 },
57
- { torpedoId: 31, name: "Torpedo 31", status: 2, capacityNominal: 250 },
58
- { torpedoId: 32, name: "Torpedo 32", status: 2, capacityNominal: 200 },
59
- { torpedoId: 33, name: "Torpedo 33", status: 2, capacityNominal: 200 },
60
54
  { torpedoId: 34, name: "Torpedo 34", status: 2, capacityNominal: 240 },
61
- { torpedoId: 35, name: "Torpedo 35", status: 2, capacityNominal: 200 },
62
55
  { torpedoId: 36, name: "Torpedo 36", status: 2, capacityNominal: 200 },
63
56
  { torpedoId: 37, name: "Torpedo 37", status: 2, capacityNominal: 230 },
64
57
  { torpedoId: 38, name: "Torpedo 38", status: 2, capacityNominal: 211 },
65
58
  { torpedoId: 39, name: "Torpedo 39", status: 2, capacityNominal: 220 },
66
59
  { torpedoId: 40, name: "Torpedo 40", status: 2, capacityNominal: 250 },
67
- { torpedoId: 41, name: "Torpedo 41", status: 2, capacityNominal: 250 },
68
60
  { torpedoId: 42, name: "Torpedo 42", status: 2, capacityNominal: 250 },
69
61
  { torpedoId: 43, name: "Torpedo 43", status: 2, capacityNominal: 250 },
70
62
  { torpedoId: 44, name: "Torpedo 44", status: 2, capacityNominal: 240 },