@machynx/data-db 1.0.1 → 1.0.5

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "prisma-client-42e00b689da0346759e9a69fa4866b644caacc486b410217ff27f3ba834cdb4a",
2
+ "name": "prisma-client-db84b3bd7f8e22659f71f399bf1b45e2c5ccaecfaa0d4f6d6a1ee3f72cd75398",
3
3
  "main": "index.js",
4
4
  "types": "index.d.ts",
5
5
  "browser": "default.js",
@@ -109,10 +109,10 @@
109
109
  },
110
110
  "./*": "./*"
111
111
  },
112
- "version": "7.0.0",
112
+ "version": "7.2.0",
113
113
  "sideEffects": false,
114
114
  "dependencies": {
115
- "@prisma/client-runtime-utils": "7.0.0"
115
+ "@prisma/client-runtime-utils": "7.2.0"
116
116
  },
117
117
  "imports": {
118
118
  "#wasm-compiler-loader": {
@@ -26,6 +26,8 @@ model MachineHourlyAnalytics {
26
26
 
27
27
  @@unique([organizationId, machineId, startDateTime], map: "unique_machineHourlyCompound")
28
28
  @@index([machineId, startDateTime])
29
+ @@index([organizationId, startDateTime]) // For org-wide queries
30
+ @@index([machineId, startDateTime, endDateTime]) // For range scans
29
31
  @@schema("analytics")
30
32
  }
31
33
 
@@ -240,24 +242,24 @@ model DevicePowerSensorHourlyAnalytics {
240
242
  // ----------------------------------------------------------------------
241
243
 
242
244
  model AuditLog {
243
- id BigInt @id @default(autoincrement()) @db.BigInt
244
- entityName String
245
- entityId Int?
246
- action String
247
- userId Int? // ID for CoreUser
248
- orgId Int? // ID for CoreOrganization
249
- timestamp DateTime @default(now())
250
- httpMethod String
251
- route String
252
- statusCode Int
253
- ipAddress String?
254
- userAgent String?
255
- oldValues Json?
256
- newValues Json?
245
+ id BigInt @id @default(autoincrement()) @db.BigInt
246
+ entityName String
247
+ entityId Int?
248
+ action String
249
+ userId Int? // ID for CoreUser
250
+ organizationId Int? // ID for CoreOrganization
251
+ timestamp DateTime @default(now())
252
+ httpMethod String
253
+ route String
254
+ statusCode Int
255
+ ipAddress String?
256
+ userAgent String?
257
+ oldValues Json?
258
+ newValues Json?
257
259
 
258
260
  @@index([entityName, entityId])
259
261
  @@index([userId])
260
- @@index([orgId])
262
+ @@index([organizationId])
261
263
  @@schema("audit")
262
264
  }
263
265
 
@@ -371,11 +373,11 @@ model Device {
371
373
  // PRODUCTION CRITICAL: The Link to your Global Inventory
372
374
  globalDeviceUid String @unique // Immutable ID printed on the sticker (Core DB)
373
375
 
374
- deviceUid String @unique @default(cuid()) // Local Internal ID
375
- deviceName String?
376
- isActive Boolean @default(true)
377
- orgId Int
378
- gatewayId Int?
376
+ deviceUid String @unique @default(cuid()) // Local Internal ID
377
+ deviceName String?
378
+ isActive Boolean @default(true)
379
+ organizationId Int
380
+ gatewayId Int?
379
381
 
380
382
  // Hardware
381
383
  sensors Sensor[] @relation("DeviceSensors")
@@ -400,8 +402,11 @@ model Device {
400
402
  createdAt DateTime @default(now())
401
403
  updatedAt DateTime @updatedAt
402
404
 
403
- @@index([orgId])
405
+ @@index([organizationId])
404
406
  @@index([globalDeviceUid])
407
+ @@index([gatewayId])
408
+ @@index([machineId])
409
+ @@index([factoryId])
405
410
  @@schema("device")
406
411
  }
407
412
 
@@ -487,6 +492,9 @@ model MachineDeviceAssignment {
487
492
  machine Machine @relation("MachineToDeviceAssignments", fields: [machineId], references: [id])
488
493
 
489
494
  @@index([deviceId])
495
+ @@index([machineId])
496
+ @@index([assignedAt])
497
+ @@index([unassignedAt])
490
498
  @@schema("device")
491
499
  }
492
500
 
@@ -507,6 +515,9 @@ model SensorLog {
507
515
  updatedAt DateTime @default(now())
508
516
 
509
517
  @@unique([sensorId, senseTime])
518
+ @@index([isProcessed])
519
+ @@index([sensorId, isProcessed])
520
+ @@index([senseTime])
510
521
  @@schema("device")
511
522
  }
512
523
 
@@ -523,6 +534,9 @@ model RFIDSensorLog {
523
534
  createdAt DateTime @default(now())
524
535
  updatedAt DateTime @updatedAt
525
536
 
537
+ @@index([operatorId])
538
+ @@index([rfid])
539
+ @@index([sensorLogId])
526
540
  @@schema("device")
527
541
  }
528
542
 
@@ -621,6 +635,8 @@ model Factory {
621
635
  requestCategories MaintenanceRequestCategory[] @relation("FactoryMaintenanceRequestCategories")
622
636
  hourlyAnalytics FactoryHourlyAnalytics[] @relation("FactoryToHourlyAnalytics")
623
637
 
638
+ userAccess OrganizationUserFactoryEntityAccess[] @relation("UserToFactory")
639
+
624
640
  createdAt DateTime @default(now())
625
641
  updatedAt DateTime @updatedAt
626
642
 
@@ -645,7 +661,6 @@ model Floor {
645
661
  devicesDirect Device[] @relation("FloorToDevicesDirect")
646
662
  hourlyAnalytics FloorHourlyAnalytics[] @relation("FloorToHourlyAnalytics")
647
663
 
648
- // Access Control (FIXED: Added this relation)
649
664
  userAccess OrganizationUserFactoryEntityAccess[] @relation("UserToFloors")
650
665
 
651
666
  floorTypeId Int?
@@ -692,11 +707,12 @@ model FloorSetting {
692
707
  }
693
708
 
694
709
  model AssemblyLine {
695
- id Int @id @default(autoincrement())
696
- code String?
697
- name String
698
- description String?
699
- floorId Int
710
+ id Int @id @default(autoincrement())
711
+ organizationId Int
712
+ code String?
713
+ name String
714
+ description String?
715
+ floorId Int
700
716
 
701
717
  machines Machine[] @relation("LineToMachines")
702
718
  sensors Sensor[] @relation("AssemblyLineToSensors")
@@ -979,14 +995,14 @@ enum MaintenanceLogStatus {
979
995
  }
980
996
 
981
997
  model MaintenanceLog {
982
- id Int @id @default(autoincrement())
983
- machineId Int
984
- orgId Int
985
- reportedById Int?
986
- description String?
987
- status MaintenanceLogStatus @default(OPEN)
988
- startTime DateTime?
989
- endTime DateTime?
998
+ id Int @id @default(autoincrement())
999
+ machineId Int
1000
+ organizationId Int
1001
+ reportedById Int?
1002
+ description String?
1003
+ status MaintenanceLogStatus @default(OPEN)
1004
+ startTime DateTime?
1005
+ endTime DateTime?
990
1006
 
991
1007
  machine Machine @relation("MachineMaintenance", fields: [machineId], references: [id])
992
1008
 
@@ -1132,7 +1148,8 @@ model Operator {
1132
1148
  // ERP/HR Link
1133
1149
  externalId String? // REMOVED @index here
1134
1150
 
1135
- name String?
1151
+ firstName String?
1152
+ lastName String?
1136
1153
  description String?
1137
1154
  organizationId Int?
1138
1155
  factoryId Int?
@@ -1171,6 +1188,10 @@ model OperatorTimeLog {
1171
1188
  createdAt DateTime @default(now())
1172
1189
  updatedAt DateTime @updatedAt
1173
1190
 
1191
+ @@index([operatorId, checkInAt])
1192
+ @@index([deviceId, checkInAt])
1193
+ @@index([machineId, checkInAt])
1194
+ @@index([checkInAt, checkOutAt])
1174
1195
  @@schema("operator")
1175
1196
  }
1176
1197
 
@@ -1243,6 +1264,7 @@ model Order {
1243
1264
  @@index([organizationId])
1244
1265
  @@index([customerId])
1245
1266
  @@index([factoryId])
1267
+ @@index([erpSource, externalId])
1246
1268
  @@schema("order")
1247
1269
  }
1248
1270
 
@@ -1365,17 +1387,62 @@ model ProductionUnitQC {
1365
1387
  }
1366
1388
 
1367
1389
  model OrganizationUserFactoryEntityAccess {
1368
- id Int @id @default(autoincrement())
1369
- userId Int @unique // Links to CoreUser in Core DB
1390
+ id Int @id @default(autoincrement())
1391
+ userId Int
1392
+ organizationId Int
1393
+
1394
+ factoryId Int?
1395
+ floorId Int?
1396
+ assemblyLineId Int?
1397
+ machineId Int?
1398
+
1399
+ factory Factory? @relation("UserToFactory", fields: [factoryId], references: [id], onDelete: Cascade)
1400
+ floor Floor? @relation("UserToFloors", fields: [floorId], references: [id], onDelete: Cascade)
1401
+ assemblyLine AssemblyLine? @relation("UserToAssemblyLines", fields: [assemblyLineId], references: [id], onDelete: Cascade)
1402
+ machine Machine? @relation("UserToMachines", fields: [machineId], references: [id], onDelete: Cascade)
1403
+
1370
1404
  createdAt DateTime @default(now())
1371
1405
  updatedAt DateTime @updatedAt
1372
1406
 
1373
- // Local Access Grants
1374
- floors Floor[] @relation("UserToFloors")
1375
- assemblyLines AssemblyLine[] @relation("UserToAssemblyLines")
1376
- machines Machine[] @relation("UserToMachines")
1407
+ @@unique([userId, factoryId, floorId, assemblyLineId, machineId], name: "unique_user_entity")
1408
+ @@index([userId, organizationId])
1409
+ @@index([factoryId])
1410
+ @@index([floorId])
1411
+ @@index([assemblyLineId])
1412
+ @@index([machineId])
1413
+ @@schema("organization")
1414
+ }
1377
1415
 
1378
- @@index([userId])
1416
+ model MaintenanceSpecialization {
1417
+ id Int @id @default(autoincrement())
1418
+ organizationId Int
1419
+ name String
1420
+
1421
+ @@unique([organizationId, name])
1422
+ @@schema("organization")
1423
+ }
1424
+
1425
+ model OrganizationCustomer {
1426
+ id Int @id @default(autoincrement())
1427
+ organizationId Int
1428
+ name String
1429
+ description String?
1430
+ createdAt DateTime @default(now())
1431
+ updatedAt DateTime @updatedAt
1432
+
1433
+ @@index([organizationId])
1434
+ @@schema("organization")
1435
+ }
1436
+
1437
+ model AssemblyLineType {
1438
+ id Int @id @default(autoincrement())
1439
+ name String
1440
+ organizationId Int
1441
+ createdAt DateTime @default(now())
1442
+ updatedAt DateTime @updatedAt
1443
+
1444
+ @@unique([organizationId, name])
1445
+ @@index([organizationId])
1379
1446
  @@schema("organization")
1380
1447
  }
1381
1448
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machynx/data-db",
3
- "version": "1.0.1",
3
+ "version": "1.0.5",
4
4
  "description": "Machynx Data Plane Database - Shared Prisma schema & client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -21,9 +21,9 @@
21
21
  "db:push": "prisma db push --skip-generate",
22
22
  "db:seed": "ts-node prisma/seed.ts",
23
23
  "prisma:studio": "prisma studio",
24
- "release:patch": "npm version patch -m \"chore: release v%s\" && yarn release:git",
25
- "release:minor": "npm version minor -m \"chore: release v%s\" && yarn release:git",
26
- "release:major": "npm version major -m \"chore: release v%s\" && yarn release:git",
24
+ "release:patch": "npm version patch -m \"chore: release v%s\" && npm run release:git",
25
+ "release:minor": "npm version minor -m \"chore: release v%s\" && npm run release:git",
26
+ "release:major": "npm version major -m \"chore: release v%s\" && npm run release:git",
27
27
  "release:git": "git push && git push --tags",
28
28
  "release:publish": "npm publish --access public"
29
29
  },
@@ -58,8 +58,8 @@
58
58
  "prisma": "^7.0.0"
59
59
  },
60
60
  "devDependencies": {
61
- "@types/node": "^24.10.1",
62
- "prisma": "^7.0.0",
61
+ "@types/node": "^25.0.7",
62
+ "prisma": "^7.2.0",
63
63
  "ts-node": "^10.9.2",
64
64
  "typescript": "^5.9.3"
65
65
  }
@@ -275,7 +275,7 @@ CREATE TABLE "audit"."AuditLog" (
275
275
  "entityId" INTEGER,
276
276
  "action" TEXT NOT NULL,
277
277
  "userId" INTEGER,
278
- "orgId" INTEGER,
278
+ "organizationId" INTEGER,
279
279
  "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
280
280
  "httpMethod" TEXT NOT NULL,
281
281
  "route" TEXT NOT NULL,
@@ -352,7 +352,7 @@ CREATE TABLE "device"."Device" (
352
352
  "deviceUid" TEXT NOT NULL,
353
353
  "deviceName" TEXT,
354
354
  "isActive" BOOLEAN NOT NULL DEFAULT true,
355
- "orgId" INTEGER NOT NULL,
355
+ "organizationId" INTEGER NOT NULL,
356
356
  "gatewayId" INTEGER,
357
357
  "machineId" INTEGER,
358
358
  "assemblyLineId" INTEGER,
@@ -561,6 +561,7 @@ CREATE TABLE "factory"."FloorSetting" (
561
561
  -- CreateTable
562
562
  CREATE TABLE "factory"."AssemblyLine" (
563
563
  "id" SERIAL NOT NULL,
564
+ "organizationId" INTEGER NOT NULL,
564
565
  "code" TEXT,
565
566
  "name" TEXT NOT NULL,
566
567
  "description" TEXT,
@@ -726,7 +727,7 @@ CREATE TABLE "machine"."MachineAlertSubscription" (
726
727
  CREATE TABLE "maintenance"."MaintenanceLog" (
727
728
  "id" SERIAL NOT NULL,
728
729
  "machineId" INTEGER NOT NULL,
729
- "orgId" INTEGER NOT NULL,
730
+ "organizationId" INTEGER NOT NULL,
730
731
  "reportedById" INTEGER,
731
732
  "description" TEXT,
732
733
  "status" "maintenance"."MaintenanceLogStatus" NOT NULL DEFAULT 'OPEN',
@@ -837,7 +838,8 @@ CREATE TABLE "operator"."Operator" (
837
838
  "id" SERIAL NOT NULL,
838
839
  "rfid" TEXT,
839
840
  "externalId" TEXT,
840
- "name" TEXT,
841
+ "firstName" TEXT,
842
+ "lastName" TEXT,
841
843
  "description" TEXT,
842
844
  "organizationId" INTEGER,
843
845
  "factoryId" INTEGER,
@@ -979,12 +981,49 @@ CREATE TABLE "production_tracking"."ProductionUnitQC" (
979
981
  CREATE TABLE "organization"."OrganizationUserFactoryEntityAccess" (
980
982
  "id" SERIAL NOT NULL,
981
983
  "userId" INTEGER NOT NULL,
984
+ "organizationId" INTEGER NOT NULL,
985
+ "factoryId" INTEGER,
986
+ "floorId" INTEGER,
987
+ "assemblyLineId" INTEGER,
988
+ "machineId" INTEGER,
982
989
  "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
983
990
  "updatedAt" TIMESTAMP(3) NOT NULL,
984
991
 
985
992
  CONSTRAINT "OrganizationUserFactoryEntityAccess_pkey" PRIMARY KEY ("id")
986
993
  );
987
994
 
995
+ -- CreateTable
996
+ CREATE TABLE "organization"."MaintenanceSpecialization" (
997
+ "id" SERIAL NOT NULL,
998
+ "organizationId" INTEGER NOT NULL,
999
+ "name" TEXT NOT NULL,
1000
+
1001
+ CONSTRAINT "MaintenanceSpecialization_pkey" PRIMARY KEY ("id")
1002
+ );
1003
+
1004
+ -- CreateTable
1005
+ CREATE TABLE "organization"."OrganizationCustomer" (
1006
+ "id" SERIAL NOT NULL,
1007
+ "organizationId" INTEGER NOT NULL,
1008
+ "name" TEXT NOT NULL,
1009
+ "description" TEXT,
1010
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
1011
+ "updatedAt" TIMESTAMP(3) NOT NULL,
1012
+
1013
+ CONSTRAINT "OrganizationCustomer_pkey" PRIMARY KEY ("id")
1014
+ );
1015
+
1016
+ -- CreateTable
1017
+ CREATE TABLE "organization"."AssemblyLineType" (
1018
+ "id" SERIAL NOT NULL,
1019
+ "name" TEXT NOT NULL,
1020
+ "organizationId" INTEGER NOT NULL,
1021
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
1022
+ "updatedAt" TIMESTAMP(3) NOT NULL,
1023
+
1024
+ CONSTRAINT "AssemblyLineType_pkey" PRIMARY KEY ("id")
1025
+ );
1026
+
988
1027
  -- CreateTable
989
1028
  CREATE TABLE "tasks"."OperatorOperationCategory" (
990
1029
  "id" SERIAL NOT NULL,
@@ -1096,32 +1135,14 @@ CREATE TABLE "tasks"."TaskComment" (
1096
1135
  CONSTRAINT "TaskComment_pkey" PRIMARY KEY ("id")
1097
1136
  );
1098
1137
 
1099
- -- CreateTable
1100
- CREATE TABLE "factory"."_UserToFloors" (
1101
- "A" INTEGER NOT NULL,
1102
- "B" INTEGER NOT NULL,
1103
-
1104
- CONSTRAINT "_UserToFloors_AB_pkey" PRIMARY KEY ("A","B")
1105
- );
1106
-
1107
- -- CreateTable
1108
- CREATE TABLE "factory"."_UserToAssemblyLines" (
1109
- "A" INTEGER NOT NULL,
1110
- "B" INTEGER NOT NULL,
1111
-
1112
- CONSTRAINT "_UserToAssemblyLines_AB_pkey" PRIMARY KEY ("A","B")
1113
- );
1114
-
1115
- -- CreateTable
1116
- CREATE TABLE "machine"."_UserToMachines" (
1117
- "A" INTEGER NOT NULL,
1118
- "B" INTEGER NOT NULL,
1138
+ -- CreateIndex
1139
+ CREATE INDEX "MachineHourlyAnalytics_machineId_startDateTime_idx" ON "analytics"."MachineHourlyAnalytics"("machineId", "startDateTime");
1119
1140
 
1120
- CONSTRAINT "_UserToMachines_AB_pkey" PRIMARY KEY ("A","B")
1121
- );
1141
+ -- CreateIndex
1142
+ CREATE INDEX "MachineHourlyAnalytics_organizationId_startDateTime_idx" ON "analytics"."MachineHourlyAnalytics"("organizationId", "startDateTime");
1122
1143
 
1123
1144
  -- CreateIndex
1124
- CREATE INDEX "MachineHourlyAnalytics_machineId_startDateTime_idx" ON "analytics"."MachineHourlyAnalytics"("machineId", "startDateTime");
1145
+ CREATE INDEX "MachineHourlyAnalytics_machineId_startDateTime_endDateTime_idx" ON "analytics"."MachineHourlyAnalytics"("machineId", "startDateTime", "endDateTime");
1125
1146
 
1126
1147
  -- CreateIndex
1127
1148
  CREATE UNIQUE INDEX "unique_machineHourlyCompound" ON "analytics"."MachineHourlyAnalytics"("organizationId", "machineId", "startDateTime");
@@ -1166,7 +1187,7 @@ CREATE INDEX "AuditLog_entityName_entityId_idx" ON "audit"."AuditLog"("entityNam
1166
1187
  CREATE INDEX "AuditLog_userId_idx" ON "audit"."AuditLog"("userId");
1167
1188
 
1168
1189
  -- CreateIndex
1169
- CREATE INDEX "AuditLog_orgId_idx" ON "audit"."AuditLog"("orgId");
1190
+ CREATE INDEX "AuditLog_organizationId_idx" ON "audit"."AuditLog"("organizationId");
1170
1191
 
1171
1192
  -- CreateIndex
1172
1193
  CREATE INDEX "ChatbotHistory_userId_idx" ON "chatbot"."ChatbotHistory"("userId");
@@ -1202,11 +1223,20 @@ CREATE UNIQUE INDEX "Device_globalDeviceUid_key" ON "device"."Device"("globalDev
1202
1223
  CREATE UNIQUE INDEX "Device_deviceUid_key" ON "device"."Device"("deviceUid");
1203
1224
 
1204
1225
  -- CreateIndex
1205
- CREATE INDEX "Device_orgId_idx" ON "device"."Device"("orgId");
1226
+ CREATE INDEX "Device_organizationId_idx" ON "device"."Device"("organizationId");
1206
1227
 
1207
1228
  -- CreateIndex
1208
1229
  CREATE INDEX "Device_globalDeviceUid_idx" ON "device"."Device"("globalDeviceUid");
1209
1230
 
1231
+ -- CreateIndex
1232
+ CREATE INDEX "Device_gatewayId_idx" ON "device"."Device"("gatewayId");
1233
+
1234
+ -- CreateIndex
1235
+ CREATE INDEX "Device_machineId_idx" ON "device"."Device"("machineId");
1236
+
1237
+ -- CreateIndex
1238
+ CREATE INDEX "Device_factoryId_idx" ON "device"."Device"("factoryId");
1239
+
1210
1240
  -- CreateIndex
1211
1241
  CREATE UNIQUE INDEX "Sensor_sensorUid_key" ON "device"."Sensor"("sensorUid");
1212
1242
 
@@ -1225,12 +1255,39 @@ CREATE UNIQUE INDEX "InfraredSensorConfig_sensorId_key" ON "device"."InfraredSen
1225
1255
  -- CreateIndex
1226
1256
  CREATE INDEX "MachineDeviceAssignment_deviceId_idx" ON "device"."MachineDeviceAssignment"("deviceId");
1227
1257
 
1258
+ -- CreateIndex
1259
+ CREATE INDEX "MachineDeviceAssignment_machineId_idx" ON "device"."MachineDeviceAssignment"("machineId");
1260
+
1261
+ -- CreateIndex
1262
+ CREATE INDEX "MachineDeviceAssignment_assignedAt_idx" ON "device"."MachineDeviceAssignment"("assignedAt");
1263
+
1264
+ -- CreateIndex
1265
+ CREATE INDEX "MachineDeviceAssignment_unassignedAt_idx" ON "device"."MachineDeviceAssignment"("unassignedAt");
1266
+
1267
+ -- CreateIndex
1268
+ CREATE INDEX "SensorLog_isProcessed_idx" ON "device"."SensorLog"("isProcessed");
1269
+
1270
+ -- CreateIndex
1271
+ CREATE INDEX "SensorLog_sensorId_isProcessed_idx" ON "device"."SensorLog"("sensorId", "isProcessed");
1272
+
1273
+ -- CreateIndex
1274
+ CREATE INDEX "SensorLog_senseTime_idx" ON "device"."SensorLog"("senseTime");
1275
+
1228
1276
  -- CreateIndex
1229
1277
  CREATE UNIQUE INDEX "SensorLog_sensorId_senseTime_key" ON "device"."SensorLog"("sensorId", "senseTime");
1230
1278
 
1231
1279
  -- CreateIndex
1232
1280
  CREATE UNIQUE INDEX "RFIDSensorLog_sensorLogId_key" ON "device"."RFIDSensorLog"("sensorLogId");
1233
1281
 
1282
+ -- CreateIndex
1283
+ CREATE INDEX "RFIDSensorLog_operatorId_idx" ON "device"."RFIDSensorLog"("operatorId");
1284
+
1285
+ -- CreateIndex
1286
+ CREATE INDEX "RFIDSensorLog_rfid_idx" ON "device"."RFIDSensorLog"("rfid");
1287
+
1288
+ -- CreateIndex
1289
+ CREATE INDEX "RFIDSensorLog_sensorLogId_idx" ON "device"."RFIDSensorLog"("sensorLogId");
1290
+
1234
1291
  -- CreateIndex
1235
1292
  CREATE UNIQUE INDEX "ProximitySensorLog_sensorLogId_key" ON "device"."ProximitySensorLog"("sensorLogId");
1236
1293
 
@@ -1297,6 +1354,18 @@ CREATE INDEX "Operator_externalId_idx" ON "operator"."Operator"("externalId");
1297
1354
  -- CreateIndex
1298
1355
  CREATE UNIQUE INDEX "Operator_organizationId_rfid_key" ON "operator"."Operator"("organizationId", "rfid");
1299
1356
 
1357
+ -- CreateIndex
1358
+ CREATE INDEX "OperatorTimeLog_operatorId_checkInAt_idx" ON "operator"."OperatorTimeLog"("operatorId", "checkInAt");
1359
+
1360
+ -- CreateIndex
1361
+ CREATE INDEX "OperatorTimeLog_deviceId_checkInAt_idx" ON "operator"."OperatorTimeLog"("deviceId", "checkInAt");
1362
+
1363
+ -- CreateIndex
1364
+ CREATE INDEX "OperatorTimeLog_machineId_checkInAt_idx" ON "operator"."OperatorTimeLog"("machineId", "checkInAt");
1365
+
1366
+ -- CreateIndex
1367
+ CREATE INDEX "OperatorTimeLog_checkInAt_checkOutAt_idx" ON "operator"."OperatorTimeLog"("checkInAt", "checkOutAt");
1368
+
1300
1369
  -- CreateIndex
1301
1370
  CREATE UNIQUE INDEX "Order_externalId_key" ON "order"."Order"("externalId");
1302
1371
 
@@ -1309,6 +1378,9 @@ CREATE INDEX "Order_customerId_idx" ON "order"."Order"("customerId");
1309
1378
  -- CreateIndex
1310
1379
  CREATE INDEX "Order_factoryId_idx" ON "order"."Order"("factoryId");
1311
1380
 
1381
+ -- CreateIndex
1382
+ CREATE INDEX "Order_erpSource_externalId_idx" ON "order"."Order"("erpSource", "externalId");
1383
+
1312
1384
  -- CreateIndex
1313
1385
  CREATE INDEX "OrderProduct_orderId_idx" ON "order"."OrderProduct"("orderId");
1314
1386
 
@@ -1340,34 +1412,49 @@ CREATE INDEX "ProductionUnitLog_productionUnitId_idx" ON "production_tracking"."
1340
1412
  CREATE UNIQUE INDEX "ProductionRouteStep_productionUnitId_key" ON "production_tracking"."ProductionRouteStep"("productionUnitId");
1341
1413
 
1342
1414
  -- CreateIndex
1343
- CREATE UNIQUE INDEX "OrganizationUserFactoryEntityAccess_userId_key" ON "organization"."OrganizationUserFactoryEntityAccess"("userId");
1415
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_userId_organizationId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("userId", "organizationId");
1344
1416
 
1345
1417
  -- CreateIndex
1346
- CREATE INDEX "OrganizationUserFactoryEntityAccess_userId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("userId");
1418
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_factoryId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("factoryId");
1347
1419
 
1348
1420
  -- CreateIndex
1349
- CREATE INDEX "OperatorOperationCategory_factoryId_idx" ON "tasks"."OperatorOperationCategory"("factoryId");
1421
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_floorId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("floorId");
1350
1422
 
1351
1423
  -- CreateIndex
1352
- CREATE INDEX "Task_shiftId_idx" ON "tasks"."Task"("shiftId");
1424
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_assemblyLineId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("assemblyLineId");
1353
1425
 
1354
1426
  -- CreateIndex
1355
- CREATE INDEX "Task_taskGroupId_idx" ON "tasks"."Task"("taskGroupId");
1427
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_machineId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("machineId");
1356
1428
 
1357
1429
  -- CreateIndex
1358
- CREATE UNIQUE INDEX "TaskLot_taskId_lotId_key" ON "tasks"."TaskLot"("taskId", "lotId");
1430
+ CREATE UNIQUE INDEX "OrganizationUserFactoryEntityAccess_userId_factoryId_floorI_key" ON "organization"."OrganizationUserFactoryEntityAccess"("userId", "factoryId", "floorId", "assemblyLineId", "machineId");
1359
1431
 
1360
1432
  -- CreateIndex
1361
- CREATE UNIQUE INDEX "TaskGroupLot_taskGroupId_lotId_key" ON "tasks"."TaskGroupLot"("taskGroupId", "lotId");
1433
+ CREATE UNIQUE INDEX "MaintenanceSpecialization_organizationId_name_key" ON "organization"."MaintenanceSpecialization"("organizationId", "name");
1434
+
1435
+ -- CreateIndex
1436
+ CREATE INDEX "OrganizationCustomer_organizationId_idx" ON "organization"."OrganizationCustomer"("organizationId");
1437
+
1438
+ -- CreateIndex
1439
+ CREATE INDEX "AssemblyLineType_organizationId_idx" ON "organization"."AssemblyLineType"("organizationId");
1362
1440
 
1363
1441
  -- CreateIndex
1364
- CREATE INDEX "_UserToFloors_B_index" ON "factory"."_UserToFloors"("B");
1442
+ CREATE UNIQUE INDEX "AssemblyLineType_organizationId_name_key" ON "organization"."AssemblyLineType"("organizationId", "name");
1365
1443
 
1366
1444
  -- CreateIndex
1367
- CREATE INDEX "_UserToAssemblyLines_B_index" ON "factory"."_UserToAssemblyLines"("B");
1445
+ CREATE INDEX "OperatorOperationCategory_factoryId_idx" ON "tasks"."OperatorOperationCategory"("factoryId");
1446
+
1447
+ -- CreateIndex
1448
+ CREATE INDEX "Task_shiftId_idx" ON "tasks"."Task"("shiftId");
1449
+
1450
+ -- CreateIndex
1451
+ CREATE INDEX "Task_taskGroupId_idx" ON "tasks"."Task"("taskGroupId");
1452
+
1453
+ -- CreateIndex
1454
+ CREATE UNIQUE INDEX "TaskLot_taskId_lotId_key" ON "tasks"."TaskLot"("taskId", "lotId");
1368
1455
 
1369
1456
  -- CreateIndex
1370
- CREATE INDEX "_UserToMachines_B_index" ON "machine"."_UserToMachines"("B");
1457
+ CREATE UNIQUE INDEX "TaskGroupLot_taskGroupId_lotId_key" ON "tasks"."TaskGroupLot"("taskGroupId", "lotId");
1371
1458
 
1372
1459
  -- AddForeignKey
1373
1460
  ALTER TABLE "analytics"."MachineHourlyAnalytics" ADD CONSTRAINT "MachineHourlyAnalytics_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "machine"."Machine"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -1609,6 +1696,18 @@ ALTER TABLE "production_tracking"."ProductionRouteStep" ADD CONSTRAINT "Producti
1609
1696
  -- AddForeignKey
1610
1697
  ALTER TABLE "production_tracking"."ProductionUnitQC" ADD CONSTRAINT "ProductionUnitQC_productionUnitId_fkey" FOREIGN KEY ("productionUnitId") REFERENCES "production_tracking"."ProductionUnit"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
1611
1698
 
1699
+ -- AddForeignKey
1700
+ ALTER TABLE "organization"."OrganizationUserFactoryEntityAccess" ADD CONSTRAINT "OrganizationUserFactoryEntityAccess_factoryId_fkey" FOREIGN KEY ("factoryId") REFERENCES "factory"."Factory"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1701
+
1702
+ -- AddForeignKey
1703
+ ALTER TABLE "organization"."OrganizationUserFactoryEntityAccess" ADD CONSTRAINT "OrganizationUserFactoryEntityAccess_floorId_fkey" FOREIGN KEY ("floorId") REFERENCES "factory"."Floor"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1704
+
1705
+ -- AddForeignKey
1706
+ ALTER TABLE "organization"."OrganizationUserFactoryEntityAccess" ADD CONSTRAINT "OrganizationUserFactoryEntityAccess_assemblyLineId_fkey" FOREIGN KEY ("assemblyLineId") REFERENCES "factory"."AssemblyLine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1707
+
1708
+ -- AddForeignKey
1709
+ ALTER TABLE "organization"."OrganizationUserFactoryEntityAccess" ADD CONSTRAINT "OrganizationUserFactoryEntityAccess_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "machine"."Machine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1710
+
1612
1711
  -- AddForeignKey
1613
1712
  ALTER TABLE "tasks"."OperatorOperationCategory" ADD CONSTRAINT "OperatorOperationCategory_factoryId_fkey" FOREIGN KEY ("factoryId") REFERENCES "factory"."Factory"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
1614
1713
 
@@ -1668,21 +1767,3 @@ ALTER TABLE "tasks"."TaskInspection" ADD CONSTRAINT "TaskInspection_taskId_fkey"
1668
1767
 
1669
1768
  -- AddForeignKey
1670
1769
  ALTER TABLE "tasks"."TaskComment" ADD CONSTRAINT "TaskComment_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "tasks"."Task"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
1671
-
1672
- -- AddForeignKey
1673
- ALTER TABLE "factory"."_UserToFloors" ADD CONSTRAINT "_UserToFloors_A_fkey" FOREIGN KEY ("A") REFERENCES "factory"."Floor"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1674
-
1675
- -- AddForeignKey
1676
- ALTER TABLE "factory"."_UserToFloors" ADD CONSTRAINT "_UserToFloors_B_fkey" FOREIGN KEY ("B") REFERENCES "organization"."OrganizationUserFactoryEntityAccess"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1677
-
1678
- -- AddForeignKey
1679
- ALTER TABLE "factory"."_UserToAssemblyLines" ADD CONSTRAINT "_UserToAssemblyLines_A_fkey" FOREIGN KEY ("A") REFERENCES "factory"."AssemblyLine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1680
-
1681
- -- AddForeignKey
1682
- ALTER TABLE "factory"."_UserToAssemblyLines" ADD CONSTRAINT "_UserToAssemblyLines_B_fkey" FOREIGN KEY ("B") REFERENCES "organization"."OrganizationUserFactoryEntityAccess"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1683
-
1684
- -- AddForeignKey
1685
- ALTER TABLE "machine"."_UserToMachines" ADD CONSTRAINT "_UserToMachines_A_fkey" FOREIGN KEY ("A") REFERENCES "machine"."Machine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1686
-
1687
- -- AddForeignKey
1688
- ALTER TABLE "machine"."_UserToMachines" ADD CONSTRAINT "_UserToMachines_B_fkey" FOREIGN KEY ("B") REFERENCES "organization"."OrganizationUserFactoryEntityAccess"("id") ON DELETE CASCADE ON UPDATE CASCADE;