@juliobrim/prisma-shared 1.0.17 → 1.0.18

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,97 @@
1
+ -- CreateEnum
2
+ CREATE TYPE "public"."MachineType" AS ENUM ('sew', 'discrete');
3
+
4
+ -- AlterTable
5
+ ALTER TABLE "public"."machine" ADD COLUMN "type" "public"."MachineType" DEFAULT 'discrete';
6
+
7
+ -- AlterTable
8
+ ALTER TABLE "public"."node_operation_queue" ADD COLUMN "deviceId" TEXT;
9
+
10
+ -- CreateTable
11
+ CREATE TABLE "public"."device" (
12
+ "id" TEXT NOT NULL,
13
+ "clientId" TEXT NOT NULL,
14
+ "name" TEXT NOT NULL,
15
+ "stationName" TEXT,
16
+ "isActive" BOOLEAN NOT NULL DEFAULT true,
17
+ "prodReportIntervalSec" INTEGER NOT NULL DEFAULT 20,
18
+ "machineId" TEXT,
19
+ "tenantId" TEXT,
20
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
21
+ "updatedAt" TIMESTAMP(3) NOT NULL,
22
+
23
+ CONSTRAINT "device_pkey" PRIMARY KEY ("id")
24
+ );
25
+
26
+ -- CreateTable
27
+ CREATE TABLE "public"."device_operator" (
28
+ "id" TEXT NOT NULL,
29
+ "deviceId" TEXT NOT NULL,
30
+ "operatorId" TEXT NOT NULL,
31
+ "pin" TEXT,
32
+ "isActive" BOOLEAN NOT NULL DEFAULT true,
33
+ "tenantId" TEXT,
34
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
35
+ "updatedAt" TIMESTAMP(3) NOT NULL,
36
+
37
+ CONSTRAINT "device_operator_pkey" PRIMARY KEY ("id")
38
+ );
39
+
40
+ -- CreateTable
41
+ CREATE TABLE "public"."device_state" (
42
+ "id" TEXT NOT NULL,
43
+ "deviceId" TEXT NOT NULL,
44
+ "plannedProd" TEXT,
45
+ "actualProd" TEXT,
46
+ "amountProd" TEXT,
47
+ "rejectedProd" TEXT,
48
+ "runningOpNumber" TEXT,
49
+ "runningOpProduct" TEXT,
50
+ "runningOpAmount" TEXT,
51
+ "runningOpStartDate" TEXT,
52
+ "runningOpEndDate" TEXT,
53
+ "lastCommand" TEXT,
54
+ "isOnline" BOOLEAN NOT NULL DEFAULT true,
55
+ "lastSeen" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
56
+ "tenantId" TEXT,
57
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
58
+ "updatedAt" TIMESTAMP(3) NOT NULL,
59
+
60
+ CONSTRAINT "device_state_pkey" PRIMARY KEY ("id")
61
+ );
62
+
63
+ -- CreateIndex
64
+ CREATE UNIQUE INDEX "device_clientId_key" ON "public"."device"("clientId");
65
+
66
+ -- CreateIndex
67
+ CREATE UNIQUE INDEX "device_machineId_key" ON "public"."device"("machineId");
68
+
69
+ -- CreateIndex
70
+ CREATE UNIQUE INDEX "device_operator_deviceId_operatorId_key" ON "public"."device_operator"("deviceId", "operatorId");
71
+
72
+ -- CreateIndex
73
+ CREATE UNIQUE INDEX "device_state_deviceId_key" ON "public"."device_state"("deviceId");
74
+
75
+ -- AddForeignKey
76
+ ALTER TABLE "public"."node_operation_queue" ADD CONSTRAINT "node_operation_queue_deviceId_fkey" FOREIGN KEY ("deviceId") REFERENCES "public"."device"("id") ON DELETE CASCADE ON UPDATE CASCADE;
77
+
78
+ -- AddForeignKey
79
+ ALTER TABLE "public"."device" ADD CONSTRAINT "device_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "public"."machine"("id") ON DELETE SET NULL ON UPDATE CASCADE;
80
+
81
+ -- AddForeignKey
82
+ ALTER TABLE "public"."device" ADD CONSTRAINT "device_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "public"."tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
83
+
84
+ -- AddForeignKey
85
+ ALTER TABLE "public"."device_operator" ADD CONSTRAINT "device_operator_deviceId_fkey" FOREIGN KEY ("deviceId") REFERENCES "public"."device"("id") ON DELETE CASCADE ON UPDATE CASCADE;
86
+
87
+ -- AddForeignKey
88
+ ALTER TABLE "public"."device_operator" ADD CONSTRAINT "device_operator_operatorId_fkey" FOREIGN KEY ("operatorId") REFERENCES "public"."operator"("id") ON DELETE CASCADE ON UPDATE CASCADE;
89
+
90
+ -- AddForeignKey
91
+ ALTER TABLE "public"."device_operator" ADD CONSTRAINT "device_operator_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "public"."tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
92
+
93
+ -- AddForeignKey
94
+ ALTER TABLE "public"."device_state" ADD CONSTRAINT "device_state_deviceId_fkey" FOREIGN KEY ("deviceId") REFERENCES "public"."device"("id") ON DELETE CASCADE ON UPDATE CASCADE;
95
+
96
+ -- AddForeignKey
97
+ ALTER TABLE "public"."device_state" ADD CONSTRAINT "device_state_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "public"."tenant"("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.17",
3
+ "version": "1.0.18",
4
4
  "description": "Schema Prisma compartilhado entre projetos Sabcon",
