@juliobrim/prisma-shared 1.0.26 → 1.0.28

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;
@@ -0,0 +1,22 @@
1
+ -- CreateTable
2
+ CREATE TABLE "public"."MachineScriptState" (
3
+ "id" TEXT NOT NULL,
4
+ "machineId" TEXT NOT NULL,
5
+ "state" JSONB,
6
+ "lastUpdated" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
7
+ "lastMessageTimestamp" TIMESTAMP(3),
8
+
9
+ CONSTRAINT "MachineScriptState_pkey" PRIMARY KEY ("id")
10
+ );
11
+
12
+ -- CreateIndex
13
+ CREATE UNIQUE INDEX "MachineScriptState_machineId_key" ON "public"."MachineScriptState"("machineId");
14
+
15
+ -- CreateIndex
16
+ CREATE INDEX "MachineScriptState_machineId_idx" ON "public"."MachineScriptState"("machineId");
17
+
18
+ -- CreateIndex
19
+ CREATE INDEX "MachineScriptState_lastMessageTimestamp_idx" ON "public"."MachineScriptState"("lastMessageTimestamp");
20
+
21
+ -- AddForeignKey
22
+ ALTER TABLE "public"."MachineScriptState" ADD CONSTRAINT "MachineScriptState_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "public"."machine"("id") ON DELETE CASCADE 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.28",
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,57 @@ 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
+ MachineScriptState MachineScriptState?
265
266
 
266
267
  @@map("machine")
267
268
  }
268
269
 
269
- // Estrutura proposta para o banco de dados
270
270
  model MachineFormula {
271
- id String @id @default(cuid())
271
+ id String @id @default(cuid())
272
272
  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
273
+ name String
274
+ formula Json
275
+ isActive Boolean @default(true)
276
+ createdAt DateTime @default(now())
277
+ updatedAt DateTime @updatedAt
278
278
  tenantId String?
279
-
280
- machine Machine @relation(fields: [machineId], references: [id])
281
- tenant Tenant? @relation(fields: [tenantId], references: [id])
282
- results MachineFormulaResult[]
279
+ machine Machine @relation(fields: [machineId], references: [id])
280
+ tenant Tenant? @relation(fields: [tenantId], references: [id])
281
+ results MachineFormulaResult[]
283
282
 
284
283
  @@map("machine_formula")
285
284
  }
286
285
 
287
286
  model MachineFormulaResult {
288
- id String @id @default(cuid())
287
+ id String @id @default(cuid())
289
288
  machineId String
290
289
  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.)
290
+ timestamp DateTime @default(now())
291
+ sensorData Json
292
+ result Json
294
293
  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])
294
+ formula MachineFormula @relation(fields: [formulaId], references: [id])
295
+ machine Machine @relation(fields: [machineId], references: [id])
296
+ tenant Tenant? @relation(fields: [tenantId], references: [id])
299
297
 
300
298
  @@map("machine_formula_result")
301
299
  }
@@ -317,6 +315,7 @@ model Node {
317
315
  operation Operation?
318
316
  productionNode ProductionNode?
319
317
 
318
+ @@index([flowId], map: "idx_node_flow_id")
320
319
  @@map("node")
321
320
  }
322
321
 
