@juliobrim/prisma-shared 1.0.26 → 1.0.27

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.
@@ -0,0 +1,9 @@
1
+ -- CreateIndex
2
+ CREATE INDEX IF NOT EXISTS "idx_machine_sensors_machine_id" ON "machine_sensors"("machineId");
3
+
4
+ -- CreateIndex
5
+ CREATE INDEX IF NOT EXISTS "idx_node_flow_id" ON "node"("flowId");
6
+
7
+ -- CreateIndex
8
+ CREATE INDEX IF NOT EXISTS "idx_operation_node_id" ON "operation"("nodeId");
9
+
@@ -0,0 +1,19 @@
1
+ -- CreateTable
2
+ CREATE TABLE "public"."machine_processing_script" (
3
+ "id" TEXT NOT NULL,
4
+ "machineId" TEXT NOT NULL,
5
+ "script" TEXT NOT NULL,
6
+ "isActive" BOOLEAN NOT NULL DEFAULT true,
7
+ "version" INTEGER NOT NULL DEFAULT 1,
8
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
9
+ "updatedAt" TIMESTAMP(3) NOT NULL,
10
+ "createdBy" TEXT,
11
+
12
+ CONSTRAINT "machine_processing_script_pkey" PRIMARY KEY ("id")
13
+ );
14
+
15
+ -- CreateIndex
16
+ CREATE UNIQUE INDEX "machine_processing_script_machineId_key" ON "public"."machine_processing_script"("machineId");
17
+
18
+ -- AddForeignKey
19
+ ALTER TABLE "public"."machine_processing_script" ADD CONSTRAINT "machine_processing_script_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "public"."machine"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juliobrim/prisma-shared",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "description": "Schema Prisma compartilhado entre projetos Sabcon",
5
5
  "main": "schema.prisma",
