@juliobrim/prisma-shared 1.0.49 → 1.0.51

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,37 @@
1
+ -- CreateTable
2
+ CREATE TABLE "operator_availability_cache" (
3
+ "id" TEXT NOT NULL,
4
+ "date" DATE NOT NULL,
5
+ "operatorId" TEXT NOT NULL,
6
+ "shiftId" TEXT,
7
+ "tenantId" TEXT,
8
+ "expectedGrossMinutes" INTEGER NOT NULL DEFAULT 0,
9
+ "expectedBreakMinutes" INTEGER NOT NULL DEFAULT 0,
10
+ "expectedNetMinutes" INTEGER NOT NULL DEFAULT 0,
11
+ "actualWorkedMinutes" INTEGER NOT NULL DEFAULT 0,
12
+ "plannedDowntimeMinutes" INTEGER NOT NULL DEFAULT 0,
13
+ "unplannedDowntimeMinutes" INTEGER NOT NULL DEFAULT 0,
14
+ "unjustifiedDowntimeMinutes" INTEGER NOT NULL DEFAULT 0,
15
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
16
+ "updatedAt" TIMESTAMP(3) NOT NULL,
17
+
18
+ CONSTRAINT "operator_availability_cache_pkey" PRIMARY KEY ("id")
19
+ );
20
+
21
+ -- CreateIndex
22
+ CREATE INDEX "operator_availability_cache_tenantId_date_idx" ON "operator_availability_cache"("tenantId", "date");
23
+
24
+ -- CreateIndex
25
+ CREATE INDEX "operator_availability_cache_shiftId_date_idx" ON "operator_availability_cache"("shiftId", "date");
26
+
27
+ -- CreateIndex
28
+ CREATE UNIQUE INDEX "operator_availability_cache_operatorId_date_key" ON "operator_availability_cache"("operatorId", "date");
29
+
30
+ -- AddForeignKey
31
+ ALTER TABLE "operator_availability_cache" ADD CONSTRAINT "operator_availability_cache_operatorId_fkey" FOREIGN KEY ("operatorId") REFERENCES "operator"("id") ON DELETE CASCADE ON UPDATE CASCADE;
32
+
33
+ -- AddForeignKey
34
+ ALTER TABLE "operator_availability_cache" ADD CONSTRAINT "operator_availability_cache_shiftId_fkey" FOREIGN KEY ("shiftId") REFERENCES "shift"("id") ON DELETE SET NULL ON UPDATE CASCADE;
35
+
36
+ -- AddForeignKey
37
+ ALTER TABLE "operator_availability_cache" ADD CONSTRAINT "operator_availability_cache_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,11 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - A unique constraint covering the columns `[productId,batchNumber,internalBatchNumber]` on the table `product_batch` will be added. If there are existing duplicate values, this will fail.
5
+
6
+ */
7
+ -- DropIndex
8
+ DROP INDEX "product_batch_productId_batchNumber_key";
9
+
10
+ -- CreateIndex
11
+ CREATE UNIQUE INDEX "product_batch_productId_batchNumber_internalBatchNumber_key" ON "product_batch"("productId", "batchNumber", "internalBatchNumber");
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "production_order" ADD COLUMN "sectorAggregatedValue" DOUBLE PRECISION;
@@ -0,0 +1,70 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `role` on the `user` table. All the data in the column will be lost.
5
+ - You are about to drop the `permission` table. If the table is not empty, all the data it contains will be lost.
6
+ - You are about to drop the `user_permission` table. If the table is not empty, all the data it contains will be lost.
7
+
8
+ */
9
+ -- DropForeignKey
10
+ ALTER TABLE "user_permission" DROP CONSTRAINT "fk_permission";
11
+
12
+ -- DropForeignKey
13
+ ALTER TABLE "user_permission" DROP CONSTRAINT "user_permission_tenantId_fkey";
14
+
15
+ -- DropForeignKey
16
+ ALTER TABLE "user_permission" DROP CONSTRAINT "user_permission_user_id_fkey";
17
+
18
+ -- AlterTable
19
+ ALTER TABLE "user" DROP COLUMN "role",
20
+ ADD COLUMN "roleId" TEXT;
21
+
22
+ -- DropTable
23
+ DROP TABLE "permission";
24
+
25
+ -- DropTable
26
+ DROP TABLE "user_permission";
27
+
28
+ -- CreateTable
29
+ CREATE TABLE "Permission" (
30
+ "id" TEXT NOT NULL,
31
+ "action" TEXT NOT NULL,
32
+ "subject" TEXT NOT NULL,
33
+ "conditions" JSONB,
34
+ "description" TEXT,
35
+
36
+ CONSTRAINT "Permission_pkey" PRIMARY KEY ("id")
37
+ );
38
+
39
+ -- CreateTable
40
+ CREATE TABLE "Role" (
41
+ "id" TEXT NOT NULL,
42
+ "name" TEXT NOT NULL,
43
+ "description" TEXT,
44
+ "tenantId" TEXT,
45
+
46
+ CONSTRAINT "Role_pkey" PRIMARY KEY ("id")
47
+ );
48
+
49
+ -- CreateTable
50
+ CREATE TABLE "RolePermission" (
51
+ "roleId" TEXT NOT NULL,
52
+ "permissionId" TEXT NOT NULL,
53
+
54
+ CONSTRAINT "RolePermission_pkey" PRIMARY KEY ("roleId","permissionId")
55
+ );
56
+
57
+ -- CreateIndex
58
+ CREATE UNIQUE INDEX "Role_name_key" ON "Role"("name");
59
+
60
+ -- AddForeignKey
61
+ ALTER TABLE "Role" ADD CONSTRAINT "Role_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "tenant"("id") ON DELETE SET NULL ON UPDATE CASCADE;
62
+
63
+ -- AddForeignKey
64
+ ALTER TABLE "RolePermission" ADD CONSTRAINT "RolePermission_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "Role"("id") ON DELETE CASCADE ON UPDATE CASCADE;
65
+
66
+ -- AddForeignKey
67
+ ALTER TABLE "RolePermission" ADD CONSTRAINT "RolePermission_permissionId_fkey" FOREIGN KEY ("permissionId") REFERENCES "Permission"("id") ON DELETE CASCADE ON UPDATE CASCADE;
68
+
69
+ -- AddForeignKey
70
+ ALTER TABLE "user" ADD CONSTRAINT "user_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "Role"("id") ON DELETE SET NULL ON UPDATE CASCADE;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juliobrim/prisma-shared",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "Schema Prisma compartilhado entre projetos Sabcon",
5
5
  "main": "schema.prisma",
