@juliobrim/prisma-shared 1.0.49 → 1.0.50

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;
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.50",
4
4
  "description": "Schema Prisma compartilhado entre projetos Sabcon",
5
5
  "main": "schema.prisma",
6
6
  "files": [
package/schema.prisma CHANGED
@@ -62,6 +62,7 @@ model Tenant {
62
62
  userPermissions UserPermission[]
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])
@@ -653,18 +655,20 @@ model ProductionNode {
653
655
  }
654
656
 
655
657
  model ProductionOrder {
656
- id String @id @default(cuid())
658
+ id String @id @default(cuid())
657
659
  productId String
658
660
  flowId String?
659
- productionOrderIndex Int? @unique
661
+ productionOrderIndex Int? @unique
660
662
  batchSize Float
661
- hasStarted Boolean @default(false)
662
- isRunning Boolean @default(false)
663
- isFinished Boolean @default(false)
663
+ hasStarted Boolean @default(false)
664
+ isRunning Boolean @default(false)
665
+ isFinished Boolean @default(false)
666
+ sectorAggregatedValue Float?
664
667
  tenantId String?
665
- endDate DateTime? @db.Date
666
- expectedEndDate DateTime? @db.Date
667
- startDate DateTime? @db.Date
668
+ endDate DateTime? @db.Date
669
+ expectedEndDate DateTime? @db.Date
670
+ startDate DateTime? @db.Date
671
+
668
672
  inputRegisters InputRegister[]
669
673
  ItemsHandlingRegister ItemsHandlingRegister[]
670
674
  NodeOperationQueue NodeOperationQueue[]
@@ -753,12 +757,13 @@ model SewMachineRawData {
753
757
  }
754
758
 
755
759
  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[]
760
+ id String @id @default(cuid())
761
+ name String @unique @db.VarChar(100)
762
+ tenantId String?
763
+ days ShiftDay[]
764
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
765
+ operators Operator[]
766
+ operatorAvailability OperatorAvailabilityCache[]
762
767
 
763
768
  @@map("shift")
764
769
  }
@@ -1003,7 +1008,7 @@ model ProductBatch {
1003
1008
  product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
1004
1009
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1005
1010
 
1006
- @@unique([productId, batchNumber])
1011
+ @@unique([productId, batchNumber, internalBatchNumber])
1007
1012
  @@map("product_batch")
1008
1013
  }
1009
1014
 
@@ -1185,3 +1190,35 @@ enum QualityIssueCategory {
1185
1190
  PROCESS_DEVIATION
1186
1191
  OTHER
1187
1192
  }
1193
+
1194
+ model OperatorAvailabilityCache {
1195
+ id String @id @default(cuid())
1196
+ date DateTime @db.Date // O dia de referência da disponibilidade (sem horas)
1197
+
1198
+ operatorId String
1199
+ shiftId String? // Pode ser nulo se o operador não estava atrelado a turno no dia, mas trabalhou
1200
+ tenantId String?
1201
+
1202
+ // Tempos esperados (baseados na configuração de ShiftDay / Break)
1203
+ expectedGrossMinutes Int @default(0) // Tempo total de turno configurado (end_time - start_time)
1204
+ expectedBreakMinutes Int @default(0) // Tempo total de pausas configurado no ShiftDay
1205
+ expectedNetMinutes Int @default(0) // Gross - Break (Carga horária líquida exigida)
1206
+
1207
+ // Tempos reais (caso o sistema também controle presença/apontamentos fora do padrão)
1208
+ actualWorkedMinutes Int @default(0) // Exemplo: somatório de apontamentos do dia
1209
+ plannedDowntimeMinutes Int @default(0) // downtimeEvent com isJustified=true e isImpactful=false
1210
+ unplannedDowntimeMinutes Int @default(0) // downtimeEvent com isJustified=true e isImpactful=true
1211
+ unjustifiedDowntimeMinutes Int @default(0) // downtimeEvent com isJustified=false
1212
+
1213
+ createdAt DateTime @default(now())
1214
+ updatedAt DateTime @updatedAt
1215
+
1216
+ operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
1217
+ shift Shift? @relation(fields: [shiftId], references: [id], onDelete: SetNull)
1218
+ tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
1219
+
1220
+ @@unique([operatorId, date]) // Garante que há apenas 1 registro de fechamento por operador por dia
1221
+ @@index([tenantId, date])
1222
+ @@index([shiftId, date])
1223
+ @@map("operator_availability_cache")
1224
+ }