@machynx/data-db 1.0.1 → 1.0.4

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-dc8ca5ca13bedb37e8d4d0350444242b69929018853f9ee7e4753b5342df10b3",
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
 
@@ -1171,6 +1187,10 @@ model OperatorTimeLog {
1171
1187
  createdAt DateTime @default(now())
1172
1188
  updatedAt DateTime @updatedAt
1173
1189
 
1190
+ @@index([operatorId, checkInAt])
1191
+ @@index([deviceId, checkInAt])
1192
+ @@index([machineId, checkInAt])
1193
+ @@index([checkInAt, checkOutAt])
1174
1194
  @@schema("operator")
1175
1195
  }
1176
1196
 
@@ -1243,6 +1263,7 @@ model Order {
1243
1263
  @@index([organizationId])
1244
1264
  @@index([customerId])
1245
1265
  @@index([factoryId])
1266
+ @@index([erpSource, externalId])
1246
1267
  @@schema("order")
1247
1268
  }
1248
1269
 
@@ -1365,17 +1386,62 @@ model ProductionUnitQC {
1365
1386
  }
1366
1387
 
1367
1388
  model OrganizationUserFactoryEntityAccess {
1368
- id Int @id @default(autoincrement())
1369
- userId Int @unique // Links to CoreUser in Core DB
1389
+ id Int @id @default(autoincrement())
1390
+ userId Int
1391
+ organizationId Int
1392
+
1393
+ factoryId Int?
1394
+ floorId Int?
1395
+ assemblyLineId Int?
1396
+ machineId Int?
1397
+
1398
+ factory Factory? @relation("UserToFactory", fields: [factoryId], references: [id], onDelete: Cascade)
1399
+ floor Floor? @relation("UserToFloors", fields: [floorId], references: [id], onDelete: Cascade)
1400
+ assemblyLine AssemblyLine? @relation("UserToAssemblyLines", fields: [assemblyLineId], references: [id], onDelete: Cascade)
1401
+ machine Machine? @relation("UserToMachines", fields: [machineId], references: [id], onDelete: Cascade)
1402
+
1370
1403
  createdAt DateTime @default(now())
1371
1404
  updatedAt DateTime @updatedAt
1372
1405
 
1373
- // Local Access Grants
1374
- floors Floor[] @relation("UserToFloors")
1375
- assemblyLines AssemblyLine[] @relation("UserToAssemblyLines")
1376
- machines Machine[] @relation("UserToMachines")
1406
+ @@unique([userId, factoryId, floorId, assemblyLineId, machineId], name: "unique_user_entity")
1407
+ @@index([userId, organizationId])
1408
+ @@index([factoryId])
1409
+ @@index([floorId])
1410
+ @@index([assemblyLineId])
1411
+ @@index([machineId])
1412
+ @@schema("organization")
1413
+ }
1377
1414
 
1378
- @@index([userId])
1415
+ model MaintenanceSpecialization {
1416
+ id Int @id @default(autoincrement())
1417
+ organizationId Int
1418
+ name String
1419
+
1420
+ @@unique([organizationId, name])
1421
+ @@schema("organization")
1422
+ }
1423
+
1424
+ model OrganizationCustomer {
1425
+ id Int @id @default(autoincrement())
1426
+ organizationId Int
1427
+ name String
1428
+ description String?
1429
+ createdAt DateTime @default(now())
1430
+ updatedAt DateTime @updatedAt
1431
+
1432
+ @@index([organizationId])
1433
+ @@schema("organization")
1434
+ }
1435
+
1436
+ model AssemblyLineType {
1437
+ id Int @id @default(autoincrement())
1438
+ name String
1439
+ organizationId Int
1440
+ createdAt DateTime @default(now())
1441
+ updatedAt DateTime @updatedAt
1442
+
1443
+ @@unique([organizationId, name])
1444
+ @@index([organizationId])
1379
1445
  @@schema("organization")
1380
1446
  }