5
5
  "main": "schema.prisma",
6
6
  "files": [
package/schema.prisma CHANGED
@@ -53,6 +53,9 @@ model Tenant {
53
53
  IotMessageRegister IotMessageRegister[]
54
54
  MachineFormula MachineFormula[]
55
55
  MachineFormulaResult MachineFormulaResult[]
56
+ devices Device[]
57
+ deviceOperators DeviceOperator[]
58
+ deviceStates DeviceState[]
56
59
 
57
60
  @@map("tenant")
58
61
  }
@@ -235,6 +238,7 @@ model Machine {
235
238
  acquired_date DateTime? @db.Date
236
239
  macAddress String? @db.VarChar(17)
237
240
  isDeleted Boolean @default(false)
241
+ type MachineType? @default(discrete)
238
242
  sectorId String?
239
243
  tenantId String?
240
244
  downtime DowntimeEvent[]
@@ -250,6 +254,7 @@ model Machine {
250
254
  IotMessageRegister IotMessageRegister[]
251
255
  MachineFormula MachineFormula[]
252
256
  MachineFormulaResult MachineFormulaResult[]
257
+ device Device?
253
258
 
254
259
  @@map("machine")
255
260
  }
@@ -444,6 +449,7 @@ model Operator {
444
449
  ProductionNode ProductionNode?
445
450
  habilityResources Resource[] @relation("OperatorToResource")
446
451
  shifts Shift[] @relation("OperatorToShift")
452
+ deviceOperators DeviceOperator[]
447
453
 
448
454
  @@map("operator")
449
455
  }
@@ -742,15 +748,86 @@ model NodeOperationQueue {
742
748
  createdAt DateTime @default(now())
743
749
  updatedAt DateTime @updatedAt
744
750
  productionOrderId String
751
+ deviceId String? // Relaciona com dispositivo IIoT
745
752
  tenantId String?
746
753
  node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
747
754
  operation Operation @relation(fields: [operationId], references: [id], onDelete: Cascade)
748
755
  productionOrder ProductionOrder @relation(fields: [productionOrderId], references: [id], onDelete: Cascade)
756
+ device Device? @relation(fields: [deviceId], references: [id], onDelete: Cascade)
749
757
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
750
758
 
751
759
  @@map("node_operation_queue")
752
760
  }
753
761
 
762
+ // Modelos para dispositivos IIoT
763
+ model Device {
764
+ id String @id @default(cuid())
765
+ clientId String @unique // Ex: "SABCON-ESP32-022"
766
+ name String // Nome da estação/device
767
+ stationName String? // Nome da estação (ex: "Estação Montagem A1")
768
+ isActive Boolean @default(true)
769
+ prodReportIntervalSec Int @default(20) // Intervalo de relatório de produção em segundos
770
+ machineId String? @unique // Relaciona com uma máquina específica
771
+ tenantId String?
772
+ createdAt DateTime @default(now())
773
+ updatedAt DateTime @updatedAt
774
+
775
+ // Relacionamentos
776
+ machine Machine? @relation(fields: [machineId], references: [id])
777
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
778
+ deviceOperators DeviceOperator[]
779
+ deviceStates DeviceState[]
780
+ nodeOperationQueues NodeOperationQueue[]
781
+
782
+ @@map("device")
783
+ }
784
+
785
+ model DeviceOperator {
786
+ id String @id @default(cuid())
787
+ deviceId String
788
+ operatorId String
789
+ pin String? // PIN do operador no dispositivo
790
+ isActive Boolean @default(true)
791
+ tenantId String?
792
+ createdAt DateTime @default(now())
793
+ updatedAt DateTime @updatedAt
794
+
795
+ // Relacionamentos
796
+ device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
797
+ operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
798
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
799
+
800
+ @@unique([deviceId, operatorId])
801
+ @@map("device_operator")
802
+ }
803
+
804
+ model DeviceState {
805
+ id String @id @default(cuid())
806
+ deviceId String
807
+ plannedProd String? // Produção planejada
808
+ actualProd String? // Produção atual
809
+ amountProd String? // Quantidade produzida (ex: "127 pçs")
810
+ rejectedProd String? // Produção rejeitada
811
+ runningOpNumber String? // Número da operação em execução
812
+ runningOpProduct String? // Produto da operação em execução
813
+ runningOpAmount String? // Quantidade da operação em execução
814
+ runningOpStartDate String? // Data de início da operação em execução
815
+ runningOpEndDate String? // Data de fim da operação em execução
816
+ lastCommand String? // Último comando enviado (ex: "restart")
817
+ isOnline Boolean @default(true)
818
+ lastSeen DateTime @default(now())
819
+ tenantId String?
820
+ createdAt DateTime @default(now())
821
+ updatedAt DateTime @updatedAt
822
+
823
+ // Relacionamentos
824
+ device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
825
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
826
+
827
+ @@unique([deviceId]) // Um estado por dispositivo
828
+ @@map("device_state")
829
+ }
830
+
754
831
  enum UserRole {
755
832
  ADMIN
756
833
  USER
@@ -769,6 +846,11 @@ enum NodeType {
769
846
  Product
770
847
  }
771
848
 
849
+ enum MachineType {
850
+ sew
851
+ discrete
852
+ }
853
+
772
854
  enum Colors {
773
855
  red
774
856
  green