@juliobrim/prisma-shared 1.0.25 → 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.25",
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
  }
@@ -235,66 +235,64 @@ model ItemsHandlingRegister {
235
235
  }
236
236
 
237
237
  model Machine {
238
- id String @id @default(cuid())
239
- model String? @db.VarChar(100)
240
- name String @unique @db.VarChar(100)
241
- capacity Float? @db.Real
242
- clp_index String?
243
- acquired_date DateTime? @db.Date
244
- macAddress String? @db.VarChar(17)
245
- isDeleted Boolean @default(false)
246
- type MachineType? @default(discrete)
247
- sectorId String?
248
- tenantId String?
249
- downtime DowntimeEvent[]
250
- followers Follower[]
251
- inputRegisters InputRegister[]
252
- stationFrom ItemsHandlingRegister[] @relation("stationFrom")
253
- stationTo ItemsHandlingRegister[] @relation("stationTo")
254
- sector Sector? @relation(fields: [sectorId], references: [id])
255
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
256
- operationRegister OperationRegister[]
257
- productionNodes ProductionNode?
258
- operationResources Resource[] @relation("MachineToResource")
259
- IotMessageRegister IotMessageRegister[]
260
- MachineFormula MachineFormula[]
261
- MachineFormulaResult MachineFormulaResult[]
262
- device Device?
263
- machineSensors MachineSensors?
238
+ id String @id @default(cuid())
239
+ model String? @db.VarChar(100)
240
+ name String @unique @db.VarChar(100)
241
+ capacity Float? @db.Real
242
+ clp_index String?
243
+ acquired_date DateTime? @db.Date
244
+ macAddress String? @db.VarChar(17)
245
+ isDeleted Boolean @default(false)
246
+ sectorId String?
247
+ tenantId String?
248
+ type MachineType? @default(discrete)
249
+ device Device?
250
+ downtime DowntimeEvent[]
251
+ followers Follower[]
252
+ inputRegisters InputRegister[]
253
+ IotMessageRegister IotMessageRegister[]
254
+ stationFrom ItemsHandlingRegister[] @relation("stationFrom")
255
+ stationTo ItemsHandlingRegister[] @relation("stationTo")
256
+ sector Sector? @relation(fields: [sectorId], references: [id])
257
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
258
+ MachineFormula MachineFormula[]
259
+ MachineFormulaResult MachineFormulaResult[]
260
+ machineSensors MachineSensors?
261
+ operationRegister OperationRegister[]
262
+ productionNodes ProductionNode?
263
+ operationResources Resource[] @relation("MachineToResource")
264
+ MachineProcessingScript MachineProcessingScript?
264
265
 
265
266
  @@map("machine")
266
267
  }
267
268
 
268
- // Estrutura proposta para o banco de dados
269
269
  model MachineFormula {
270
- id String @id @default(cuid())
270
+ id String @id @default(cuid())
271
271
  machineId String
272
- name String // "Produção Bruta", "Produção Aprovada", etc.
273
- formula Json // Fórmula visual serializada
274
- isActive Boolean @default(true)
275
- createdAt DateTime @default(now())
276
- updatedAt DateTime @updatedAt
272
+ name String
273
+ formula Json
274
+ isActive Boolean @default(true)
275
+ createdAt DateTime @default(now())
276
+ updatedAt DateTime @updatedAt
277
277
  tenantId String?
278
-
279
- machine Machine @relation(fields: [machineId], references: [id])
280
- tenant Tenant? @relation(fields: [tenantId], references: [id])
281
- results MachineFormulaResult[]
278
+ machine Machine @relation(fields: [machineId], references: [id])
279
+ tenant Tenant? @relation(fields: [tenantId], references: [id])
280
+ results MachineFormulaResult[]
282
281
 
283
282
  @@map("machine_formula")
284
283
  }
285
284
 
286
285
  model MachineFormulaResult {
287
- id String @id @default(cuid())
286
+ id String @id @default(cuid())
288
287
  machineId String
289
288
  formulaId String
290
- timestamp DateTime @default(now())
291
- sensorData Json // Dados dos sensores no momento do cálculo
292
- result Json // Resultado da fórmula (totalPieces, totalRejected, etc.)
289
+ timestamp DateTime @default(now())
290
+ sensorData Json
291
+ result Json
293
292
  tenantId String?
294
-
295
- machine Machine @relation(fields: [machineId], references: [id])
296
- formula MachineFormula @relation(fields: [formulaId], references: [id])
297
- 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])
298
296
 
299
297
  @@map("machine_formula_result")
300
298
  }
@@ -316,6 +314,7 @@ model Node {
316
314
  operation Operation?
317
315
  productionNode ProductionNode?
318
316
 
317
+ @@index([flowId], map: "idx_node_flow_id")
319
318
  @@map("node")
320
319
  }