1381
1447
 
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.4",
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',
@@ -979,12 +980,49 @@ CREATE TABLE "production_tracking"."ProductionUnitQC" (
979
980
  CREATE TABLE "organization"."OrganizationUserFactoryEntityAccess" (
980
981
  "id" SERIAL NOT NULL,
981
982
  "userId" INTEGER NOT NULL,
983
+ "organizationId" INTEGER NOT NULL,
984
+ "factoryId" INTEGER,
985
+ "floorId" INTEGER,
986
+ "assemblyLineId" INTEGER,
987
+ "machineId" INTEGER,
982
988
  "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
983
989
  "updatedAt" TIMESTAMP(3) NOT NULL,
984
990
 
985
991
  CONSTRAINT "OrganizationUserFactoryEntityAccess_pkey" PRIMARY KEY ("id")
986
992
  );
987
993
 
994
+ -- CreateTable
995
+ CREATE TABLE "organization"."MaintenanceSpecialization" (
996
+ "id" SERIAL NOT NULL,
997
+ "organizationId" INTEGER NOT NULL,
998
+ "name" TEXT NOT NULL,
999
+
1000
+ CONSTRAINT "MaintenanceSpecialization_pkey" PRIMARY KEY ("id")
1001
+ );
1002
+
1003
+ -- CreateTable
1004
+ CREATE TABLE "organization"."OrganizationCustomer" (
1005
+ "id" SERIAL NOT NULL,
1006
+ "organizationId" INTEGER NOT NULL,
1007
+ "name" TEXT NOT NULL,
1008
+ "description" TEXT,
1009
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
1010
+ "updatedAt" TIMESTAMP(3) NOT NULL,
1011
+
1012
+ CONSTRAINT "OrganizationCustomer_pkey" PRIMARY KEY ("id")
1013
+ );
1014
+
1015
+ -- CreateTable
1016
+ CREATE TABLE "organization"."AssemblyLineType" (
1017
+ "id" SERIAL NOT NULL,
1018
+ "name" TEXT NOT NULL,
1019
+ "organizationId" INTEGER NOT NULL,
1020
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
1021
+ "updatedAt" TIMESTAMP(3) NOT NULL,
1022
+
1023
+ CONSTRAINT "AssemblyLineType_pkey" PRIMARY KEY ("id")
1024
+ );
1025
+
988
1026
  -- CreateTable
989
1027
  CREATE TABLE "tasks"."OperatorOperationCategory" (
990
1028
  "id" SERIAL NOT NULL,
@@ -1096,32 +1134,14 @@ CREATE TABLE "tasks"."TaskComment" (
1096
1134
  CONSTRAINT "TaskComment_pkey" PRIMARY KEY ("id")
1097
1135
  );
1098
1136
 
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,
1137
+ -- CreateIndex
1138
+ CREATE INDEX "MachineHourlyAnalytics_machineId_startDateTime_idx" ON "analytics"."MachineHourlyAnalytics"("machineId", "startDateTime");
1119
1139
 
1120
- CONSTRAINT "_UserToMachines_AB_pkey" PRIMARY KEY ("A","B")
1121
- );
1140
+ -- CreateIndex
1141
+ CREATE INDEX "MachineHourlyAnalytics_organizationId_startDateTime_idx" ON "analytics"."MachineHourlyAnalytics"("organizationId", "startDateTime");
1122
1142
 
1123
1143
  -- CreateIndex
1124
- CREATE INDEX "MachineHourlyAnalytics_machineId_startDateTime_idx" ON "analytics"."MachineHourlyAnalytics"("machineId", "startDateTime");
1144
+ CREATE INDEX "MachineHourlyAnalytics_machineId_startDateTime_endDateTime_idx" ON "analytics"."MachineHourlyAnalytics"("machineId", "startDateTime", "endDateTime");
1125
1145
 
1126
1146
  -- CreateIndex
1127
1147
  CREATE UNIQUE INDEX "unique_machineHourlyCompound" ON "analytics"."MachineHourlyAnalytics"("organizationId", "machineId", "startDateTime");
@@ -1166,7 +1186,7 @@ CREATE INDEX "AuditLog_entityName_entityId_idx" ON "audit"."AuditLog"("entityNam
1166
1186
  CREATE INDEX "AuditLog_userId_idx" ON "audit"."AuditLog"("userId");
1167
1187
 
1168
1188
  -- CreateIndex
1169
- CREATE INDEX "AuditLog_orgId_idx" ON "audit"."AuditLog"("orgId");
1189
+ CREATE INDEX "AuditLog_organizationId_idx" ON "audit"."AuditLog"("organizationId");
1170
1190
 
1171
1191
  -- CreateIndex
1172
1192
  CREATE INDEX "ChatbotHistory_userId_idx" ON "chatbot"."ChatbotHistory"("userId");
@@ -1202,11 +1222,20 @@ CREATE UNIQUE INDEX "Device_globalDeviceUid_key" ON "device"."Device"("globalDev
1202
1222
  CREATE UNIQUE INDEX "Device_deviceUid_key" ON "device"."Device"("deviceUid");
1203
1223
 
1204
1224
  -- CreateIndex
1205
- CREATE INDEX "Device_orgId_idx" ON "device"."Device"("orgId");
1225
+ CREATE INDEX "Device_organizationId_idx" ON "device"."Device"("organizationId");
1206
1226
 
1207
1227
  -- CreateIndex
1208
1228
  CREATE INDEX "Device_globalDeviceUid_idx" ON "device"."Device"("globalDeviceUid");
1209
1229
 
1230
+ -- CreateIndex
1231
+ CREATE INDEX "Device_gatewayId_idx" ON "device"."Device"("gatewayId");
1232
+
1233
+ -- CreateIndex
1234
+ CREATE INDEX "Device_machineId_idx" ON "device"."Device"("machineId");
1235
+
1236
+ -- CreateIndex
1237
+ CREATE INDEX "Device_factoryId_idx" ON "device"."Device"("factoryId");
1238
+
1210
1239
  -- CreateIndex
1211
1240
  CREATE UNIQUE INDEX "Sensor_sensorUid_key" ON "device"."Sensor"("sensorUid");
1212
1241
 
@@ -1225,12 +1254,39 @@ CREATE UNIQUE INDEX "InfraredSensorConfig_sensorId_key" ON "device"."InfraredSen
1225
1254
  -- CreateIndex
1226
1255
  CREATE INDEX "MachineDeviceAssignment_deviceId_idx" ON "device"."MachineDeviceAssignment"("deviceId");
1227
1256
 
1257
+ -- CreateIndex
1258
+ CREATE INDEX "MachineDeviceAssignment_machineId_idx" ON "device"."MachineDeviceAssignment"("machineId");
1259
+
1260
+ -- CreateIndex
1261
+ CREATE INDEX "MachineDeviceAssignment_assignedAt_idx" ON "device"."MachineDeviceAssignment"("assignedAt");
1262
+
1263
+ -- CreateIndex
1264
+ CREATE INDEX "MachineDeviceAssignment_unassignedAt_idx" ON "device"."MachineDeviceAssignment"("unassignedAt");
1265
+
1266
+ -- CreateIndex
1267
+ CREATE INDEX "SensorLog_isProcessed_idx" ON "device"."SensorLog"("isProcessed");
1268
+
1269
+ -- CreateIndex
1270
+ CREATE INDEX "SensorLog_sensorId_isProcessed_idx" ON "device"."SensorLog"("sensorId", "isProcessed");
1271
+
1272
+ -- CreateIndex
1273
+ CREATE INDEX "SensorLog_senseTime_idx" ON "device"."SensorLog"("senseTime");
1274
+
1228
1275
  -- CreateIndex
1229
1276
  CREATE UNIQUE INDEX "SensorLog_sensorId_senseTime_key" ON "device"."SensorLog"("sensorId", "senseTime");
1230
1277
 
1231
1278
  -- CreateIndex
1232
1279
  CREATE UNIQUE INDEX "RFIDSensorLog_sensorLogId_key" ON "device"."RFIDSensorLog"("sensorLogId");
1233
1280
 
1281
+ -- CreateIndex
1282
+ CREATE INDEX "RFIDSensorLog_operatorId_idx" ON "device"."RFIDSensorLog"("operatorId");
1283
+
1284
+ -- CreateIndex
1285
+ CREATE INDEX "RFIDSensorLog_rfid_idx" ON "device"."RFIDSensorLog"("rfid");
1286
+
1287
+ -- CreateIndex
1288
+ CREATE INDEX "RFIDSensorLog_sensorLogId_idx" ON "device"."RFIDSensorLog"("sensorLogId");
1289
+
1234
1290
  -- CreateIndex
1235
1291
  CREATE UNIQUE INDEX "ProximitySensorLog_sensorLogId_key" ON "device"."ProximitySensorLog"("sensorLogId");
1236
1292
 
@@ -1297,6 +1353,18 @@ CREATE INDEX "Operator_externalId_idx" ON "operator"."Operator"("externalId");
1297
1353
  -- CreateIndex
1298
1354
  CREATE UNIQUE INDEX "Operator_organizationId_rfid_key" ON "operator"."Operator"("organizationId", "rfid");
1299
1355
 
1356
+ -- CreateIndex
1357
+ CREATE INDEX "OperatorTimeLog_operatorId_checkInAt_idx" ON "operator"."OperatorTimeLog"("operatorId", "checkInAt");
1358
+
1359
+ -- CreateIndex
1360
+ CREATE INDEX "OperatorTimeLog_deviceId_checkInAt_idx" ON "operator"."OperatorTimeLog"("deviceId", "checkInAt");
1361
+
1362
+ -- CreateIndex
1363
+ CREATE INDEX "OperatorTimeLog_machineId_checkInAt_idx" ON "operator"."OperatorTimeLog"("machineId", "checkInAt");
1364
+
1365
+ -- CreateIndex
1366
+ CREATE INDEX "OperatorTimeLog_checkInAt_checkOutAt_idx" ON "operator"."OperatorTimeLog"("checkInAt", "checkOutAt");
1367
+
1300
1368
  -- CreateIndex
1301
1369
  CREATE UNIQUE INDEX "Order_externalId_key" ON "order"."Order"("externalId");
1302
1370
 
@@ -1309,6 +1377,9 @@ CREATE INDEX "Order_customerId_idx" ON "order"."Order"("customerId");
1309
1377
  -- CreateIndex
1310
1378
  CREATE INDEX "Order_factoryId_idx" ON "order"."Order"("factoryId");
1311
1379
 
1380
+ -- CreateIndex
1381
+ CREATE INDEX "Order_erpSource_externalId_idx" ON "order"."Order"("erpSource", "externalId");
1382
+
1312
1383
  -- CreateIndex
1313
1384
  CREATE INDEX "OrderProduct_orderId_idx" ON "order"."OrderProduct"("orderId");
1314
1385
 
@@ -1340,34 +1411,49 @@ CREATE INDEX "ProductionUnitLog_productionUnitId_idx" ON "production_tracking"."
1340
1411
  CREATE UNIQUE INDEX "ProductionRouteStep_productionUnitId_key" ON "production_tracking"."ProductionRouteStep"("productionUnitId");
1341
1412
 
1342
1413
  -- CreateIndex
1343
- CREATE UNIQUE INDEX "OrganizationUserFactoryEntityAccess_userId_key" ON "organization"."OrganizationUserFactoryEntityAccess"("userId");
1414
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_userId_organizationId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("userId", "organizationId");
1344
1415
 
1345
1416
  -- CreateIndex
1346
- CREATE INDEX "OrganizationUserFactoryEntityAccess_userId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("userId");
1417
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_factoryId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("factoryId");
1347
1418
 
1348
1419
  -- CreateIndex
1349
- CREATE INDEX "OperatorOperationCategory_factoryId_idx" ON "tasks"."OperatorOperationCategory"("factoryId");
1420
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_floorId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("floorId");
1350
1421
 
1351
1422
  -- CreateIndex
1352
- CREATE INDEX "Task_shiftId_idx" ON "tasks"."Task"("shiftId");
1423
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_assemblyLineId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("assemblyLineId");
1353
1424
 
1354
1425
  -- CreateIndex
1355
- CREATE INDEX "Task_taskGroupId_idx" ON "tasks"."Task"("taskGroupId");
1426
+ CREATE INDEX "OrganizationUserFactoryEntityAccess_machineId_idx" ON "organization"."OrganizationUserFactoryEntityAccess"("machineId");
1356
1427
 
1357
1428
  -- CreateIndex
1358
- CREATE UNIQUE INDEX "TaskLot_taskId_lotId_key" ON "tasks"."TaskLot"("taskId", "lotId");
1429
+ CREATE UNIQUE INDEX "OrganizationUserFactoryEntityAccess_userId_factoryId_floorI_key" ON "organization"."OrganizationUserFactoryEntityAccess"("userId", "factoryId", "floorId", "assemblyLineId", "machineId");
1359
1430
 
1360
1431
  -- CreateIndex
1361
- CREATE UNIQUE INDEX "TaskGroupLot_taskGroupId_lotId_key" ON "tasks"."TaskGroupLot"("taskGroupId", "lotId");
1432
+ CREATE UNIQUE INDEX "MaintenanceSpecialization_organizationId_name_key" ON "organization"."MaintenanceSpecialization"("organizationId", "name");
1362
1433
 
1363
1434
  -- CreateIndex
1364
- CREATE INDEX "_UserToFloors_B_index" ON "factory"."_UserToFloors"("B");
1435
+ CREATE INDEX "OrganizationCustomer_organizationId_idx" ON "organization"."OrganizationCustomer"("organizationId");
1365
1436
 
1366
1437
  -- CreateIndex
1367
- CREATE INDEX "_UserToAssemblyLines_B_index" ON "factory"."_UserToAssemblyLines"("B");
1438
+ CREATE INDEX "AssemblyLineType_organizationId_idx" ON "organization"."AssemblyLineType"("organizationId");
1368
1439
 
1369
1440
  -- CreateIndex
1370
- CREATE INDEX "_UserToMachines_B_index" ON "machine"."_UserToMachines"("B");
1441
+ CREATE UNIQUE INDEX "AssemblyLineType_organizationId_name_key" ON "organization"."AssemblyLineType"("organizationId", "name");
1442
+
1443
+ -- CreateIndex
1444
+ CREATE INDEX "OperatorOperationCategory_factoryId_idx" ON "tasks"."OperatorOperationCategory"("factoryId");
1445
+
1446
+ -- CreateIndex
1447
+ CREATE INDEX "Task_shiftId_idx" ON "tasks"."Task"("shiftId");
1448
+
1449
+ -- CreateIndex
1450
+ CREATE INDEX "Task_taskGroupId_idx" ON "tasks"."Task"("taskGroupId");
1451
+
1452
+ -- CreateIndex
1453
+ CREATE UNIQUE INDEX "TaskLot_taskId_lotId_key" ON "tasks"."TaskLot"("taskId", "lotId");
1454
+
1455
+ -- CreateIndex
1456
+ CREATE UNIQUE INDEX "TaskGroupLot_taskGroupId_lotId_key" ON "tasks"."TaskGroupLot"("taskGroupId", "lotId");
1371
1457
 
1372
1458
  -- AddForeignKey
1373
1459
  ALTER TABLE "analytics"."MachineHourlyAnalytics" ADD CONSTRAINT "MachineHourlyAnalytics_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "machine"."Machine"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
@@ -1609,6 +1695,18 @@ ALTER TABLE "production_tracking"."ProductionRouteStep" ADD CONSTRAINT "Producti
1609
1695
  -- AddForeignKey
1610
1696
  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
1697
 
1698
+ -- AddForeignKey
1699
+ ALTER TABLE "organization"."OrganizationUserFactoryEntityAccess" ADD CONSTRAINT "OrganizationUserFactoryEntityAccess_factoryId_fkey" FOREIGN KEY ("factoryId") REFERENCES "factory"."Factory"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1700
+
1701
+ -- AddForeignKey
1702
+ ALTER TABLE "organization"."OrganizationUserFactoryEntityAccess" ADD CONSTRAINT "OrganizationUserFactoryEntityAccess_floorId_fkey" FOREIGN KEY ("floorId") REFERENCES "factory"."Floor"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1703
+
1704
+ -- AddForeignKey
1705
+ ALTER TABLE "organization"."OrganizationUserFactoryEntityAccess" ADD CONSTRAINT "OrganizationUserFactoryEntityAccess_assemblyLineId_fkey" FOREIGN KEY ("assemblyLineId") REFERENCES "factory"."AssemblyLine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1706
+
1707
+ -- AddForeignKey
1708
+ ALTER TABLE "organization"."OrganizationUserFactoryEntityAccess" ADD CONSTRAINT "OrganizationUserFactoryEntityAccess_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "machine"."Machine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
1709
+
1612
1710
  -- AddForeignKey
1613
1711
  ALTER TABLE "tasks"."OperatorOperationCategory" ADD CONSTRAINT "OperatorOperationCategory_factoryId_fkey" FOREIGN KEY ("factoryId") REFERENCES "factory"."Factory"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
1614
1712
 
@@ -1668,21 +1766,3 @@ ALTER TABLE "tasks"."TaskInspection" ADD CONSTRAINT "TaskInspection_taskId_fkey"
1668
1766
 
1669
1767
  -- AddForeignKey
1670
1768
  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;