@juliobrim/prisma-shared 1.0.50 → 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,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.50",
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,7 +59,7 @@ 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
65
  operatorAvailability OperatorAvailabilityCache[]
@@ -583,12 +583,13 @@ model PasswordResetToken {
583
583
  }
584
584
 
585
585
  model Permission {
586
- id Int @id @default(autoincrement())
587
- title Int?
588
- description String?
589
- 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?
590
591
 
591
- @@map("permission")
592
+ roles RolePermission[]
592
593
  }
593
594
 
594
595
  model Product {
@@ -727,6 +728,27 @@ model Resource {
727
728
  @@map("resource")
728
729
  }
729
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
+
730
752
  model Sector {
731
753
  id String @id @default(cuid())
732
754
  name String @unique @db.VarChar(100)
@@ -825,7 +847,8 @@ model User {
825
847
  image String?
826
848
  password String
827
849
  isTwoFactorEnabled Boolean @default(false)
828
- role UserRole @default(USER)
850
+ roleId String?
851
+ role Role? @relation(fields: [roleId], references: [id])
829
852
  tenantId String?
830
853
  accounts Account[]
831
854
  follows Follower[]
@@ -833,24 +856,11 @@ model User {
833
856
  Panel Panel[]
834
857
  twoFactorConfirmation TwoFactorConfirmation?
835
858
  tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
836
- userPermissions UserPermission[]
837
859
  aiConversations AiConversation[]
838
860
 
839
861
  @@map("user")
840
862
  }
841
863
 
842
- model UserPermission {
843
- id Int @id @default(autoincrement())
844
- userId String @map("user_id")
845
- permission_id Int?
846
- tenantId String?
847
- permission Permission? @relation(fields: [permission_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_permission")
848
- tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: Cascade)
849
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
850
-
851
- @@map("user_permission")
852
- }
853
-
854
864
  view ProductivityInterval {
855
865
  machineId String
856
866
  sequenceId Int @map("sequence_id")