@juliobrim/prisma-shared 1.0.48 → 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.
- package/migrations/20260225213047_update_shift_structure_to_include_shift_days/migration.sql +72 -0
- package/migrations/20260226023508_add_operator_availability_cache_table/migration.sql +37 -0
- package/migrations/20260302194524_add_new_constraint_to_product_batch/migration.sql +11 -0
- package/migrations/20260312022004_add_sector_aggregated_value_colum_to_production_order_table/migration.sql +2 -0
- package/package.json +1 -1
- package/schema.prisma +77 -39
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Warnings:
|
|
3
|
+
|
|
4
|
+
- You are about to drop the column `shiftId` on the `break` table. All the data in the column will be lost.
|
|
5
|
+
- You are about to drop the column `end_time` on the `shift` table. All the data in the column will be lost.
|
|
6
|
+
- You are about to drop the column `start_time` on the `shift` table. All the data in the column will be lost.
|
|
7
|
+
- You are about to drop the `_OperatorToShift` table. If the table is not empty, all the data it contains will be lost.
|
|
8
|
+
- You are about to drop the `operator_shift` table. If the table is not empty, all the data it contains will be lost.
|
|
9
|
+
|
|
10
|
+
*/
|
|
11
|
+
-- DropForeignKey
|
|
12
|
+
ALTER TABLE "_OperatorToShift" DROP CONSTRAINT "_OperatorToShift_A_fkey";
|
|
13
|
+
|
|
14
|
+
-- DropForeignKey
|
|
15
|
+
ALTER TABLE "_OperatorToShift" DROP CONSTRAINT "_OperatorToShift_B_fkey";
|
|
16
|
+
|
|
17
|
+
-- DropForeignKey
|
|
18
|
+
ALTER TABLE "break" DROP CONSTRAINT "break_shiftId_fkey";
|
|
19
|
+
|
|
20
|
+
-- DropForeignKey
|
|
21
|
+
ALTER TABLE "operator_shift" DROP CONSTRAINT "fk_shift";
|
|
22
|
+
|
|
23
|
+
-- DropForeignKey
|
|
24
|
+
ALTER TABLE "operator_shift" DROP CONSTRAINT "operator_shift_operator_id_fkey";
|
|
25
|
+
|
|
26
|
+
-- DropForeignKey
|
|
27
|
+
ALTER TABLE "operator_shift" DROP CONSTRAINT "operator_shift_tenantId_fkey";
|
|
28
|
+
|
|
29
|
+
-- AlterTable
|
|
30
|
+
ALTER TABLE "break" DROP COLUMN "shiftId",
|
|
31
|
+
ADD COLUMN "shiftDayId" TEXT;
|
|
32
|
+
|
|
33
|
+
-- AlterTable
|
|
34
|
+
ALTER TABLE "operator" ADD COLUMN "shiftId" TEXT;
|
|
35
|
+
|
|
36
|
+
-- AlterTable
|
|
37
|
+
ALTER TABLE "shift" DROP COLUMN "end_time",
|
|
38
|
+
DROP COLUMN "start_time";
|
|
39
|
+
|
|
40
|
+
-- DropTable
|
|
41
|
+
DROP TABLE "_OperatorToShift";
|
|
42
|
+
|
|
43
|
+
-- DropTable
|
|
44
|
+
DROP TABLE "operator_shift";
|
|
45
|
+
|
|
46
|
+
-- CreateTable
|
|
47
|
+
CREATE TABLE "shift_day" (
|
|
48
|
+
"id" TEXT NOT NULL,
|
|
49
|
+
"dayOfWeek" INTEGER NOT NULL,
|
|
50
|
+
"isWorkingDay" BOOLEAN NOT NULL DEFAULT true,
|
|
51
|
+
"start_time" TIME(6),
|
|
52
|
+
"end_time" TIME(6),
|
|
53
|
+
"shiftId" TEXT NOT NULL,
|
|
54
|
+
"tenantId" TEXT,
|
|
55
|
+
|
|
56
|
+
CONSTRAINT "shift_day_pkey" PRIMARY KEY ("id")
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
-- CreateIndex
|
|
60
|
+
CREATE UNIQUE INDEX "shift_day_shiftId_dayOfWeek_key" ON "shift_day"("shiftId", "dayOfWeek");
|
|
61
|
+
|
|
62
|
+
-- AddForeignKey
|
|
63
|
+
ALTER TABLE "break" ADD CONSTRAINT "break_shiftDayId_fkey" FOREIGN KEY ("shiftDayId") REFERENCES "shift_day"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
64
|
+
|
|
65
|
+
-- AddForeignKey
|
|
66
|
+
ALTER TABLE "operator" ADD CONSTRAINT "operator_shiftId_fkey" FOREIGN KEY ("shiftId") REFERENCES "shift"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
67
|
+
|
|
68
|
+
-- AddForeignKey
|
|
69
|
+
ALTER TABLE "shift_day" ADD CONSTRAINT "shift_day_shiftId_fkey" FOREIGN KEY ("shiftId") REFERENCES "shift"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
70
|
+
|
|
71
|
+
-- AddForeignKey
|
|
72
|
+
ALTER TABLE "shift_day" ADD CONSTRAINT "shift_day_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -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");
|
package/package.json
CHANGED
package/schema.prisma
CHANGED
|
@@ -55,13 +55,14 @@ model Tenant {
|
|
|
55
55
|
sectors Sector[]
|
|
56
56
|
sewMachineRawData SewMachineRawData[]
|
|
57
57
|
shifts Shift[]
|
|
58
|
+
shiftDays ShiftDay[]
|
|
58
59
|
systemPreferences SystemPreferences[]
|
|
59
60
|
processingScripts ProcessingScript[]
|
|
60
61
|
users User[]
|
|
61
62
|
userPermissions UserPermission[]
|
|
62
|
-
operatorShifts OperatorShift[]
|
|
63
63
|
machineOperationStitch MachineOperationStitch[]
|
|
64
64
|
productivityIntervals ProductivityIntervalCache[]
|
|
65
|
+
operatorAvailability OperatorAvailabilityCache[]
|
|
65
66
|
aiConversations AiConversation[]
|
|
66
67
|
qualityRegisters QualityRegister[]
|
|
67
68
|
qualityIssues QualityIssue[]
|
|
@@ -93,13 +94,13 @@ model Account {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
model Break {
|
|
96
|
-
id String
|
|
97
|
-
start_time DateTime
|
|
98
|
-
end_time DateTime
|
|
99
|
-
|
|
97
|
+
id String @id @default(cuid())
|
|
98
|
+
start_time DateTime @db.Time(6)
|
|
99
|
+
end_time DateTime @db.Time(6)
|
|
100
|
+
shiftDayId String?
|
|
100
101
|
tenantId String?
|
|
101
|
-
|
|
102
|
-
tenant Tenant?
|
|
102
|
+
shiftDay ShiftDay? @relation(fields: [shiftDayId], references: [id], onDelete: Cascade)
|
|
103
|
+
tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
103
104
|
|
|
104
105
|
@@map("break")
|
|
105
106
|
}
|
|
@@ -538,9 +539,10 @@ model Operator {
|
|
|
538
539
|
tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
539
540
|
ProductionNode ProductionNode?
|
|
540
541
|
habilityResources Resource[] @relation("OperatorToResource")
|
|
541
|
-
|
|
542
|
+
shiftId String?
|
|
543
|
+
shift Shift? @relation(fields: [shiftId], references: [id])
|
|
542
544
|
productivityIntervals ProductivityIntervalCache[]
|
|
543
|
-
|
|
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
|
|
658
|
+
id String @id @default(cuid())
|
|
657
659
|
productId String
|
|
658
660
|
flowId String?
|
|
659
|
-
productionOrderIndex Int?
|
|
661
|
+
productionOrderIndex Int? @unique
|
|
660
662
|
batchSize Float
|
|
661
|
-
hasStarted Boolean
|
|
662
|
-
isRunning Boolean
|
|
663
|
-
isFinished Boolean
|
|
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?
|
|
666
|
-
expectedEndDate DateTime?
|
|
667
|
-
startDate DateTime?
|
|
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,19 +757,33 @@ model SewMachineRawData {
|
|
|
753
757
|
}
|
|
754
758
|
|
|
755
759
|
model Shift {
|
|
756
|
-
id
|
|
757
|
-
name
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
tenantId
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
operator_shift OperatorShift[]
|
|
764
|
-
operators Operator[] @relation("OperatorToShift")
|
|
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[]
|
|
765
767
|
|
|
766
768
|
@@map("shift")
|
|
767
769
|
}
|
|
768
770
|
|
|
771
|
+
model ShiftDay {
|
|
772
|
+
id String @id @default(cuid())
|
|
773
|
+
dayOfWeek Int // 0 = Domingo, 1 = Segunda, 2 = Terça, ..., 6 = Sábado
|
|
774
|
+
isWorkingDay Boolean @default(true)
|
|
775
|
+
start_time DateTime? @db.Time(6)
|
|
776
|
+
end_time DateTime? @db.Time(6)
|
|
777
|
+
shiftId String
|
|
778
|
+
shift Shift @relation(fields: [shiftId], references: [id], onDelete: Cascade)
|
|
779
|
+
breaks Break[]
|
|
780
|
+
tenantId String?
|
|
781
|
+
tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
782
|
+
|
|
783
|
+
@@unique([shiftId, dayOfWeek])
|
|
784
|
+
@@map("shift_day")
|
|
785
|
+
}
|
|
786
|
+
|
|
769
787
|
model SystemPreferences {
|
|
770
788
|
id Int @id @default(autoincrement())
|
|
771
789
|
downtimeEventTime Int @default(300)
|
|
@@ -833,18 +851,6 @@ model UserPermission {
|
|
|
833
851
|
@@map("user_permission")
|
|
834
852
|
}
|
|
835
853
|
|
|
836
|
-
model OperatorShift {
|
|
837
|
-
id Int @id @default(autoincrement())
|
|
838
|
-
operatorId String @map("operator_id")
|
|
839
|
-
shift_id String?
|
|
840
|
-
tenantId String?
|
|
841
|
-
shift Shift? @relation(fields: [shift_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_shift")
|
|
842
|
-
tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
843
|
-
operator Operator @relation(fields: [operatorId], references: [id], onDelete: Cascade)
|
|
844
|
-
|
|
845
|
-
@@map("operator_shift")
|
|
846
|
-
}
|
|
847
|
-
|
|
848
854
|
view ProductivityInterval {
|
|
849
855
|
machineId String
|
|
850
856
|
sequenceId Int @map("sequence_id")
|
|
@@ -1002,7 +1008,7 @@ model ProductBatch {
|
|
|
1002
1008
|
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
|
1003
1009
|
tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1004
1010
|
|
|
1005
|
-
@@unique([productId, batchNumber])
|
|
1011
|
+
@@unique([productId, batchNumber, internalBatchNumber])
|
|
1006
1012
|
@@map("product_batch")
|
|
1007
1013
|
}
|
|
1008
1014
|
|
|
@@ -1184,3 +1190,35 @@ enum QualityIssueCategory {
|
|
|
1184
1190
|
PROCESS_DEVIATION
|
|
1185
1191
|
OTHER
|
|
1186
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
|
+
}
|