@@ -365,9 +364,9 @@ model Operation {
365
364
  pcpTime Int @default(0)
366
365
  tenantId String?
367
366
  downtimeEvents DowntimeEvent[]
367
+ inputRegisters InputRegister[]
368
368
  itemsHandlingRegisters ItemsHandlingRegister[]
369
369
  nodeOperationQueue NodeOperationQueue[]
370
- inputRegisters InputRegister[]
371
370
  node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
372
371
  resource Resource @relation(fields: [resourceId], references: [id])
373
372
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
@@ -378,6 +377,7 @@ model Operation {
378
377
  productionNodes ProductionNode[]
379
378
  operationGroups OperationGroup[] @relation("OperationToOperationGroup")
380
379
 
380
+ @@index([nodeId], map: "idx_operation_node_id")
381
381
  @@map("operation")
382
382
  }
383
383
 
@@ -411,10 +411,10 @@ model OperationRegister {
411
411
  startTime DateTime @default(now()) @db.Timestamp(6)
412
412
  endTime DateTime? @db.Timestamp(6)
413
413
  elapsedTime BigInt?
414
- timeSinceLastOperation BigInt?
415
414
  productionNodeId String?
416
415
  tenantId String?
417
416
  quantity Int @default(1)
417
+ timeSinceLastOperation BigInt?
418
418
  machine Machine @relation(fields: [machineId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_machine")
419
419
  operator Operator @relation(fields: [operatorId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_operator")
420
420
  operationGroup OperationGroup? @relation(fields: [operationGroupId], references: [id])
@@ -450,6 +450,7 @@ model Operator {
450
450
  operatorRoleId String?
451
451
  isDeleted Boolean @default(false)
452
452
  tenantId String?
453
+ deviceOperators DeviceOperator[]
453
454
  downtimeEvents DowntimeEvent[]
454
455
  operationRegisters OperationRegister[]
455
456
  operatorRole OperatorRole? @relation(fields: [operatorRoleId], references: [id])
@@ -457,7 +458,6 @@ model Operator {
457
458
  ProductionNode ProductionNode?
458
459
  habilityResources Resource[] @relation("OperatorToResource")
459
460
  shifts Shift[] @relation("OperatorToShift")
460
- deviceOperators DeviceOperator[]
461
461
 
462
462
  @@map("operator")
463
463
  }
@@ -510,25 +510,23 @@ model Product {
510
510
  isLocal Boolean?
511
511
  isDeleted Boolean @default(false)
512
512
  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")
513
+ customerProductId String?
514
+ description String?
515
+ sku String?
516
+ stock Float?
517
+ units String?
518
+ contentUnit String?
519
+ packageUnit String?
520
+ unitsPerPackage Float?
523
521
  flows Flow[]
524
522
  itemsHandlingRegisters ItemsHandlingRegister[]
525
523
  node Node[]
526
524
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
525
+ batches ProductBatch[]
527
526
  composedBy ProductComponents[] @relation("componentOf")
528
527
  componentOf ProductComponents[] @relation("composedBy")
529
528
  operations ProductToOperation[]
530
529
  productionOrders ProductionOrder[]
531
- batches ProductBatch[]
532
530
 
533
531
  @@map("product")
534
532
  }
@@ -573,18 +571,18 @@ model ProductionOrder {
573
571
  flowId String?
574
572
  productionOrderIndex Int? @unique
575
573
  batchSize Float
576
- startDate DateTime? @db.Date
577
- endDate DateTime? @db.Date
578
- expectedEndDate DateTime? @db.Date
579
574
  hasStarted Boolean @default(false)
580
575
  isRunning Boolean @default(false)
581
576
  isFinished Boolean @default(false)
582
577
  tenantId String?
578
+ endDate DateTime? @db.Date
579
+ expectedEndDate DateTime? @db.Date
580
+ startDate DateTime? @db.Date
581
+ inputRegisters InputRegister[]
583
582
  ItemsHandlingRegister ItemsHandlingRegister[]
584
583
  NodeOperationQueue NodeOperationQueue[]
585
584
  operationRegisters OperationRegister[]
586
585
  productionNode ProductionNode[]
587
- inputRegisters InputRegister[]
588
586
  flow Flow? @relation(fields: [flowId], references: [id])
589
587
  Product Product @relation(fields: [productId], references: [id])
590
588
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
@@ -771,44 +769,41 @@ model NodeOperationQueue {
771
769
  createdAt DateTime @default(now())
772
770
  updatedAt DateTime @updatedAt
773
771
  productionOrderId String
774
- deviceId String? // Relaciona com dispositivo IIoT
775
772
  tenantId String?
773
+ deviceId String?
774
+ device Device? @relation(fields: [deviceId], references: [id], onDelete: Cascade)
776
775
  node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
777
776
  operation Operation @relation(fields: [operationId], references: [id], onDelete: Cascade)
778
777
  productionOrder ProductionOrder @relation(fields: [productionOrderId], references: [id], onDelete: Cascade)
779
- device Device? @relation(fields: [deviceId], references: [id], onDelete: Cascade)
780
778
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
781
779
 
782
780
  @@map("node_operation_queue")
783
781
  }
784
782
 
785
- // Modelos para dispositivos IIoT
786
783
  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
784
+ id String @id @default(cuid())
785
+ isActive Boolean @default(true)
786
+ prodReportIntervalSec Int @default(20)
787
+ machineId String @unique
803
788
  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[]
789
+ createdAt DateTime @default(now())
790
+ updatedAt DateTime @updatedAt
791
+ actualProd String?
792
+ amountProd String?
793
+ isOnline Boolean @default(true)
794
+ lastCommand String?
795
+ lastSeen DateTime @default(now())
796
+ plannedProd String?
797
+ rejectedProd String?
798
+ runningOpAmount String?
799
+ runningOpEndDate String?
800
+ runningOpNumber String?
801
+ runningOpProduct String?
802
+ runningOpStartDate String?
803
+ machine Machine @relation(fields: [machineId], references: [id])
804
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
805
+ deviceOperators DeviceOperator[]
806
+ nodeOperationQueues NodeOperationQueue[]
812
807
 
813
808
  @@map("device")
814
809
  }
@@ -817,16 +812,16 @@ model MachineSensors {
817
812
  id String @id @default(cuid())
818
813
  machineId String @unique
819
814
  sensor1Name String?
820
- sensor1Multiplier Float?
821
815
  sensor2Name String?
822
- sensor2Multiplier Float?
823
816
  sensor1Show Boolean @default(true)
824
817
  sensor2Show Boolean @default(true)
825
818
  tenantId String?
819
+ sensor1Multiplier Float?
820
+ sensor2Multiplier Float?
821
+ machine Machine @relation(fields: [machineId], references: [id])
822
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
826
823
 
827
- machine Machine? @relation(fields: [machineId], references: [id])
828
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
829
-
824
+ @@index([machineId], map: "idx_machine_sensors_machine_id")
830
825
  @@map("machine_sensors")
831
826
  }
832
827
 
@@ -845,20 +840,33 @@ model MachineProcessingScript {
845
840
  @@map("machine_processing_script")
846
841
  }
847
842
 
843
+ model MachineScriptState {
844
+ id String @id @default(cuid())
845
+ machineId String @unique
846
+ state Json? // Estado JSON serializado do script
847
+ lastUpdated DateTime @default(now()) @updatedAt
848
+ lastMessageTimestamp DateTime? // Timestamp da última mensagem processada
849
+
850
+ // Relacionamento com Machine (opcional, se quiser ter referência)
851
+ machine Machine? @relation(fields: [machineId], references: [id], onDelete: Cascade)
852
+
853
+ @@index([machineId])
854
+ @@index([lastMessageTimestamp])
855
+ @@map("MachineScriptState")
856
+ }
857
+
848
858
  model DeviceOperator {
849
859
  id String @id @default(cuid())
850
860
  deviceId String
851
861
  operatorId String
852
- pin String? // PIN do operador no dispositivo
862
+ pin String?
853
863
  isActive Boolean @default(true)
854
864
  tenantId String
855
865
  createdAt DateTime @default(now())
856
866
  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)
867
+ device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
868
+ operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
869
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
862
870
 
863
871
  @@unique([deviceId, operatorId])
864
872
  @@map("device_operator")
@@ -867,16 +875,14 @@ model DeviceOperator {
867
875
  model ProductBatch {
868
876
  id String @id @default(cuid())
869
877
  productId String
870
- batchNumber String // Número do lote
871
- quantity Float // Quantidade do lote
872
- expiryDate DateTime @db.Date // Data de validade
878
+ batchNumber String
879
+ quantity Float
880
+ expiryDate DateTime @db.Date
873
881
  createdAt DateTime @default(now())
874
882
  updatedAt DateTime @updatedAt
875
883
  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)
884
+ product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
885
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
880
886
 
881
887
  @@unique([productId, batchNumber])
882
888
  @@map("product_batch")