@juliobrim/prisma-shared 1.0.17 → 1.0.19

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;
@@ -0,0 +1,51 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `clientId` on the `device` table. All the data in the column will be lost.
5
+ - You are about to drop the column `name` on the `device` table. All the data in the column will be lost.
6
+ - You are about to drop the column `stationName` on the `device` table. All the data in the column will be lost.
7
+ - You are about to drop the `device_state` table. If the table is not empty, all the data it contains will be lost.
8
+ - Made the column `machineId` on table `device` required. This step will fail if there are existing NULL values in that column.
9
+ - Made the column `tenantId` on table `device` required. This step will fail if there are existing NULL values in that column.
10
+ - Made the column `tenantId` on table `device_operator` required. This step will fail if there are existing NULL values in that column.
11
+
12
+ */
13
+ -- DropForeignKey
14
+ ALTER TABLE "public"."device" DROP CONSTRAINT "device_machineId_fkey";
15
+
16
+ -- DropForeignKey
17
+ ALTER TABLE "public"."device_state" DROP CONSTRAINT "device_state_deviceId_fkey";
18
+
19
+ -- DropForeignKey
20
+ ALTER TABLE "public"."device_state" DROP CONSTRAINT "device_state_tenantId_fkey";
21
+
22
+ -- DropIndex
23
+ DROP INDEX "public"."device_clientId_key";
24
+
25
+ -- AlterTable
26
+ ALTER TABLE "public"."device" DROP COLUMN "clientId",
27
+ DROP COLUMN "name",
28
+ DROP COLUMN "stationName",
29
+ ADD COLUMN "actualProd" TEXT,
30
+ ADD COLUMN "amountProd" TEXT,
31
+ ADD COLUMN "isOnline" BOOLEAN NOT NULL DEFAULT true,
32
+ ADD COLUMN "lastCommand" TEXT,
33
+ ADD COLUMN "lastSeen" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
34
+ ADD COLUMN "plannedProd" TEXT,
35
+ ADD COLUMN "rejectedProd" TEXT,
36
+ ADD COLUMN "runningOpAmount" TEXT,
37
+ ADD COLUMN "runningOpEndDate" TEXT,
38
+ ADD COLUMN "runningOpNumber" TEXT,
39
+ ADD COLUMN "runningOpProduct" TEXT,
40
+ ADD COLUMN "runningOpStartDate" TEXT,
41
+ ALTER COLUMN "machineId" SET NOT NULL,
42
+ ALTER COLUMN "tenantId" SET NOT NULL;
43
+
44
+ -- AlterTable
45
+ ALTER TABLE "public"."device_operator" ALTER COLUMN "tenantId" SET NOT NULL;
46
+
47
+ -- DropTable
48
+ DROP TABLE "public"."device_state";
49
+
50
+ -- AddForeignKey
51
+ ALTER TABLE "public"."device" ADD CONSTRAINT "device_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.17",
3
+ "version": "1.0.19",
4
4
  "description": "Schema Prisma compartilhado entre projetos Sabcon",
5
5
  "main": "schema.prisma",
