feat(automations): form-driven branching rules, round-robin assignment, lead-linked activities

This commit is contained in:
2026-10-11 14:12:36 +03:30
parent b30f68563d
commit b3b92abae9
27 changed files with 1160 additions and 91 deletions
@@ -0,0 +1,25 @@
-- AlterTable
ALTER TABLE "Activity" ADD COLUMN "leadId" TEXT;
-- CreateTable
CREATE TABLE "AutomationCursor" (
"id" TEXT NOT NULL,
"ruleId" TEXT NOT NULL,
"stepId" TEXT NOT NULL,
"counter" INTEGER NOT NULL DEFAULT 0,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "AutomationCursor_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "Activity_leadId_idx" ON "Activity"("leadId");
-- CreateIndex
CREATE UNIQUE INDEX "AutomationCursor_ruleId_stepId_key" ON "AutomationCursor"("ruleId", "stepId");
-- AddForeignKey
ALTER TABLE "Activity" ADD CONSTRAINT "Activity_leadId_fkey" FOREIGN KEY ("leadId") REFERENCES "Lead"("id") ON DELETE SET NULL ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "AutomationCursor" ADD CONSTRAINT "AutomationCursor_ruleId_fkey" FOREIGN KEY ("ruleId") REFERENCES "AutomationRule"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+18
View File
@@ -725,11 +725,15 @@ model Activity {
fields Json?
/// کاربران شرکت‌کننده؛ فعالیت در لیست آن‌ها هم دیده می‌شود
participantIds String[] @default([])
/// لید مرتبط (مثلاً فعالیت ساخته‌شده از ارسال فرم)
leadId String?
lead Lead? @relation(fields: [leadId], references: [id], onDelete: SetNull)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([stageId])
@@index([typeDefId])
@@index([leadId])
@@index([organizationId, status, dueAt])
@@index([organizationId, assigneeId])
@@index([organizationId, createdById])
@@ -1443,12 +1447,25 @@ model AutomationRule {
action AutomationAction
/// عنوان فعالیت/اعلان، assigneeId، notifyUserId، points، activityType
config Json @default("{}")
cursors AutomationCursor[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([organizationId, isActive, trigger])
}
/// شمارندهٔ تقسیم نوبتی برای هر گام عمل در یک قانون اتوماسیون
model AutomationCursor {
id String @id @default(cuid())
ruleId String
rule AutomationRule @relation(fields: [ruleId], references: [id], onDelete: Cascade)
stepId String
counter Int @default(0)
updatedAt DateTime @updatedAt
@@unique([ruleId, stepId])
}
enum MessageAutomationTrigger {
person_created
lead_submitted
@@ -2400,6 +2417,7 @@ model Lead {
trackingLinks TrackingLink[]
trackingEvents TrackingEvent[]
routineTasks RoutineTask[]
activities Activity[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt