Selection of multiple officials and role sub-categories
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
-- OrgRole hierarchy (parent / child sub-roles)
|
||||
ALTER TABLE "OrgRole" ADD COLUMN IF NOT EXISTS "parentId" TEXT;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "OrgRole_parentId_idx" ON "OrgRole"("parentId");
|
||||
CREATE INDEX IF NOT EXISTS "OrgRole_organizationId_parentId_idx" ON "OrgRole"("organizationId", "parentId");
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = 'OrgRole_parentId_fkey'
|
||||
) THEN
|
||||
ALTER TABLE "OrgRole"
|
||||
ADD CONSTRAINT "OrgRole_parentId_fkey"
|
||||
FOREIGN KEY ("parentId") REFERENCES "OrgRole"("id")
|
||||
ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
END IF;
|
||||
END $$;
|
||||
@@ -0,0 +1,35 @@
|
||||
-- Multi-assignee support for activities (implicit many-to-many)
|
||||
CREATE TABLE IF NOT EXISTS "_ActivityAssignees" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "_ActivityAssignees_AB_unique" ON "_ActivityAssignees"("A", "B");
|
||||
CREATE INDEX IF NOT EXISTS "_ActivityAssignees_B_index" ON "_ActivityAssignees"("B");
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = '_ActivityAssignees_A_fkey'
|
||||
) THEN
|
||||
ALTER TABLE "_ActivityAssignees"
|
||||
ADD CONSTRAINT "_ActivityAssignees_A_fkey"
|
||||
FOREIGN KEY ("A") REFERENCES "Activity"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
END IF;
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = '_ActivityAssignees_B_fkey'
|
||||
) THEN
|
||||
ALTER TABLE "_ActivityAssignees"
|
||||
ADD CONSTRAINT "_ActivityAssignees_B_fkey"
|
||||
FOREIGN KEY ("B") REFERENCES "User"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Backfill from legacy single assigneeId
|
||||
INSERT INTO "_ActivityAssignees" ("A", "B")
|
||||
SELECT a."id", a."assigneeId"
|
||||
FROM "Activity" a
|
||||
WHERE a."assigneeId" IS NOT NULL
|
||||
ON CONFLICT DO NOTHING;
|
||||
@@ -246,6 +246,7 @@ model User {
|
||||
ownedCompanies Company[] @relation("CompanyOwner")
|
||||
ownedProjectCards ProjectCard[] @relation("ProjectCardOwner")
|
||||
activities Activity[] @relation("ActivityAssignee")
|
||||
assignedActivities Activity[] @relation("ActivityAssignees")
|
||||
createdActivities Activity[] @relation("ActivityCreator")
|
||||
notes Note[] @relation("NoteAuthor")
|
||||
noteRevisions NoteRevision[] @relation("NoteRevisionEditor")
|
||||
@@ -288,6 +289,10 @@ model OrgRole {
|
||||
permissions String[] @default([])
|
||||
/// owner | admin | sales | support — نقشهای سیستمی قابل حذف نیستند
|
||||
systemKey String?
|
||||
/// نقش والد برای سلسلهمراتب زیرنقشها
|
||||
parentId String?
|
||||
parent OrgRole? @relation("OrgRoleTree", fields: [parentId], references: [id], onDelete: Restrict)
|
||||
children OrgRole[] @relation("OrgRoleTree")
|
||||
users User[]
|
||||
memberships Membership[]
|
||||
createdAt DateTime @default(now())
|
||||
@@ -295,6 +300,8 @@ model OrgRole {
|
||||
|
||||
@@unique([organizationId, name])
|
||||
@@index([organizationId])
|
||||
@@index([parentId])
|
||||
@@index([organizationId, parentId])
|
||||
}
|
||||
|
||||
model Membership {
|
||||
@@ -579,6 +586,8 @@ model Activity {
|
||||
deal Deal? @relation(fields: [dealId], references: [id], onDelete: SetNull)
|
||||
assigneeId String?
|
||||
assignee User? @relation("ActivityAssignee", fields: [assigneeId], references: [id], onDelete: SetNull)
|
||||
/// مسئولان مشترک (علاوه بر assigneeId بهعنوان مسئول اصلی)
|
||||
assignees User[] @relation("ActivityAssignees")
|
||||
createdById String?
|
||||
createdBy User? @relation("ActivityCreator", fields: [createdById], references: [id], onDelete: SetNull)
|
||||
notes Note[]
|
||||
|
||||
Reference in New Issue
Block a user