create-crm-tmp 1.0.0
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/bin/create-crm-tmp.js +93 -0
- package/package.json +25 -0
- package/template/.prettierignore +33 -0
- package/template/.prettierrc.json +25 -0
- package/template/README.md +173 -0
- package/template/eslint.config.mjs +18 -0
- package/template/exemple-contacts.csv +11 -0
- package/template/next.config.ts +8 -0
- package/template/package.json +64 -0
- package/template/postcss.config.mjs +7 -0
- package/template/prisma/migrations/20251126144728_init/migration.sql +78 -0
- package/template/prisma/migrations/20251126155204_add_user_roles/migration.sql +5 -0
- package/template/prisma/migrations/20251128095126_add_company_info/migration.sql +19 -0
- package/template/prisma/migrations/20251128123321_add_smtp_config/migration.sql +22 -0
- package/template/prisma/migrations/20251128132303_add_status/migration.sql +23 -0
- package/template/prisma/migrations/20251201102207_add_user_active/migration.sql +75 -0
- package/template/prisma/migrations/20251201105507_add_email_signature/migration.sql +2 -0
- package/template/prisma/migrations/20251201151122_add_tasks/migration.sql +45 -0
- package/template/prisma/migrations/20251202111854_add_task_reminder/migration.sql +2 -0
- package/template/prisma/migrations/20251202135859_add_google_meet_integration/migration.sql +27 -0
- package/template/prisma/migrations/20251203103317_add_meta_lead_integration/migration.sql +20 -0
- package/template/prisma/migrations/20251203104002_add_google_ads_integration/migration.sql +18 -0
- package/template/prisma/migrations/20251203112122_add_google_sheet_integration/migration.sql +32 -0
- package/template/prisma/migrations/20251203153853_allow_multiple_integration_configs/migration.sql +20 -0
- package/template/prisma/migrations/20251205141705_update_user_roles/migration.sql +12 -0
- package/template/prisma/migrations/20251205150000_add_commercial_and_telepro_assignment/migration.sql +21 -0
- package/template/prisma/migrations/20251205160000_add_interaction_logging/migration.sql +11 -0
- package/template/prisma/migrations/20251208090314_add_automatic_interaction_types/migration.sql +12 -0
- package/template/prisma/migrations/20251208094843_mg/migration.sql +14 -0
- package/template/prisma/migrations/20251208100000_add_company_support/migration.sql +14 -0
- package/template/prisma/migrations/20251208110000_add_templates/migration.sql +26 -0
- package/template/prisma/migrations/20251208141304_add_video_conference_task_type/migration.sql +2 -0
- package/template/prisma/migrations/20251209104759_add_internal_note_to_task/migration.sql +2 -0
- package/template/prisma/migrations/20251209134803_add_company_field/migration.sql +2 -0
- package/template/prisma/migrations/20251209150000_rename_company_to_company_name/migration.sql +3 -0
- package/template/prisma/migrations/20251209150016_add_email_tracking/migration.sql +21 -0
- package/template/prisma/migrations/20251209155908_add_notify_contact_to_task/migration.sql +2 -0
- package/template/prisma/migrations/20251210110019_add_appointment_types/migration.sql +10 -0
- package/template/prisma/migrations/20251210113928_add_contact_files/migration.sql +26 -0
- package/template/prisma/migrations/20251212132339_add_custom_roles/migration.sql +24 -0
- package/template/prisma/migrations/20251215104448_add_file_interaction_types/migration.sql +11 -0
- package/template/prisma/migrations/20251215145616_add_closing_reasons/migration.sql +12 -0
- package/template/prisma/migrations/20251216140850_add_log_users/migration.sql +25 -0
- package/template/prisma/migrations/20251216151000_rename_perdu_to_ferme/migration.sql +8 -0
- package/template/prisma/migrations/20251216162318_add_column_mappings_to_google_sheet/migration.sql +2 -0
- package/template/prisma/migrations/20251216185127_add_workflows/migration.sql +80 -0
- package/template/prisma/migrations/20251216192237_add_scheduled_workflow_actions/migration.sql +32 -0
- package/template/prisma/migrations/migration_lock.toml +3 -0
- package/template/prisma/schema.prisma +582 -0
- package/template/prisma.config.ts +14 -0
- package/template/src/app/(auth)/invite/[token]/page.tsx +200 -0
- package/template/src/app/(auth)/layout.tsx +3 -0
- package/template/src/app/(auth)/reset-password/complete/page.tsx +213 -0
- package/template/src/app/(auth)/reset-password/page.tsx +146 -0
- package/template/src/app/(auth)/reset-password/verify/page.tsx +183 -0
- package/template/src/app/(auth)/signin/page.tsx +166 -0
- package/template/src/app/(dashboard)/agenda/page.tsx +3051 -0
- package/template/src/app/(dashboard)/automatisation/[id]/page.tsx +24 -0
- package/template/src/app/(dashboard)/automatisation/_components/workflow-editor.tsx +905 -0
- package/template/src/app/(dashboard)/automatisation/new/page.tsx +20 -0
- package/template/src/app/(dashboard)/automatisation/page.tsx +337 -0
- package/template/src/app/(dashboard)/closing/page.tsx +1052 -0
- package/template/src/app/(dashboard)/contacts/[id]/page.tsx +6028 -0
- package/template/src/app/(dashboard)/contacts/page.tsx +3713 -0
- package/template/src/app/(dashboard)/dashboard/page.tsx +186 -0
- package/template/src/app/(dashboard)/layout.tsx +30 -0
- package/template/src/app/(dashboard)/settings/page.tsx +4070 -0
- package/template/src/app/(dashboard)/templates/page.tsx +567 -0
- package/template/src/app/(dashboard)/users/list/page.tsx +507 -0
- package/template/src/app/(dashboard)/users/page.tsx +457 -0
- package/template/src/app/(dashboard)/users/permissions/page.tsx +181 -0
- package/template/src/app/(dashboard)/users/roles/page.tsx +434 -0
- package/template/src/app/api/audit-logs/route.ts +57 -0
- package/template/src/app/api/auth/[...all]/route.ts +4 -0
- package/template/src/app/api/auth/check-active/route.ts +31 -0
- package/template/src/app/api/auth/google/callback/route.ts +94 -0
- package/template/src/app/api/auth/google/disconnect/route.ts +32 -0
- package/template/src/app/api/auth/google/route.ts +34 -0
- package/template/src/app/api/auth/google/status/route.ts +32 -0
- package/template/src/app/api/closing-reasons/route.ts +27 -0
- package/template/src/app/api/contacts/[id]/files/[fileId]/route.ts +94 -0
- package/template/src/app/api/contacts/[id]/files/route.ts +269 -0
- package/template/src/app/api/contacts/[id]/interactions/[interactionId]/route.ts +91 -0
- package/template/src/app/api/contacts/[id]/interactions/route.ts +103 -0
- package/template/src/app/api/contacts/[id]/meet/route.ts +296 -0
- package/template/src/app/api/contacts/[id]/route.ts +322 -0
- package/template/src/app/api/contacts/[id]/send-email/route.ts +254 -0
- package/template/src/app/api/contacts/export/route.ts +270 -0
- package/template/src/app/api/contacts/import/route.ts +381 -0
- package/template/src/app/api/contacts/route.ts +283 -0
- package/template/src/app/api/dashboard/stats/route.ts +299 -0
- package/template/src/app/api/email/track/[id]/route.ts +68 -0
- package/template/src/app/api/integrations/google-sheet/sync/route.ts +526 -0
- package/template/src/app/api/invite/complete/route.ts +88 -0
- package/template/src/app/api/invite/validate/route.ts +55 -0
- package/template/src/app/api/reminders/route.ts +95 -0
- package/template/src/app/api/reset-password/complete/route.ts +73 -0
- package/template/src/app/api/reset-password/request/route.ts +84 -0
- package/template/src/app/api/reset-password/validate/route.ts +49 -0
- package/template/src/app/api/reset-password/verify/route.ts +74 -0
- package/template/src/app/api/roles/[id]/route.ts +183 -0
- package/template/src/app/api/roles/route.ts +140 -0
- package/template/src/app/api/send/route.ts +282 -0
- package/template/src/app/api/settings/change-password/route.ts +95 -0
- package/template/src/app/api/settings/closing-reasons/[id]/route.ts +84 -0
- package/template/src/app/api/settings/closing-reasons/route.ts +74 -0
- package/template/src/app/api/settings/company/route.ts +121 -0
- package/template/src/app/api/settings/google-ads/[id]/route.ts +117 -0
- package/template/src/app/api/settings/google-ads/route.ts +122 -0
- package/template/src/app/api/settings/google-sheet/[id]/route.ts +230 -0
- package/template/src/app/api/settings/google-sheet/auto-map/route.ts +196 -0
- package/template/src/app/api/settings/google-sheet/route.ts +254 -0
- package/template/src/app/api/settings/meta-leads/[id]/route.ts +123 -0
- package/template/src/app/api/settings/meta-leads/route.ts +132 -0
- package/template/src/app/api/settings/profile/route.ts +42 -0
- package/template/src/app/api/settings/smtp/route.ts +130 -0
- package/template/src/app/api/settings/smtp/test/route.ts +121 -0
- package/template/src/app/api/settings/statuses/[id]/route.ts +101 -0
- package/template/src/app/api/settings/statuses/route.ts +83 -0
- package/template/src/app/api/statuses/route.ts +25 -0
- package/template/src/app/api/tasks/[id]/attendees/route.ts +76 -0
- package/template/src/app/api/tasks/[id]/route.ts +728 -0
- package/template/src/app/api/tasks/meet/route.ts +240 -0
- package/template/src/app/api/tasks/route.ts +417 -0
- package/template/src/app/api/templates/[id]/route.ts +140 -0
- package/template/src/app/api/templates/route.ts +91 -0
- package/template/src/app/api/users/[id]/route.ts +168 -0
- package/template/src/app/api/users/list/route.ts +45 -0
- package/template/src/app/api/users/me/route.ts +48 -0
- package/template/src/app/api/users/route.ts +250 -0
- package/template/src/app/api/webhooks/google-ads/route.ts +208 -0
- package/template/src/app/api/webhooks/meta-leads/route.ts +258 -0
- package/template/src/app/api/workflows/[id]/route.ts +192 -0
- package/template/src/app/api/workflows/process/route.ts +293 -0
- package/template/src/app/api/workflows/route.ts +124 -0
- package/template/src/app/favicon.ico +0 -0
- package/template/src/app/globals.css +1416 -0
- package/template/src/app/layout.tsx +31 -0
- package/template/src/app/page.tsx +32 -0
- package/template/src/components/dashboard/activity-chart.tsx +67 -0
- package/template/src/components/dashboard/contacts-chart.tsx +63 -0
- package/template/src/components/dashboard/recent-activity.tsx +164 -0
- package/template/src/components/dashboard/sales-analytics-chart.tsx +81 -0
- package/template/src/components/dashboard/stat-card.tsx +61 -0
- package/template/src/components/dashboard/status-distribution-chart.tsx +45 -0
- package/template/src/components/dashboard/tasks-pie-chart.tsx +88 -0
- package/template/src/components/dashboard/top-contacts-list.tsx +129 -0
- package/template/src/components/dashboard/upcoming-tasks-list.tsx +126 -0
- package/template/src/components/editor.tsx +856 -0
- package/template/src/components/email-template.tsx +35 -0
- package/template/src/components/header.tsx +320 -0
- package/template/src/components/invitation-email-template.tsx +79 -0
- package/template/src/components/meet-cancellation-email-template.tsx +120 -0
- package/template/src/components/meet-confirmation-email-template.tsx +156 -0
- package/template/src/components/meet-update-email-template.tsx +209 -0
- package/template/src/components/page-header.tsx +61 -0
- package/template/src/components/reset-password-email-template.tsx +79 -0
- package/template/src/components/sidebar.tsx +294 -0
- package/template/src/components/skeleton.tsx +380 -0
- package/template/src/components/ui/commands.tsx +396 -0
- package/template/src/components/ui/components.tsx +150 -0
- package/template/src/components/ui/theme.tsx +5 -0
- package/template/src/components/view-as-banner.tsx +45 -0
- package/template/src/components/view-as-modal.tsx +186 -0
- package/template/src/contexts/mobile-menu-context.tsx +31 -0
- package/template/src/contexts/sidebar-context.tsx +107 -0
- package/template/src/contexts/task-reminder-context.tsx +239 -0
- package/template/src/contexts/view-as-context.tsx +84 -0
- package/template/src/hooks/use-user-role.ts +82 -0
- package/template/src/lib/audit-log.ts +45 -0
- package/template/src/lib/auth-client.ts +16 -0
- package/template/src/lib/auth.ts +35 -0
- package/template/src/lib/check-permission.ts +193 -0
- package/template/src/lib/contact-duplicate.ts +112 -0
- package/template/src/lib/contact-interactions.ts +371 -0
- package/template/src/lib/encryption.ts +99 -0
- package/template/src/lib/google-calendar.ts +300 -0
- package/template/src/lib/google-drive.ts +372 -0
- package/template/src/lib/permissions.ts +412 -0
- package/template/src/lib/prisma.ts +32 -0
- package/template/src/lib/roles.ts +120 -0
- package/template/src/lib/template-variables.ts +76 -0
- package/template/src/lib/utils.ts +46 -0
- package/template/src/lib/workflow-executor.ts +482 -0
- package/template/src/proxy.ts +91 -0
- package/template/tsconfig.json +34 -0
- package/template/vercel.json +8 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
-- CreateEnum
|
|
2
|
+
CREATE TYPE "Civility" AS ENUM ('M', 'MME', 'MLLE');
|
|
3
|
+
|
|
4
|
+
-- CreateEnum
|
|
5
|
+
CREATE TYPE "InteractionType" AS ENUM ('CALL', 'SMS', 'EMAIL', 'MEETING', 'NOTE');
|
|
6
|
+
|
|
7
|
+
-- AlterTable
|
|
8
|
+
ALTER TABLE "user" ADD COLUMN "active" BOOLEAN NOT NULL DEFAULT true;
|
|
9
|
+
|
|
10
|
+
-- CreateTable
|
|
11
|
+
CREATE TABLE "contact" (
|
|
12
|
+
"id" TEXT NOT NULL,
|
|
13
|
+
"civility" "Civility",
|
|
14
|
+
"firstName" TEXT,
|
|
15
|
+
"lastName" TEXT,
|
|
16
|
+
"phone" TEXT NOT NULL,
|
|
17
|
+
"secondaryPhone" TEXT,
|
|
18
|
+
"email" TEXT,
|
|
19
|
+
"address" TEXT,
|
|
20
|
+
"city" TEXT,
|
|
21
|
+
"postalCode" TEXT,
|
|
22
|
+
"origin" TEXT,
|
|
23
|
+
"statusId" TEXT,
|
|
24
|
+
"assignedUserId" TEXT,
|
|
25
|
+
"createdById" TEXT NOT NULL,
|
|
26
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
27
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
28
|
+
|
|
29
|
+
CONSTRAINT "contact_pkey" PRIMARY KEY ("id")
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
-- CreateTable
|
|
33
|
+
CREATE TABLE "interaction" (
|
|
34
|
+
"id" TEXT NOT NULL,
|
|
35
|
+
"contactId" TEXT NOT NULL,
|
|
36
|
+
"type" "InteractionType" NOT NULL,
|
|
37
|
+
"title" TEXT,
|
|
38
|
+
"content" TEXT NOT NULL,
|
|
39
|
+
"userId" TEXT NOT NULL,
|
|
40
|
+
"date" TIMESTAMP(3),
|
|
41
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
42
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
43
|
+
|
|
44
|
+
CONSTRAINT "interaction_pkey" PRIMARY KEY ("id")
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
-- CreateIndex
|
|
48
|
+
CREATE INDEX "contact_statusId_idx" ON "contact"("statusId");
|
|
49
|
+
|
|
50
|
+
-- CreateIndex
|
|
51
|
+
CREATE INDEX "contact_assignedUserId_idx" ON "contact"("assignedUserId");
|
|
52
|
+
|
|
53
|
+
-- CreateIndex
|
|
54
|
+
CREATE INDEX "contact_createdById_idx" ON "contact"("createdById");
|
|
55
|
+
|
|
56
|
+
-- CreateIndex
|
|
57
|
+
CREATE INDEX "interaction_contactId_idx" ON "interaction"("contactId");
|
|
58
|
+
|
|
59
|
+
-- CreateIndex
|
|
60
|
+
CREATE INDEX "interaction_userId_idx" ON "interaction"("userId");
|
|
61
|
+
|
|
62
|
+
-- AddForeignKey
|
|
63
|
+
ALTER TABLE "contact" ADD CONSTRAINT "contact_statusId_fkey" FOREIGN KEY ("statusId") REFERENCES "status"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
64
|
+
|
|
65
|
+
-- AddForeignKey
|
|
66
|
+
ALTER TABLE "contact" ADD CONSTRAINT "contact_assignedUserId_fkey" FOREIGN KEY ("assignedUserId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
67
|
+
|
|
68
|
+
-- AddForeignKey
|
|
69
|
+
ALTER TABLE "contact" ADD CONSTRAINT "contact_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
70
|
+
|
|
71
|
+
-- AddForeignKey
|
|
72
|
+
ALTER TABLE "interaction" ADD CONSTRAINT "interaction_contactId_fkey" FOREIGN KEY ("contactId") REFERENCES "contact"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
73
|
+
|
|
74
|
+
-- AddForeignKey
|
|
75
|
+
ALTER TABLE "interaction" ADD CONSTRAINT "interaction_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- CreateEnum
|
|
2
|
+
CREATE TYPE "TaskType" AS ENUM ('CALL', 'MEETING', 'EMAIL', 'OTHER');
|
|
3
|
+
|
|
4
|
+
-- CreateEnum
|
|
5
|
+
CREATE TYPE "TaskPriority" AS ENUM ('LOW', 'MEDIUM', 'HIGH', 'URGENT');
|
|
6
|
+
|
|
7
|
+
-- CreateTable
|
|
8
|
+
CREATE TABLE "task" (
|
|
9
|
+
"id" TEXT NOT NULL,
|
|
10
|
+
"contactId" TEXT,
|
|
11
|
+
"type" "TaskType" NOT NULL,
|
|
12
|
+
"title" TEXT,
|
|
13
|
+
"description" TEXT NOT NULL,
|
|
14
|
+
"priority" "TaskPriority" NOT NULL DEFAULT 'MEDIUM',
|
|
15
|
+
"scheduledAt" TIMESTAMP(3) NOT NULL,
|
|
16
|
+
"assignedUserId" TEXT NOT NULL,
|
|
17
|
+
"createdById" TEXT NOT NULL,
|
|
18
|
+
"completed" BOOLEAN NOT NULL DEFAULT false,
|
|
19
|
+
"completedAt" TIMESTAMP(3),
|
|
20
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
21
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
22
|
+
|
|
23
|
+
CONSTRAINT "task_pkey" PRIMARY KEY ("id")
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
-- CreateIndex
|
|
27
|
+
CREATE INDEX "task_contactId_idx" ON "task"("contactId");
|
|
28
|
+
|
|
29
|
+
-- CreateIndex
|
|
30
|
+
CREATE INDEX "task_assignedUserId_idx" ON "task"("assignedUserId");
|
|
31
|
+
|
|
32
|
+
-- CreateIndex
|
|
33
|
+
CREATE INDEX "task_createdById_idx" ON "task"("createdById");
|
|
34
|
+
|
|
35
|
+
-- CreateIndex
|
|
36
|
+
CREATE INDEX "task_scheduledAt_idx" ON "task"("scheduledAt");
|
|
37
|
+
|
|
38
|
+
-- AddForeignKey
|
|
39
|
+
ALTER TABLE "task" ADD CONSTRAINT "task_contactId_fkey" FOREIGN KEY ("contactId") REFERENCES "contact"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
40
|
+
|
|
41
|
+
-- AddForeignKey
|
|
42
|
+
ALTER TABLE "task" ADD CONSTRAINT "task_assignedUserId_fkey" FOREIGN KEY ("assignedUserId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
43
|
+
|
|
44
|
+
-- AddForeignKey
|
|
45
|
+
ALTER TABLE "task" ADD CONSTRAINT "task_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- AlterTable
|
|
2
|
+
ALTER TABLE "task" ADD COLUMN "durationMinutes" INTEGER,
|
|
3
|
+
ADD COLUMN "googleEventId" TEXT,
|
|
4
|
+
ADD COLUMN "googleMeetLink" TEXT;
|
|
5
|
+
|
|
6
|
+
-- CreateTable
|
|
7
|
+
CREATE TABLE "user_google_account" (
|
|
8
|
+
"id" TEXT NOT NULL,
|
|
9
|
+
"userId" TEXT NOT NULL,
|
|
10
|
+
"accessToken" TEXT NOT NULL,
|
|
11
|
+
"refreshToken" TEXT NOT NULL,
|
|
12
|
+
"tokenExpiresAt" TIMESTAMP(3) NOT NULL,
|
|
13
|
+
"email" TEXT,
|
|
14
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
15
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
16
|
+
|
|
17
|
+
CONSTRAINT "user_google_account_pkey" PRIMARY KEY ("id")
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- CreateIndex
|
|
21
|
+
CREATE UNIQUE INDEX "user_google_account_userId_key" ON "user_google_account"("userId");
|
|
22
|
+
|
|
23
|
+
-- CreateIndex
|
|
24
|
+
CREATE INDEX "task_googleEventId_idx" ON "task"("googleEventId");
|
|
25
|
+
|
|
26
|
+
-- AddForeignKey
|
|
27
|
+
ALTER TABLE "user_google_account" ADD CONSTRAINT "user_google_account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "meta_lead_config" (
|
|
3
|
+
"id" TEXT NOT NULL DEFAULT 'meta_lead_config_singleton',
|
|
4
|
+
"pageId" TEXT NOT NULL,
|
|
5
|
+
"accessToken" TEXT NOT NULL,
|
|
6
|
+
"verifyToken" TEXT NOT NULL,
|
|
7
|
+
"active" BOOLEAN NOT NULL DEFAULT true,
|
|
8
|
+
"defaultStatusId" TEXT,
|
|
9
|
+
"defaultAssignedUserId" TEXT,
|
|
10
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
11
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
12
|
+
|
|
13
|
+
CONSTRAINT "meta_lead_config_pkey" PRIMARY KEY ("id")
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
-- AddForeignKey
|
|
17
|
+
ALTER TABLE "meta_lead_config" ADD CONSTRAINT "meta_lead_config_defaultStatusId_fkey" FOREIGN KEY ("defaultStatusId") REFERENCES "status"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
18
|
+
|
|
19
|
+
-- AddForeignKey
|
|
20
|
+
ALTER TABLE "meta_lead_config" ADD CONSTRAINT "meta_lead_config_defaultAssignedUserId_fkey" FOREIGN KEY ("defaultAssignedUserId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "google_ads_lead_config" (
|
|
3
|
+
"id" TEXT NOT NULL DEFAULT 'google_ads_lead_config_singleton',
|
|
4
|
+
"webhookKey" TEXT NOT NULL,
|
|
5
|
+
"active" BOOLEAN NOT NULL DEFAULT true,
|
|
6
|
+
"defaultStatusId" TEXT,
|
|
7
|
+
"defaultAssignedUserId" TEXT,
|
|
8
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
9
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
10
|
+
|
|
11
|
+
CONSTRAINT "google_ads_lead_config_pkey" PRIMARY KEY ("id")
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
-- AddForeignKey
|
|
15
|
+
ALTER TABLE "google_ads_lead_config" ADD CONSTRAINT "google_ads_lead_config_defaultStatusId_fkey" FOREIGN KEY ("defaultStatusId") REFERENCES "status"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
16
|
+
|
|
17
|
+
-- AddForeignKey
|
|
18
|
+
ALTER TABLE "google_ads_lead_config" ADD CONSTRAINT "google_ads_lead_config_defaultAssignedUserId_fkey" FOREIGN KEY ("defaultAssignedUserId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "google_sheet_sync_config" (
|
|
3
|
+
"id" TEXT NOT NULL DEFAULT 'google_sheet_sync_config_singleton',
|
|
4
|
+
"ownerUserId" TEXT NOT NULL,
|
|
5
|
+
"spreadsheetId" TEXT NOT NULL,
|
|
6
|
+
"sheetName" TEXT NOT NULL,
|
|
7
|
+
"headerRow" INTEGER NOT NULL,
|
|
8
|
+
"phoneColumn" TEXT NOT NULL,
|
|
9
|
+
"firstNameColumn" TEXT,
|
|
10
|
+
"lastNameColumn" TEXT,
|
|
11
|
+
"emailColumn" TEXT,
|
|
12
|
+
"cityColumn" TEXT,
|
|
13
|
+
"postalCodeColumn" TEXT,
|
|
14
|
+
"originColumn" TEXT,
|
|
15
|
+
"active" BOOLEAN NOT NULL DEFAULT true,
|
|
16
|
+
"lastSyncedRow" INTEGER,
|
|
17
|
+
"defaultStatusId" TEXT,
|
|
18
|
+
"defaultAssignedUserId" TEXT,
|
|
19
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
20
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
21
|
+
|
|
22
|
+
CONSTRAINT "google_sheet_sync_config_pkey" PRIMARY KEY ("id")
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
-- AddForeignKey
|
|
26
|
+
ALTER TABLE "google_sheet_sync_config" ADD CONSTRAINT "google_sheet_sync_config_ownerUserId_fkey" FOREIGN KEY ("ownerUserId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
27
|
+
|
|
28
|
+
-- AddForeignKey
|
|
29
|
+
ALTER TABLE "google_sheet_sync_config" ADD CONSTRAINT "google_sheet_sync_config_defaultStatusId_fkey" FOREIGN KEY ("defaultStatusId") REFERENCES "status"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
30
|
+
|
|
31
|
+
-- AddForeignKey
|
|
32
|
+
ALTER TABLE "google_sheet_sync_config" ADD CONSTRAINT "google_sheet_sync_config_defaultAssignedUserId_fkey" FOREIGN KEY ("defaultAssignedUserId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
package/template/prisma/migrations/20251203153853_allow_multiple_integration_configs/migration.sql
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Ajouter la colonne name avec une valeur par défaut temporaire
|
|
2
|
+
ALTER TABLE "google_ads_lead_config" ADD COLUMN "name" TEXT;
|
|
3
|
+
ALTER TABLE "google_sheet_sync_config" ADD COLUMN "name" TEXT;
|
|
4
|
+
ALTER TABLE "meta_lead_config" ADD COLUMN "name" TEXT;
|
|
5
|
+
|
|
6
|
+
-- Mettre à jour les valeurs existantes avec un nom par défaut
|
|
7
|
+
UPDATE "google_ads_lead_config" SET "name" = 'Configuration Google Ads' WHERE "name" IS NULL;
|
|
8
|
+
UPDATE "google_sheet_sync_config" SET "name" = 'Configuration Google Sheets' WHERE "name" IS NULL;
|
|
9
|
+
UPDATE "meta_lead_config" SET "name" = 'Configuration Meta Lead Ads' WHERE "name" IS NULL;
|
|
10
|
+
|
|
11
|
+
-- Rendre la colonne NOT NULL
|
|
12
|
+
ALTER TABLE "google_ads_lead_config" ALTER COLUMN "name" SET NOT NULL;
|
|
13
|
+
ALTER TABLE "google_sheet_sync_config" ALTER COLUMN "name" SET NOT NULL;
|
|
14
|
+
ALTER TABLE "meta_lead_config" ALTER COLUMN "name" SET NOT NULL;
|
|
15
|
+
|
|
16
|
+
-- Changer l'ID pour utiliser cuid() au lieu d'une valeur fixe
|
|
17
|
+
-- Pour les tables existantes, on garde l'ID actuel mais on supprime la contrainte DEFAULT
|
|
18
|
+
ALTER TABLE "google_ads_lead_config" ALTER COLUMN "id" DROP DEFAULT;
|
|
19
|
+
ALTER TABLE "google_sheet_sync_config" ALTER COLUMN "id" DROP DEFAULT;
|
|
20
|
+
ALTER TABLE "meta_lead_config" ALTER COLUMN "id" DROP DEFAULT;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- AlterEnum
|
|
2
|
+
-- This migration adds more than one value to an enum.
|
|
3
|
+
-- With PostgreSQL versions 11 and earlier, this is not possible
|
|
4
|
+
-- in a single migration. This can be worked around by creating
|
|
5
|
+
-- multiple migrations, each migration adding only one value to
|
|
6
|
+
-- the enum.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
ALTER TYPE "Role" ADD VALUE 'MANAGER';
|
|
10
|
+
ALTER TYPE "Role" ADD VALUE 'COMMERCIAL';
|
|
11
|
+
ALTER TYPE "Role" ADD VALUE 'TELEPRO';
|
|
12
|
+
ALTER TYPE "Role" ADD VALUE 'COMPTABLE';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- Ajouter les nouvelles colonnes
|
|
2
|
+
ALTER TABLE "contact" ADD COLUMN "assignedCommercialId" TEXT;
|
|
3
|
+
ALTER TABLE "contact" ADD COLUMN "assignedTeleproId" TEXT;
|
|
4
|
+
|
|
5
|
+
-- Migrer les données existantes : assigner les contacts existants au commercial
|
|
6
|
+
-- (on suppose que les utilisateurs assignés actuellement sont des commerciaux)
|
|
7
|
+
UPDATE "contact" SET "assignedCommercialId" = "assignedUserId" WHERE "assignedUserId" IS NOT NULL;
|
|
8
|
+
|
|
9
|
+
-- Créer les index
|
|
10
|
+
CREATE INDEX IF NOT EXISTS "contact_assignedCommercialId_idx" ON "contact"("assignedCommercialId");
|
|
11
|
+
CREATE INDEX IF NOT EXISTS "contact_assignedTeleproId_idx" ON "contact"("assignedTeleproId");
|
|
12
|
+
|
|
13
|
+
-- Ajouter les contraintes de clé étrangère
|
|
14
|
+
ALTER TABLE "contact" ADD CONSTRAINT "contact_assignedCommercialId_fkey" FOREIGN KEY ("assignedCommercialId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
15
|
+
ALTER TABLE "contact" ADD CONSTRAINT "contact_assignedTeleproId_fkey" FOREIGN KEY ("assignedTeleproId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
16
|
+
|
|
17
|
+
-- Supprimer l'ancienne colonne et son index
|
|
18
|
+
DROP INDEX IF EXISTS "contact_assignedUserId_idx";
|
|
19
|
+
ALTER TABLE "contact" DROP CONSTRAINT IF EXISTS "contact_assignedUserId_fkey";
|
|
20
|
+
ALTER TABLE "contact" DROP COLUMN "assignedUserId";
|
|
21
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- AlterEnum
|
|
2
|
+
-- Ajouter les nouveaux types d'interactions à l'enum existant
|
|
3
|
+
ALTER TYPE "InteractionType" ADD VALUE IF NOT EXISTS 'STATUS_CHANGE';
|
|
4
|
+
ALTER TYPE "InteractionType" ADD VALUE IF NOT EXISTS 'CONTACT_UPDATE';
|
|
5
|
+
ALTER TYPE "InteractionType" ADD VALUE IF NOT EXISTS 'APPOINTMENT_CREATED';
|
|
6
|
+
ALTER TYPE "InteractionType" ADD VALUE IF NOT EXISTS 'ASSIGNMENT_CHANGE';
|
|
7
|
+
|
|
8
|
+
-- AlterTable
|
|
9
|
+
-- Ajouter le champ metadata à la table interaction
|
|
10
|
+
ALTER TABLE "interaction" ADD COLUMN IF NOT EXISTS "metadata" JSONB;
|
|
11
|
+
|
package/template/prisma/migrations/20251208090314_add_automatic_interaction_types/migration.sql
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- AlterEnum
|
|
2
|
+
-- This migration adds more than one value to an enum.
|
|
3
|
+
-- With PostgreSQL versions 11 and earlier, this is not possible
|
|
4
|
+
-- in a single migration. This can be worked around by creating
|
|
5
|
+
-- multiple migrations, each migration adding only one value to
|
|
6
|
+
-- the enum.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
ALTER TYPE "InteractionType" ADD VALUE 'STATUS_CHANGED';
|
|
10
|
+
ALTER TYPE "InteractionType" ADD VALUE 'INFO_UPDATED';
|
|
11
|
+
ALTER TYPE "InteractionType" ADD VALUE 'ASSIGNMENT_CHANGED';
|
|
12
|
+
ALTER TYPE "InteractionType" ADD VALUE 'CONTACT_CREATED';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Warnings:
|
|
3
|
+
|
|
4
|
+
- The values [STATUS_CHANGED,INFO_UPDATED,ASSIGNMENT_CHANGED,CONTACT_CREATED] on the enum `InteractionType` will be removed. If these variants are still used in the database, this will fail.
|
|
5
|
+
|
|
6
|
+
*/
|
|
7
|
+
-- AlterEnum
|
|
8
|
+
BEGIN;
|
|
9
|
+
CREATE TYPE "InteractionType_new" AS ENUM ('CALL', 'SMS', 'EMAIL', 'MEETING', 'NOTE', 'STATUS_CHANGE', 'CONTACT_UPDATE', 'APPOINTMENT_CREATED', 'ASSIGNMENT_CHANGE');
|
|
10
|
+
ALTER TABLE "interaction" ALTER COLUMN "type" TYPE "InteractionType_new" USING ("type"::text::"InteractionType_new");
|
|
11
|
+
ALTER TYPE "InteractionType" RENAME TO "InteractionType_old";
|
|
12
|
+
ALTER TYPE "InteractionType_new" RENAME TO "InteractionType";
|
|
13
|
+
DROP TYPE "public"."InteractionType_old";
|
|
14
|
+
COMMIT;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- Add isCompany and companyId fields to contact table
|
|
2
|
+
ALTER TABLE "contact" ADD COLUMN IF NOT EXISTS "isCompany" BOOLEAN NOT NULL DEFAULT false;
|
|
3
|
+
ALTER TABLE "contact" ADD COLUMN IF NOT EXISTS "companyId" TEXT;
|
|
4
|
+
|
|
5
|
+
-- Create index for companyId
|
|
6
|
+
CREATE INDEX IF NOT EXISTS "contact_companyId_idx" ON "contact"("companyId");
|
|
7
|
+
|
|
8
|
+
-- Create index for isCompany
|
|
9
|
+
CREATE INDEX IF NOT EXISTS "contact_isCompany_idx" ON "contact"("isCompany");
|
|
10
|
+
|
|
11
|
+
-- Add foreign key constraint for companyId
|
|
12
|
+
ALTER TABLE "contact" ADD CONSTRAINT "contact_companyId_fkey"
|
|
13
|
+
FOREIGN KEY ("companyId") REFERENCES "contact"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
14
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
-- CreateEnum
|
|
2
|
+
CREATE TYPE "TemplateType" AS ENUM ('EMAIL', 'SMS', 'NOTE');
|
|
3
|
+
|
|
4
|
+
-- CreateTable
|
|
5
|
+
CREATE TABLE IF NOT EXISTS "template" (
|
|
6
|
+
"id" TEXT NOT NULL,
|
|
7
|
+
"name" TEXT NOT NULL,
|
|
8
|
+
"type" "TemplateType" NOT NULL,
|
|
9
|
+
"subject" TEXT,
|
|
10
|
+
"content" TEXT NOT NULL,
|
|
11
|
+
"userId" TEXT NOT NULL,
|
|
12
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
13
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
14
|
+
|
|
15
|
+
CONSTRAINT "template_pkey" PRIMARY KEY ("id")
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
-- CreateIndex
|
|
19
|
+
CREATE INDEX IF NOT EXISTS "template_userId_idx" ON "template"("userId");
|
|
20
|
+
|
|
21
|
+
-- CreateIndex
|
|
22
|
+
CREATE INDEX IF NOT EXISTS "template_type_idx" ON "template"("type");
|
|
23
|
+
|
|
24
|
+
-- AddForeignKey
|
|
25
|
+
ALTER TABLE "template" ADD CONSTRAINT "template_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
26
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "email_tracking" (
|
|
3
|
+
"id" TEXT NOT NULL,
|
|
4
|
+
"interactionId" TEXT NOT NULL,
|
|
5
|
+
"openCount" INTEGER NOT NULL DEFAULT 0,
|
|
6
|
+
"firstOpenedAt" TIMESTAMP(3),
|
|
7
|
+
"lastOpenedAt" TIMESTAMP(3),
|
|
8
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
9
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
10
|
+
|
|
11
|
+
CONSTRAINT "email_tracking_pkey" PRIMARY KEY ("id")
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
-- CreateIndex
|
|
15
|
+
CREATE UNIQUE INDEX "email_tracking_interactionId_key" ON "email_tracking"("interactionId");
|
|
16
|
+
|
|
17
|
+
-- CreateIndex
|
|
18
|
+
CREATE INDEX "email_tracking_interactionId_idx" ON "email_tracking"("interactionId");
|
|
19
|
+
|
|
20
|
+
-- AddForeignKey
|
|
21
|
+
ALTER TABLE "email_tracking" ADD CONSTRAINT "email_tracking_interactionId_fkey" FOREIGN KEY ("interactionId") REFERENCES "interaction"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- AlterEnum
|
|
2
|
+
-- This migration adds more than one value to an enum.
|
|
3
|
+
-- With PostgreSQL versions 11 and earlier, this is not possible
|
|
4
|
+
-- in a single migration. This can be worked around by creating
|
|
5
|
+
-- multiple migrations, each migration adding only one value to
|
|
6
|
+
-- the enum.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
ALTER TYPE "InteractionType" ADD VALUE 'APPOINTMENT_DELETED';
|
|
10
|
+
ALTER TYPE "InteractionType" ADD VALUE 'APPOINTMENT_CHANGED';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "contact_file" (
|
|
3
|
+
"id" TEXT NOT NULL,
|
|
4
|
+
"contactId" TEXT NOT NULL,
|
|
5
|
+
"fileName" TEXT NOT NULL,
|
|
6
|
+
"fileSize" INTEGER NOT NULL,
|
|
7
|
+
"mimeType" TEXT NOT NULL,
|
|
8
|
+
"googleDriveFileId" TEXT NOT NULL,
|
|
9
|
+
"uploadedById" TEXT NOT NULL,
|
|
10
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
11
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
12
|
+
|
|
13
|
+
CONSTRAINT "contact_file_pkey" PRIMARY KEY ("id")
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
-- CreateIndex
|
|
17
|
+
CREATE INDEX "contact_file_contactId_idx" ON "contact_file"("contactId");
|
|
18
|
+
|
|
19
|
+
-- CreateIndex
|
|
20
|
+
CREATE INDEX "contact_file_uploadedById_idx" ON "contact_file"("uploadedById");
|
|
21
|
+
|
|
22
|
+
-- AddForeignKey
|
|
23
|
+
ALTER TABLE "contact_file" ADD CONSTRAINT "contact_file_contactId_fkey" FOREIGN KEY ("contactId") REFERENCES "contact"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
24
|
+
|
|
25
|
+
-- AddForeignKey
|
|
26
|
+
ALTER TABLE "contact_file" ADD CONSTRAINT "contact_file_uploadedById_fkey" FOREIGN KEY ("uploadedById") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
-- AlterTable
|
|
2
|
+
ALTER TABLE "user" ADD COLUMN "customRoleId" TEXT;
|
|
3
|
+
|
|
4
|
+
-- CreateTable
|
|
5
|
+
CREATE TABLE "custom_role" (
|
|
6
|
+
"id" TEXT NOT NULL,
|
|
7
|
+
"name" TEXT NOT NULL,
|
|
8
|
+
"description" TEXT,
|
|
9
|
+
"permissions" JSONB NOT NULL,
|
|
10
|
+
"isSystem" BOOLEAN NOT NULL DEFAULT false,
|
|
11
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
12
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
13
|
+
|
|
14
|
+
CONSTRAINT "custom_role_pkey" PRIMARY KEY ("id")
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- CreateIndex
|
|
18
|
+
CREATE UNIQUE INDEX "custom_role_name_key" ON "custom_role"("name");
|
|
19
|
+
|
|
20
|
+
-- CreateIndex
|
|
21
|
+
CREATE INDEX "user_customRoleId_idx" ON "user"("customRoleId");
|
|
22
|
+
|
|
23
|
+
-- AddForeignKey
|
|
24
|
+
ALTER TABLE "user" ADD CONSTRAINT "user_customRoleId_fkey" FOREIGN KEY ("customRoleId") REFERENCES "custom_role"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- AlterEnum
|
|
2
|
+
-- This migration adds more than one value to an enum.
|
|
3
|
+
-- With PostgreSQL versions 11 and earlier, this is not possible
|
|
4
|
+
-- in a single migration. This can be worked around by creating
|
|
5
|
+
-- multiple migrations, each migration adding only one value to
|
|
6
|
+
-- the enum.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
ALTER TYPE "InteractionType" ADD VALUE 'FILE_UPLOADED';
|
|
10
|
+
ALTER TYPE "InteractionType" ADD VALUE 'FILE_REPLACED';
|
|
11
|
+
ALTER TYPE "InteractionType" ADD VALUE 'FILE_DELETED';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- AlterTable
|
|
2
|
+
ALTER TABLE "contact" ADD COLUMN "closingReason" TEXT;
|
|
3
|
+
|
|
4
|
+
-- CreateTable
|
|
5
|
+
CREATE TABLE "closing_reason" (
|
|
6
|
+
"id" TEXT NOT NULL,
|
|
7
|
+
"name" TEXT NOT NULL,
|
|
8
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
9
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
10
|
+
|
|
11
|
+
CONSTRAINT "closing_reason_pkey" PRIMARY KEY ("id")
|
|
12
|
+
);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "audit_log" (
|
|
3
|
+
"id" TEXT NOT NULL,
|
|
4
|
+
"actorId" TEXT,
|
|
5
|
+
"targetUserId" TEXT,
|
|
6
|
+
"action" TEXT NOT NULL,
|
|
7
|
+
"entityType" TEXT NOT NULL,
|
|
8
|
+
"entityId" TEXT,
|
|
9
|
+
"metadata" JSONB,
|
|
10
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
11
|
+
|
|
12
|
+
CONSTRAINT "audit_log_pkey" PRIMARY KEY ("id")
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
-- CreateIndex
|
|
16
|
+
CREATE INDEX "audit_log_entityType_entityId_idx" ON "audit_log"("entityType", "entityId");
|
|
17
|
+
|
|
18
|
+
-- CreateIndex
|
|
19
|
+
CREATE INDEX "audit_log_createdAt_idx" ON "audit_log"("createdAt");
|
|
20
|
+
|
|
21
|
+
-- AddForeignKey
|
|
22
|
+
ALTER TABLE "audit_log" ADD CONSTRAINT "audit_log_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
23
|
+
|
|
24
|
+
-- AddForeignKey
|
|
25
|
+
ALTER TABLE "audit_log" ADD CONSTRAINT "audit_log_targetUserId_fkey" FOREIGN KEY ("targetUserId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
-- CreateEnum
|
|
2
|
+
CREATE TYPE "WorkflowTriggerType" AS ENUM ('CONTACT_CREATED', 'STATUS_CHANGED', 'TIME_BASED', 'MANUAL');
|
|
3
|
+
|
|
4
|
+
-- CreateEnum
|
|
5
|
+
CREATE TYPE "WorkflowActionType" AS ENUM ('SEND_EMAIL', 'SEND_SMS', 'CHANGE_STATUS', 'CREATE_TASK', 'WAIT');
|
|
6
|
+
|
|
7
|
+
-- CreateEnum
|
|
8
|
+
CREATE TYPE "WorkflowConditionOperator" AS ENUM ('EQUALS', 'NOT_EQUALS');
|
|
9
|
+
|
|
10
|
+
-- CreateTable
|
|
11
|
+
CREATE TABLE "workflow" (
|
|
12
|
+
"id" TEXT NOT NULL,
|
|
13
|
+
"name" TEXT NOT NULL,
|
|
14
|
+
"description" TEXT,
|
|
15
|
+
"active" BOOLEAN NOT NULL DEFAULT true,
|
|
16
|
+
"userId" TEXT NOT NULL,
|
|
17
|
+
"triggerType" "WorkflowTriggerType" NOT NULL,
|
|
18
|
+
"triggerFromStatusId" TEXT,
|
|
19
|
+
"triggerToStatusId" TEXT,
|
|
20
|
+
"triggerTimeDays" INTEGER,
|
|
21
|
+
"triggerTimeHours" INTEGER,
|
|
22
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
23
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
24
|
+
|
|
25
|
+
CONSTRAINT "workflow_pkey" PRIMARY KEY ("id")
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
-- CreateTable
|
|
29
|
+
CREATE TABLE "workflow_action" (
|
|
30
|
+
"id" TEXT NOT NULL,
|
|
31
|
+
"workflowId" TEXT NOT NULL,
|
|
32
|
+
"actionType" "WorkflowActionType" NOT NULL,
|
|
33
|
+
"order" INTEGER NOT NULL DEFAULT 0,
|
|
34
|
+
"delayDays" INTEGER NOT NULL DEFAULT 0,
|
|
35
|
+
"delayHours" INTEGER NOT NULL DEFAULT 0,
|
|
36
|
+
"emailTemplateId" TEXT,
|
|
37
|
+
"smsMessage" TEXT,
|
|
38
|
+
"newStatusId" TEXT,
|
|
39
|
+
"taskTitle" TEXT,
|
|
40
|
+
"taskDescription" TEXT,
|
|
41
|
+
"conditionOperator" "WorkflowConditionOperator",
|
|
42
|
+
"conditionStatusId" TEXT,
|
|
43
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
44
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
45
|
+
|
|
46
|
+
CONSTRAINT "workflow_action_pkey" PRIMARY KEY ("id")
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
-- CreateIndex
|
|
50
|
+
CREATE INDEX "workflow_userId_idx" ON "workflow"("userId");
|
|
51
|
+
|
|
52
|
+
-- CreateIndex
|
|
53
|
+
CREATE INDEX "workflow_active_idx" ON "workflow"("active");
|
|
54
|
+
|
|
55
|
+
-- CreateIndex
|
|
56
|
+
CREATE INDEX "workflow_action_workflowId_idx" ON "workflow_action"("workflowId");
|
|
57
|
+
|
|
58
|
+
-- CreateIndex
|
|
59
|
+
CREATE INDEX "workflow_action_order_idx" ON "workflow_action"("order");
|
|
60
|
+
|
|
61
|
+
-- AddForeignKey
|
|
62
|
+
ALTER TABLE "workflow" ADD CONSTRAINT "workflow_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
63
|
+
|
|
64
|
+
-- AddForeignKey
|
|
65
|
+
ALTER TABLE "workflow" ADD CONSTRAINT "workflow_triggerFromStatusId_fkey" FOREIGN KEY ("triggerFromStatusId") REFERENCES "status"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
66
|
+
|
|
67
|
+
-- AddForeignKey
|
|
68
|
+
ALTER TABLE "workflow" ADD CONSTRAINT "workflow_triggerToStatusId_fkey" FOREIGN KEY ("triggerToStatusId") REFERENCES "status"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
69
|
+
|
|
70
|
+
-- AddForeignKey
|
|
71
|
+
ALTER TABLE "workflow_action" ADD CONSTRAINT "workflow_action_workflowId_fkey" FOREIGN KEY ("workflowId") REFERENCES "workflow"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
72
|
+
|
|
73
|
+
-- AddForeignKey
|
|
74
|
+
ALTER TABLE "workflow_action" ADD CONSTRAINT "workflow_action_emailTemplateId_fkey" FOREIGN KEY ("emailTemplateId") REFERENCES "template"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
75
|
+
|
|
76
|
+
-- AddForeignKey
|
|
77
|
+
ALTER TABLE "workflow_action" ADD CONSTRAINT "workflow_action_newStatusId_fkey" FOREIGN KEY ("newStatusId") REFERENCES "status"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
78
|
+
|
|
79
|
+
-- AddForeignKey
|
|
80
|
+
ALTER TABLE "workflow_action" ADD CONSTRAINT "workflow_action_conditionStatusId_fkey" FOREIGN KEY ("conditionStatusId") REFERENCES "status"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|