6
6
  "files": [
package/schema.prisma CHANGED
@@ -59,9 +59,10 @@ model Tenant {
59
59
  systemPreferences SystemPreferences[]
60
60
  processingScripts ProcessingScript[]
61
61
  users User[]
62
- userPermissions UserPermission[]
62
+ roles Role[]
63
63
  machineOperationStitch MachineOperationStitch[]
64
64
  productivityIntervals ProductivityIntervalCache[]
65
+ operatorAvailability OperatorAvailabilityCache[]
65
66
  aiConversations AiConversation[]
66
67
  qualityRegisters QualityRegister[]
67
68
  qualityIssues QualityIssue[]
@@ -541,6 +542,7 @@ model Operator {
541
542
  shiftId String?
542
543
  shift Shift? @relation(fields: [shiftId], references: [id])
543
544
  productivityIntervals ProductivityIntervalCache[]
545
+ operatorAvailability OperatorAvailabilityCache[]
544
546
  qualityRegisters QualityRegister[]
545
547
 
546
548
  @@index([tenantId, isDeleted])
@@ -581,12 +583,13 @@ model PasswordResetToken {
581
583
  }
582
584
 
583
585
  model Permission {
584
- id Int @id @default(autoincrement())
585
- title Int?
586
- description String?
587
- user_permission UserPermission[]
586
+ id String @id @default(cuid())
587
+ action String // Ex: "create", "read", "update", "delete", "manage"
588
+ subject String // Ex: "User", "Report", "all"
589
+ conditions Json? // Ex: {"tenantId": "123"}
590
+ description String?
588
591
 
589
- @@map("permission")
592
+ roles RolePermission[]
590
593
  }
591
594
 
592
595
  model Product {
@@ -653,18 +656,20 @@ model ProductionNode {
653
656
  }
654
657
 
655
658
  model ProductionOrder {
656
- id String @id @default(cuid())
659
+ id String @id @default(cuid())
657
660
  productId String
658
661
  flowId String?
659
- productionOrderIndex Int? @unique
662
+ productionOrderIndex Int? @unique
660
663
  batchSize Float
661
- hasStarted Boolean @default(false)
662
- isRunning Boolean @default(false)
663
- isFinished Boolean @default(false)
664
+ hasStarted Boolean @default(false)
665
+ isRunning Boolean @default(false)
666
+ isFinished Boolean @default(false)
667
+ sectorAggregatedValue Float?
664
668
  tenantId String?
665
- endDate DateTime? @db.Date
666
- expectedEndDate DateTime? @db.Date
667
- startDate DateTime? @db.Date
669
+ endDate DateTime? @db.Date
670
+ expectedEndDate DateTime? @db.Date
671
+ startDate DateTime? @db.Date
672
+
668
673
  inputRegisters InputRegister[]
669
674
  ItemsHandlingRegister ItemsHandlingRegister[]
670
675
  NodeOperationQueue NodeOperationQueue[]
@@ -723,6 +728,27 @@ model Resource {
723
728
  @@map("resource")
724
729
  }
725
730
 
731
+ model Role {
732
+ id String @id @default(cuid())
733
+ name String @unique // Ex: "Admin", "Operador", "Gerente"
734
+ description String?
735
+ tenantId String?
736
+ permissions RolePermission[]
737
+ users User[]
738
+
739
+ tenant Tenant? @relation(fields: [tenantId], references: [id])
740
+ }
741
+
742
+ model RolePermission {
743
+ roleId String
744
+ permissionId String
745
+
746
+ role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
747
+ permission Permission @relation(fields: [permissionId], references: [id], onDelete: Cascade)
748
+
749
+ @@id([roleId, permissionId])
750
+ }
751
+
726
752
  model Sector {
727
753
  id String @id @default(cuid())
728
754
  name String @unique @db.VarChar(100)
@@ -753,12 +779,13 @@ model SewMachineRawData {
753
779
  }
754
780
 
755
781
  model Shift {
756
- id String @id @default(cuid())
757
- name String @unique @db.VarChar(100)
758
- tenantId String?
759
- days ShiftDay[]
760
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
761
- operators Operator[]
782
+ id String @id @default(cuid())
783
+ name String @unique @db.VarChar(100)
784
+ tenantId String?
785
+ days ShiftDay[]
786
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
787
+ operators Operator[]
788
+ operatorAvailability OperatorAvailabilityCache[]
762
789
 
763
790
  @@map("shift")
764
791
  }
@@ -820,7 +847,8 @@ model User {
820
847
  image String?
821
848
  password String
822
849
  isTwoFactorEnabled Boolean @default(false)
823
- role UserRole @default(USER)
850
+ roleId String?
851
+ role Role? @relation(fields: [roleId], references: [id])
824
852
  tenantId String?
825
853
  accounts Account[]
826
854
  follows Follower[]
@@ -828,24 +856,11 @@ model User {
828
856
  Panel Panel[]
829
857
  twoFactorConfirmation TwoFactorConfirmation?
830
858
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
831
- userPermissions UserPermission[]
832
859
  aiConversations AiConversation[]
833
860
 
834
861
  @@map("user")
835
862
  }
836
863
 
837
- model UserPermission {
838
- id Int @id @default(autoincrement())
839
- userId String @map("user_id")
840
- permission_id Int?
841
- tenantId String?
842
- permission Permission? @relation(fields: [permission_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_permission")
843
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
844
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
845
-
846
- @@map("user_permission")
847
- }
848
-
849
864
  view ProductivityInterval {
850
865
  machineId String
851
866
  sequenceId Int @map("sequence_id")
@@ -1003,7 +1018,7 @@ model ProductBatch {
1003
1018
  product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
1004
1019
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1005
1020
 
1006
- @@unique([productId, batchNumber])
1021
+ @@unique([productId, batchNumber, internalBatchNumber])
1007
1022
  @@map("product_batch")
1008
1023
  }
1009
1024
 
@@ -1185,3 +1200,35 @@ enum QualityIssueCategory {
1185
1200
  PROCESS_DEVIATION
1186
1201
  OTHER
1187
1202
  }
1203
+
1204
+ model OperatorAvailabilityCache {
1205
+ id String @id @default(cuid())
1206
+ date DateTime @db.Date // O dia de referência da disponibilidade (sem horas)
1207
+
1208
+ operatorId String
1209
+ shiftId String? // Pode ser nulo se o operador não estava atrelado a turno no dia, mas trabalhou
1210
+ tenantId String?
1211
+
1212
+ // Tempos esperados (baseados na configuração de ShiftDay / Break)
1213
+ expectedGrossMinutes Int @default(0) // Tempo total de turno configurado (end_time - start_time)
1214
+ expectedBreakMinutes Int @default(0) // Tempo total de pausas configurado no ShiftDay
1215
+ expectedNetMinutes Int @default(0) // Gross - Break (Carga horária líquida exigida)
1216
+
1217
+ // Tempos reais (caso o sistema também controle presença/apontamentos fora do padrão)
1218
+ actualWorkedMinutes Int @default(0) // Exemplo: somatório de apontamentos do dia
1219
+ plannedDowntimeMinutes Int @default(0) // downtimeEvent com isJustified=true e isImpactful=false
1220
+ unplannedDowntimeMinutes Int @default(0) // downtimeEvent com isJustified=true e isImpactful=true
1221
+ unjustifiedDowntimeMinutes Int @default(0) // downtimeEvent com isJustified=false
1222
+
1223
+ createdAt DateTime @default(now())
1224
+ updatedAt DateTime @updatedAt
1225
+
1226
+ operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
1227
+ shift Shift? @relation(fields: [shiftId], references: [id], onDelete: SetNull)
1228
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1229
+
1230
+ @@unique([operatorId, date]) // Garante que há apenas 1 registro de fechamento por operador por dia
1231
+ @@index([tenantId, date])
1232
+ @@index([shiftId, date])
1233
+ @@map("operator_availability_cache")
1234
+ }