6
6
  "files": [
package/schema.prisma CHANGED
@@ -53,6 +53,8 @@ model Tenant {
53
53
  IotMessageRegister IotMessageRegister[]
54
54
  MachineFormula MachineFormula[]
55
55
  MachineFormulaResult MachineFormulaResult[]
56
+ devices Device[]
57
+ deviceOperators DeviceOperator[]
56
58
 
57
59
  @@map("tenant")
58
60
  }
@@ -235,6 +237,7 @@ model Machine {
235
237
  acquired_date DateTime? @db.Date
236
238
  macAddress String? @db.VarChar(17)
237
239
  isDeleted Boolean @default(false)
240
+ type MachineType? @default(discrete)
238
241
  sectorId String?
239
242
  tenantId String?
240
243
  downtime DowntimeEvent[]
@@ -250,6 +253,7 @@ model Machine {
250
253
  IotMessageRegister IotMessageRegister[]
251
254
  MachineFormula MachineFormula[]
252
255
  MachineFormulaResult MachineFormulaResult[]
256
+ device Device?
253
257
 
254
258
  @@map("machine")
255
259
  }
@@ -444,6 +448,7 @@ model Operator {
444
448
  ProductionNode ProductionNode?
445
449
  habilityResources Resource[] @relation("OperatorToResource")
446
450
  shifts Shift[] @relation("OperatorToShift")
451
+ deviceOperators DeviceOperator[]
447
452
 
448
453
  @@map("operator")
449
454
  }
@@ -742,15 +747,67 @@ model NodeOperationQueue {
742
747
  createdAt DateTime @default(now())
743
748
  updatedAt DateTime @updatedAt
744
749
  productionOrderId String
750
+ deviceId String? // Relaciona com dispositivo IIoT
745
751
  tenantId String?
746
752
  node Node @relation(fields: [nodeId], references: [id], onDelete: Cascade)
747
753
  operation Operation @relation(fields: [operationId], references: [id], onDelete: Cascade)
748
754
  productionOrder ProductionOrder @relation(fields: [productionOrderId], references: [id], onDelete: Cascade)
755
+ device Device? @relation(fields: [deviceId], references: [id], onDelete: Cascade)
749
756
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
750
757
 
751
758
  @@map("node_operation_queue")
752
759
  }
753
760
 
761
+ // Modelos para dispositivos IIoT
762
+ model Device {
763
+ id String @id @default(cuid())
764
+ isActive Boolean @default(true)
765
+ prodReportIntervalSec Int @default(20) // Intervalo de relatório de produção em segundos
766
+ plannedProd String? // Produção planejada
767
+ actualProd String? // Produção atual
768
+ amountProd String? // Quantidade produzida (ex: "127 pçs")
769
+ rejectedProd String? // Produção rejeitada
770
+ runningOpNumber String? // Número da operação em execução
771
+ runningOpProduct String? // Produto da operação em execução
772
+ runningOpAmount String? // Quantidade da operação em execução
773
+ runningOpStartDate String? // Data de início da operação em execução
774
+ runningOpEndDate String? // Data de fim da operação em execução
775
+ lastCommand String? // Último comando enviado (ex: "restart")
776
+ isOnline Boolean @default(true)
777
+ lastSeen DateTime @default(now())
778
+ machineId String @unique // Relaciona com uma máquina específica
779
+ tenantId String
780
+ createdAt DateTime @default(now())
781
+ updatedAt DateTime @updatedAt
782
+
783
+ // Relacionamentos
784
+ machine Machine @relation(fields: [machineId], references: [id])
785
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
786
+ deviceOperators DeviceOperator[]
787
+ nodeOperationQueues NodeOperationQueue[]
788
+
789
+ @@map("device")
790
+ }
791
+
792
+ model DeviceOperator {
793
+ id String @id @default(cuid())
794
+ deviceId String
795
+ operatorId String
796
+ pin String? // PIN do operador no dispositivo
797
+ isActive Boolean @default(true)
798
+ tenantId String
799
+ createdAt DateTime @default(now())
800
+ updatedAt DateTime @updatedAt
801
+
802
+ // Relacionamentos
803
+ device Device @relation(fields: [deviceId], references: [id], onDelete: Cascade)
804
+ operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
805
+ tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
806
+
807
+ @@unique([deviceId, operatorId])
808
+ @@map("device_operator")
809
+ }
810
+
754
811
  enum UserRole {
755
812
  ADMIN
756
813
  USER
@@ -769,6 +826,11 @@ enum NodeType {
769
826
  Product
770
827
  }
771
828
 
829
+ enum MachineType {
830
+ sew
831
+ discrete
832
+ }
833
+
772
834
  enum Colors {
773
835
  red
774
836
  green