6
6
  "files": [
package/schema.prisma CHANGED
@@ -17,14 +17,20 @@ model Tenant {
17
17
  updatedAt DateTime @updatedAt
18
18
  accounts Account[]
19
19
  breaks Break[]
20
+ devices Device[]
21
+ deviceOperators DeviceOperator[]
20
22
  downtimeEvents DowntimeEvent[]
21
23
  downtimeReasons DowntimeReason[]
22
24
  edges Edge[]
23
25
  flows Flow[]
24
26
  followers Follower[]
25
27
  inputRegisters InputRegister[]
28
+ IotMessageRegister IotMessageRegister[]
26
29
  itemsHandlingRegisters ItemsHandlingRegister[]
27
30
  machines Machine[]
31
+ MachineFormula MachineFormula[]
32
+ MachineFormulaResult MachineFormulaResult[]
33
+ machineSensors MachineSensors[]
28
34
  nodes Node[]
29
35
  nodeOperationQueue NodeOperationQueue[]
30
36
  notifications Notification[]
@@ -37,6 +43,7 @@ model Tenant {
37
43
  operatorRoles OperatorRole[]
38
44
  panels Panel[]
39
45
  products Product[]
46
+ productBatches ProductBatch[]
40
47
  productComponents ProductComponents[]
41
48
  productToOperations ProductToOperation[]
42
49
  productionNodes ProductionNode[]
@@ -50,13 +57,6 @@ model Tenant {
50
57
  users User[]
51
58
  userPermissions UserPermission[]
52
59
  userShifts UserShift[]
53
- IotMessageRegister IotMessageRegister[]
54
- MachineFormula MachineFormula[]
55
- MachineFormulaResult MachineFormulaResult[]
56
- devices Device[]
57
- deviceOperators DeviceOperator[]
58
- machineSensors MachineSensors[]
59
- productBatches ProductBatch[]
60
60
 
61
61
  @@map("tenant")
62
62
  }
@@ -184,9 +184,9 @@ model InputRegister {
184
184
  operationId String?
185
185
  productionOrderId String?
186
186
  machine Machine @relation(fields: [machineId], references: [id], onDelete: Cascade)
187
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
188
187
  operation Operation? @relation(fields: [operationId], references: [id], onDelete: Cascade)
189
188
  productionOrder ProductionOrder? @relation(fields: [productionOrderId], references: [id], onDelete: Cascade)
189
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
190
190
 
191
191
  @@map("input_register")
192
192
  }
@@ -243,59 +243,56 @@ model Machine {
243
243
  acquired_date DateTime? @db.Date
244
244
  macAddress String? @db.VarChar(17)
245
245
  isDeleted Boolean @default(false)
246
- type MachineType? @default(discrete)
247
246
  sectorId String?
248
247
  tenantId String?
248
+ type MachineType? @default(discrete)
249
+ device Device?
249
250
  downtime DowntimeEvent[]
250
251
  followers Follower[]
251
252
  inputRegisters InputRegister[]
253
+ IotMessageRegister IotMessageRegister[]
252
254
  stationFrom ItemsHandlingRegister[] @relation("stationFrom")
253
255
  stationTo ItemsHandlingRegister[] @relation("stationTo")
254
256
  sector Sector? @relation(fields: [sectorId], references: [id])
255
257
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
256
- operationRegister OperationRegister[]
257
- productionNodes ProductionNode?
258
- operationResources Resource[] @relation("MachineToResource")
259
- IotMessageRegister IotMessageRegister[]
260
258
  MachineFormula MachineFormula[]
261
259
  MachineFormulaResult MachineFormulaResult[]
262
- device Device?
263
260
  machineSensors MachineSensors?
261
+ operationRegister OperationRegister[]
262
+ productionNodes ProductionNode?
263
+ operationResources Resource[] @relation("MachineToResource")
264
264
  MachineProcessingScript MachineProcessingScript?
265
265
 
266
266
  @@map("machine")
267
267
  }
268
268
 
269
- // Estrutura proposta para o banco de dados
270
269
  model MachineFormula {
271
- id String @id @default(cuid())
270
+ id String @id @default(cuid())
272
271
  machineId String
273
- name String // "Produção Bruta", "Produção Aprovada", etc.
274
- formula Json // Fórmula visual serializada
275
- isActive Boolean @default(true)
276
- createdAt DateTime @default(now())
277
- updatedAt DateTime @updatedAt
272
+ name String
273
+ formula Json
274
+ isActive Boolean @default(true)
275
+ createdAt DateTime @default(now())
276
+ updatedAt DateTime @updatedAt
278
277
  tenantId String?
279
-
280
- machine Machine @relation(fields: [machineId], references: [id])
281
- tenant Tenant? @relation(fields: [tenantId], references: [id])
282
- results MachineFormulaResult[]
278
+ machine Machine @relation(fields: [machineId], references: [id])
279
+ tenant Tenant? @relation(fields: [tenantId], references: [id])
280
+ results MachineFormulaResult[]
283
281
 
284
282
  @@map("machine_formula")
285
283
  }
286
284
 
287
285
  model MachineFormulaResult {
288
- id String @id @default(cuid())
286
+ id String @id @default(cuid())
289
287
  machineId String
290
288
  formulaId String
291
- timestamp DateTime @default(now())
292
- sensorData Json // Dados dos sensores no momento do cálculo
293
- result Json // Resultado da fórmula (totalPieces, totalRejected, etc.)
289
+ timestamp DateTime @default(now())
290
+ sensorData Json
291
+ result Json
294
292
  tenantId String?
295
-
296
- machine Machine @relation(fields: [machineId], references: [id])
297
- formula MachineFormula @relation(fields: [formulaId], references: [id])
298
- tenant Tenant? @relation(fields: [tenantId], references: [id])
293
+ formula MachineFormula @relation(fields: [formulaId], references: [id])
294
+ machine Machine @relation(fields: [machineId], references: [id])
295
+ tenant Tenant? @relation(fields: [tenantId], references: [id])
299
296
 
300
297
  @@map("machine_formula_result")
301
298
  }
@@ -317,6 +314,7 @@ model Node {
317
314
  operation Operation?
318
315
  productionNode ProductionNode?
319
316
 
317
+ @@index([flowId], map: "idx_node_flow_id")
320
318
  @@map("node")
321
319
  }
322
320
 
@@ -365,9 +363,9 @@ model Operation {
365
363
  pcpTime Int @default(0)
366
364
  tenantId String?
367
365
  downtimeEvents DowntimeEvent[]
366
+ inputRegisters InputRegister[]
368
367
  itemsHandlingRegisters ItemsHandlingRegister[]
369
368
  nodeOperationQueue NodeOperationQueue[]
370
- inputRegisters InputRegister[]
371
369
  node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
372
370
  resource Resource @relation(fields: [resourceId], references: [id])
373
371
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
@@ -378,6 +376,7 @@ model Operation {
378
376
  productionNodes ProductionNode[]
379
377
  operationGroups OperationGroup[] @relation("OperationToOperationGroup")
380
378
 
379
+ @@index([nodeId], map: "idx_operation_node_id")
381
380
  @@map("operation")
382
381
  }
383
382
 
@@ -411,10 +410,10 @@ model OperationRegister {
411
410
  startTime DateTime @default(now()) @db.Timestamp(6)
412
411
  endTime DateTime? @db.Timestamp(6)
413
412
  elapsedTime BigInt?
414
- timeSinceLastOperation BigInt?
415
413
  productionNodeId String?
416
414
  tenantId String?
417
415
  quantity Int @default(1)
416
+ timeSinceLastOperation BigInt?
418
417
  machine Machine @relation(fields: [machineId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_machine")
419
418
  operator Operator @relation(fields: [operatorId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_operator")
420
419
  operationGroup OperationGroup? @relation(fields: [operationGroupId], references: [id])
@@ -450,6 +449,7 @@ model Operator {
450
449
  operatorRoleId String?
451
450
  isDeleted Boolean @default(false)
452
451
  tenantId String?
452
+ deviceOperators DeviceOperator[]
453
453
  downtimeEvents DowntimeEvent[]
454
454
  operationRegisters OperationRegister[]
455
455
  operatorRole OperatorRole? @relation(fields: [operatorRoleId], references: [id])
@@ -457,7 +457,6 @@ model Operator {
457
457
  ProductionNode ProductionNode?
458
458
  habilityResources Resource[] @relation("OperatorToResource")
459
459
  shifts Shift[] @relation("OperatorToShift")
460
- deviceOperators DeviceOperator[]
461
460
 
462
461
  @@map("operator")
463
462
  }
@@ -510,25 +509,23 @@ model Product {
510
509
  isLocal Boolean?
511
510
  isDeleted Boolean @default(false)
512
511
  tenantId String?
513
- // Campos para importação de produtos do cliente
514
- customerProductId String? // ID do produto no sistema do cliente
515
- sku String? // Código SKU do produto
516
- description String? // Descrição detalhada do produto
517
- units String? // Unidade de medida (UN, KG, etc.)
518
- stock Float? // Quantidade em estoque
519
- // Campos para controle de embalagem
520
- unitsPerPackage Float? // Quantidade de unidades por embalagem (ex: 60 cápsulas por pote)
521
- packageUnit String? // Unidade da embalagem (ex: "pote", "caixa", "frasco")
522
- contentUnit String? // Unidade do conteúdo (ex: "cápsula", "comprimido", "ml")
512
+ customerProductId String?
513
+ description String?
514
+ sku String?
515
+ stock Float?
516
+ units String?
517
+ contentUnit String?
518
+ packageUnit String?
519
+ unitsPerPackage Float?
523
520
  flows Flow[]
524
521
  itemsHandlingRegisters ItemsHandlingRegister[]
525
522
  node Node[]
526
523
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
524
+ batches ProductBatch[]
527
525
  composedBy ProductComponents[] @relation("componentOf")
528
526
  componentOf ProductComponents[] @relation("composedBy")
529
527
  operations ProductToOperation[]
530
528
  productionOrders ProductionOrder[]
531
- batches ProductBatch[]
532
529
 
533
530
  @@map("product")
534
531
  }
@@ -573,18 +570,18 @@ model ProductionOrder {
573
570
  flowId String?
574
571
  productionOrderIndex Int? @unique
575
572
  batchSize Float
576
- startDate DateTime? @db.Date
577
- endDate DateTime? @db.Date
578
- expectedEndDate DateTime? @db.Date
579
573
  hasStarted Boolean @default(false)
580
574
  isRunning Boolean @default(false)
581
575
  isFinished Boolean @default(false)
582
576
  tenantId String?
577
+ endDate DateTime? @db.Date
578
+ expectedEndDate DateTime? @db.Date
579
+ startDate DateTime? @db.Date
580
+ inputRegisters InputRegister[]
583
581
  ItemsHandlingRegister ItemsHandlingRegister[]
584
582
  NodeOperationQueue NodeOperationQueue[]
585
583
  operationRegisters OperationRegister[]
586
584
  productionNode ProductionNode[]
587
- inputRegisters InputRegister[]
588
585
  flow Flow? @relation(fields: [flowId], references: [id])
589
586
  Product Product @relation(fields: [productId], references: [id])
590
587
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
@@ -771,44 +768,41 @@ model NodeOperationQueue {
771
768
  createdAt DateTime @default(now())
772
769
  updatedAt DateTime @updatedAt
773
770
  productionOrderId String
774
- deviceId String? // Relaciona com dispositivo IIoT
775
771
  tenantId String?
772
+ deviceId String?
773
+ device Device? @relation(fields: [deviceId], references: [id], onDelete: Cascade)
776
774
  node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
777
775
  operation Operation @relation(fields: [operationId], references: [id], onDelete: Cascade)
778
776
  productionOrder ProductionOrder @relation(fields: [productionOrderId], references: [id], onDelete: Cascade)
779
- device Device? @relation(fields: [deviceId], references: [id], onDelete: Cascade)
780
777
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
781
778
 
782
779
  @@map("node_operation_queue")
783
780
  }
784
781
 
785
- // Modelos para dispositivos IIoT
786
782
  model Device {
787
- id String @id @default(cuid())
788
- isActive Boolean @default(true)
789
- prodReportIntervalSec Int @default(20) // Intervalo de relatório de produção em segundos
790
- plannedProd String? // Produção planejada
791
- actualProd String? // Produção atual
792
- amountProd String? // Quantidade produzida (ex: "127 pçs")
793
- rejectedProd String? // Produção rejeitada
794
- runningOpNumber String? // Número da operação em execução
795
- runningOpProduct String? // Produto da operação em execução
796
- runningOpAmount String? // Quantidade da operação em execução
797
- runningOpStartDate String? // Data de início da operação em execução
798
- runningOpEndDate String? // Data de fim da operação em execução
799
- lastCommand String? // Último comando enviado (ex: "restart")
800
- isOnline Boolean @default(true)
801
- lastSeen DateTime @default(now())
802
- machineId String @unique // Relaciona com uma máquina específica
783
+ id String @id @default(cuid())
784
+ isActive Boolean @default(true)
785
+ prodReportIntervalSec Int @default(20)
786
+ machineId String @unique
803
787
  tenantId String
804
- createdAt DateTime @default(now())
805
- updatedAt DateTime @updatedAt
806
-
807
- // Relacionamentos
808
- machine Machine @relation(fields: [machineId], references: [id])
809
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
810
- deviceOperators DeviceOperator[]
811
- nodeOperationQueues NodeOperationQueue[]
788
+ createdAt DateTime @default(now())
789
+ updatedAt DateTime @updatedAt
790
+ actualProd String?
791
+ amountProd String?
792
+ isOnline Boolean @default(true)
793
+ lastCommand String?
794
+ lastSeen DateTime @default(now())
795
+ plannedProd String?
796
+ rejectedProd String?
797
+ runningOpAmount String?
798
+ runningOpEndDate String?
799
+ runningOpNumber String?
800
+ runningOpProduct String?
801
+ runningOpStartDate String?
802
+ machine Machine @relation(fields: [machineId], references: [id])
803
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
804
+ deviceOperators DeviceOperator[]
805
+ nodeOperationQueues NodeOperationQueue[]
812
806
 
813
807
  @@map("device")
814
808
  }
@@ -817,16 +811,16 @@ model MachineSensors {
817
811
  id String @id @default(cuid())
818
812
  machineId String @unique
819
813
  sensor1Name String?
820
- sensor1Multiplier Float?
821
814
  sensor2Name String?
822
- sensor2Multiplier Float?
823
815
  sensor1Show Boolean @default(true)
824
816
  sensor2Show Boolean @default(true)
825
817
  tenantId String?
818
+ sensor1Multiplier Float?
819
+ sensor2Multiplier Float?
820
+ machine Machine @relation(fields: [machineId], references: [id])
821
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
826
822
 
827
- machine Machine? @relation(fields: [machineId], references: [id])
828
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
829
-
823
+ @@index([machineId], map: "idx_machine_sensors_machine_id")
830
824
  @@map("machine_sensors")
831
825
  }
832
826
 
@@ -849,16 +843,14 @@ model DeviceOperator {
849
843
  id String @id @default(cuid())
850
844
  deviceId String
851
845
  operatorId String
852
- pin String? // PIN do operador no dispositivo
846
+ pin String?
853
847
  isActive Boolean @default(true)
854
848
  tenantId String
855
849
  createdAt DateTime @default(now())
856
850
  updatedAt DateTime @updatedAt
857
-
858
- // Relacionamentos
859
- device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
860
- operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
861
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
851
+ device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
852
+ operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
853
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
862
854
 
863
855
  @@unique([deviceId, operatorId])
864
856
  @@map("device_operator")
@@ -867,16 +859,14 @@ model DeviceOperator {
867
859
  model ProductBatch {
868
860
  id String @id @default(cuid())
869
861
  productId String
870
- batchNumber String // Número do lote
871
- quantity Float // Quantidade do lote
872
- expiryDate DateTime @db.Date // Data de validade
862
+ batchNumber String
863
+ quantity Float
864
+ expiryDate DateTime @db.Date
873
865
  createdAt DateTime @default(now())
874
866
  updatedAt DateTime @updatedAt
875
867
  tenantId String?
876
-
877
- // Relacionamentos
878
- product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
879
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
868
+ product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
869
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
880
870
 
881
871
  @@unique([productId, batchNumber])
882
872
  @@map("product_batch")