321
320
 
@@ -364,9 +363,9 @@ model Operation {
364
363
  pcpTime Int @default(0)
365
364
  tenantId String?
366
365
  downtimeEvents DowntimeEvent[]
366
+ inputRegisters InputRegister[]
367
367
  itemsHandlingRegisters ItemsHandlingRegister[]
368
368
  nodeOperationQueue NodeOperationQueue[]
369
- inputRegisters InputRegister[]
370
369
  node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
371
370
  resource Resource @relation(fields: [resourceId], references: [id])
372
371
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
@@ -377,6 +376,7 @@ model Operation {
377
376
  productionNodes ProductionNode[]
378
377
  operationGroups OperationGroup[] @relation("OperationToOperationGroup")
379
378
 
379
+ @@index([nodeId], map: "idx_operation_node_id")
380
380
  @@map("operation")
381
381
  }
382
382
 
@@ -410,10 +410,10 @@ model OperationRegister {
410
410
  startTime DateTime @default(now()) @db.Timestamp(6)
411
411
  endTime DateTime? @db.Timestamp(6)
412
412
  elapsedTime BigInt?
413
- timeSinceLastOperation BigInt?
414
413
  productionNodeId String?
415
414
  tenantId String?
416
415
  quantity Int @default(1)
416
+ timeSinceLastOperation BigInt?
417
417
  machine Machine @relation(fields: [machineId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_machine")
418
418
  operator Operator @relation(fields: [operatorId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_operator")
419
419
  operationGroup OperationGroup? @relation(fields: [operationGroupId], references: [id])
@@ -449,6 +449,7 @@ model Operator {
449
449
  operatorRoleId String?
450
450
  isDeleted Boolean @default(false)
451
451
  tenantId String?
452
+ deviceOperators DeviceOperator[]
452
453
  downtimeEvents DowntimeEvent[]
453
454
  operationRegisters OperationRegister[]
454
455
  operatorRole OperatorRole? @relation(fields: [operatorRoleId], references: [id])
@@ -456,7 +457,6 @@ model Operator {
456
457
  ProductionNode ProductionNode?
457
458
  habilityResources Resource[] @relation("OperatorToResource")
458
459
  shifts Shift[] @relation("OperatorToShift")
459
- deviceOperators DeviceOperator[]
460
460
 
461
461
  @@map("operator")
462
462
  }
@@ -509,25 +509,23 @@ model Product {
509
509
  isLocal Boolean?
510
510
  isDeleted Boolean @default(false)
511
511
  tenantId String?
512
- // Campos para importação de produtos do cliente
513
- customerProductId String? // ID do produto no sistema do cliente
514
- sku String? // Código SKU do produto
515
- description String? // Descrição detalhada do produto
516
- units String? // Unidade de medida (UN, KG, etc.)
517
- stock Float? // Quantidade em estoque
518
- // Campos para controle de embalagem
519
- unitsPerPackage Float? // Quantidade de unidades por embalagem (ex: 60 cápsulas por pote)
520
- packageUnit String? // Unidade da embalagem (ex: "pote", "caixa", "frasco")
521
- 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?
522
520
  flows Flow[]
523
521
  itemsHandlingRegisters ItemsHandlingRegister[]
524
522
  node Node[]
525
523
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
524
+ batches ProductBatch[]
526
525
  composedBy ProductComponents[] @relation("componentOf")
527
526
  componentOf ProductComponents[] @relation("composedBy")
528
527
  operations ProductToOperation[]
529
528
  productionOrders ProductionOrder[]
530
- batches ProductBatch[]
531
529
 
532
530
  @@map("product")
533
531
  }
@@ -572,18 +570,18 @@ model ProductionOrder {
572
570
  flowId String?
573
571
  productionOrderIndex Int? @unique
574
572
  batchSize Float
575
- startDate DateTime? @db.Date
576
- endDate DateTime? @db.Date
577
- expectedEndDate DateTime? @db.Date
578
573
  hasStarted Boolean @default(false)
579
574
  isRunning Boolean @default(false)
580
575
  isFinished Boolean @default(false)
581
576
  tenantId String?
577
+ endDate DateTime? @db.Date
578
+ expectedEndDate DateTime? @db.Date
579
+ startDate DateTime? @db.Date
580
+ inputRegisters InputRegister[]
582
581
  ItemsHandlingRegister ItemsHandlingRegister[]
583
582
  NodeOperationQueue NodeOperationQueue[]
584
583
  operationRegisters OperationRegister[]
585
584
  productionNode ProductionNode[]
586
- inputRegisters InputRegister[]
587
585
  flow Flow? @relation(fields: [flowId], references: [id])
588
586
  Product Product @relation(fields: [productId], references: [id])
589
587
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
@@ -770,44 +768,41 @@ model NodeOperationQueue {
770
768
  createdAt DateTime @default(now())
771
769
  updatedAt DateTime @updatedAt
772
770
  productionOrderId String
773
- deviceId String? // Relaciona com dispositivo IIoT
774
771
  tenantId String?
772
+ deviceId String?
773
+ device Device? @relation(fields: [deviceId], references: [id], onDelete: Cascade)
775
774
  node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
776
775
  operation Operation @relation(fields: [operationId], references: [id], onDelete: Cascade)
777
776
  productionOrder ProductionOrder @relation(fields: [productionOrderId], references: [id], onDelete: Cascade)
778
- device Device? @relation(fields: [deviceId], references: [id], onDelete: Cascade)
779
777
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
780
778
 
781
779
  @@map("node_operation_queue")
782
780
  }
783
781
 
784
- // Modelos para dispositivos IIoT
785
782
  model Device {
786
- id String @id @default(cuid())
787
- isActive Boolean @default(true)
788
- prodReportIntervalSec Int @default(20) // Intervalo de relatório de produção em segundos
789
- plannedProd String? // Produção planejada
790
- actualProd String? // Produção atual
791
- amountProd String? // Quantidade produzida (ex: "127 pçs")
792
- rejectedProd String? // Produção rejeitada
793
- runningOpNumber String? // Número da operação em execução
794
- runningOpProduct String? // Produto da operação em execução
795
- runningOpAmount String? // Quantidade da operação em execução
796
- runningOpStartDate String? // Data de início da operação em execução
797
- runningOpEndDate String? // Data de fim da operação em execução
798
- lastCommand String? // Último comando enviado (ex: "restart")
799
- isOnline Boolean @default(true)
800
- lastSeen DateTime @default(now())
801
- 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
802
787
  tenantId String
803
- createdAt DateTime @default(now())
804
- updatedAt DateTime @updatedAt
805
-
806
- // Relacionamentos
807
- machine Machine @relation(fields: [machineId], references: [id])
808
- tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
809
- deviceOperators DeviceOperator[]
810
- 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[]
811
806
 
812
807
  @@map("device")
813
808
  }
@@ -816,33 +811,46 @@ model MachineSensors {
816
811
  id String @id @default(cuid())
817
812
  machineId String @unique
818
813
  sensor1Name String?
819
- sensor1Multiplier Float?
820
814
  sensor2Name String?
821
- sensor2Multiplier Float?
822
815
  sensor1Show Boolean @default(true)
823
816
  sensor2Show Boolean @default(true)
824
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)
825
822
 
826
- machine Machine? @relation(fields: [machineId], references: [id])
827
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
828
-
823
+ @@index([machineId], map: "idx_machine_sensors_machine_id")
829
824
  @@map("machine_sensors")
830
825
  }
831
826
 
827
+ model MachineProcessingScript {
828
+ id String @id @default(cuid())
829
+ machineId String @unique
830
+ script String
831
+ isActive Boolean @default(true)
832
+ version Int @default(1)
833
+ createdAt DateTime @default(now())
834
+ updatedAt DateTime @updatedAt
835
+ createdBy String?
836
+
837
+ machine Machine @relation(fields: [machineId], references: [id])
838
+
839
+ @@map("machine_processing_script")
840
+ }
841
+
832
842
  model DeviceOperator {
833
843
  id String @id @default(cuid())
834
844
  deviceId String
835
845
  operatorId String
836
- pin String? // PIN do operador no dispositivo
846
+ pin String?
837
847
  isActive Boolean @default(true)
838
848
  tenantId String
839
849
  createdAt DateTime @default(now())
840
850
  updatedAt DateTime @updatedAt
841
-
842
- // Relacionamentos
843
- device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
844
- operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
845
- 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)
846
854
 
847
855
  @@unique([deviceId, operatorId])
848
856
  @@map("device_operator")
@@ -851,16 +859,14 @@ model DeviceOperator {
851
859
  model ProductBatch {
852
860
  id String @id @default(cuid())
853
861
  productId String
854
- batchNumber String // Número do lote
855
- quantity Float // Quantidade do lote
856
- expiryDate DateTime @db.Date // Data de validade
862
+ batchNumber String
863
+ quantity Float
864
+ expiryDate DateTime @db.Date
857
865
  createdAt DateTime @default(now())
858
866
  updatedAt DateTime @updatedAt
859
867
  tenantId String?
860
-
861
- // Relacionamentos
862
- product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
863
- 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)
864
870
 
865
871
  @@unique([productId, batchNumber])
866
872
  @@map("product_batch")