@adaptware/eagles-db 0.4.17 → 0.4.19

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.
@@ -3,49 +3,52 @@ enum ApplicationStatus {
3
3
  PENDING
4
4
  IN_PROGRESS
5
5
  SHORTLISTED
6
+ SELECTED
6
7
  REJECTED
7
8
  }
8
9
 
9
10
  model Application {
10
- id String @id @default(uuid())
11
- candidate_id String
12
- resume_id String
13
- organisation_id String
14
- job_description_id String
15
- fit_check_score Float?
16
- applied_at DateTime @default(now())
17
- evaluation_plan_id String?
18
- fit_check_id String? @unique
19
- round_no Int @default(0)
11
+ id String @id @default(uuid())
12
+ candidate_id String
13
+ resume_id String
14
+ organisation_id String
15
+ job_description_id String
16
+ fit_check_score Float?
17
+ applied_at DateTime @default(now())
18
+ evaluation_plan_id String?
19
+ fit_check_id String? @unique
20
+ round_no Int @default(0)
21
+ is_jaf_completed Boolean @default(false)
20
22
  //Screening fields
21
- on_notice_period Boolean @default(false)
22
- expected_joining_date DateTime?
23
- current_ctc String?
24
- expected_ctc String?
25
- notice_period Int?
26
- preferred_location String?
23
+ on_notice_period Boolean @default(false)
24
+ expected_joining_date DateTime?
25
+ current_ctc String?
26
+ expected_ctc String?
27
+ notice_period Int?
28
+ preferred_location String?
27
29
  // Relations
28
- fit_check_status FitCheckStatus?
29
- status ApplicationStatus @default(PENDING)
30
- evaluation_plan EvaluationPlan? @relation(fields: [evaluation_plan_id], references: [id])
31
- candidate User @relation(fields: [candidate_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
32
- organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
33
- resume Resume @relation(fields: [resume_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
34
- job_description JobDescription @relation(fields: [job_description_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
35
- fit_check FitCheck? @relation(fields: [fit_check_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
36
- interviews Interview[]
37
- assignments Assignment[]
38
- ongoing_evaluations OngoingEvaluation[]
39
- activity_logs ActivityLog[]
40
- notes Notes[]
41
- conversations Conversation[]
42
- communication_messages CommunicationMessage[]
30
+ fit_check_status FitCheckStatus?
31
+ status ApplicationStatus @default(PENDING)
32
+ evaluation_plan EvaluationPlan? @relation(fields: [evaluation_plan_id], references: [id])
33
+ candidate User @relation(fields: [candidate_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
34
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
35
+ resume Resume @relation(fields: [resume_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
36
+ job_description JobDescription @relation(fields: [job_description_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
37
+ fit_check FitCheck? @relation(fields: [fit_check_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
38
+ interviews Interview[]
39
+ assignments Assignment[]
40
+ ongoing_evaluations OngoingEvaluation[]
41
+ activity_logs ActivityLog[]
42
+ notes Notes[]
43
+ job_application_responses JobApplicationResponse[]
44
+ conversations Conversation[]
45
+ communication_messages CommunicationMessage[]
43
46
  // Audit fields
44
- created_at DateTime @default(now())
45
- updated_at DateTime @updatedAt
46
- created_by String
47
- updated_by String
48
- is_active Boolean @default(true)
47
+ created_at DateTime @default(now())
48
+ updated_at DateTime @updatedAt
49
+ created_by String
50
+ updated_by String
51
+ is_active Boolean @default(true)
49
52
 
50
53
  @@unique([candidate_id, job_description_id]) // Ensures candidate applies only once per job
51
54
  @@index([candidate_id])
@@ -17,8 +17,12 @@ model Assignment {
17
17
  feedback Json?
18
18
  status AssignmentStatus @default(AVAILABLE)
19
19
  cancel_reason String?
20
+ /// @deprecated Prefer `solution_document_id` + `Document`.
20
21
  solution_url String?
22
+ /// @deprecated Prefer `zip_document_id` + `Document`.
21
23
  zip_url String?
24
+ solution_document_id String? @unique
25
+ zip_document_id String? @unique
22
26
  scheduled_start_time DateTime?
23
27
  scheduled_end_time DateTime?
24
28
  created_at DateTime @default(now())
@@ -34,6 +38,8 @@ model Assignment {
34
38
  job_description JobDescription @relation(fields: [job_description_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
35
39
  application Application? @relation(fields: [application_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
36
40
  ongoing_evaluation OngoingEvaluation? @relation(fields: [ongoing_evaluation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
41
+ solution_document Document? @relation("AssignmentSolutionDocument", fields: [solution_document_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
42
+ zip_document Document? @relation("AssignmentZipDocument", fields: [zip_document_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
37
43
 
38
44
  @@unique([candidate_id, ongoing_evaluation_id])
39
45
  @@index([candidate_id])
@@ -0,0 +1,37 @@
1
+ model Document {
2
+ // Primary key
3
+ id String @id @default(uuid())
4
+ // Foreign keys
5
+ organisation_id String?
6
+ candidate_id String?
7
+ // Data fields
8
+ original_file_name String
9
+ stored_file_name String
10
+ file_extension String?
11
+ s3_bucket String?
12
+ s3_key String?
13
+ mime_type String?
14
+ file_size BigInt?
15
+ file_hash String?
16
+ metadata Json?
17
+ // Audit fields
18
+ created_at DateTime @default(now())
19
+ updated_at DateTime @updatedAt
20
+ created_by String
21
+ updated_by String
22
+ is_active Boolean @default(true)
23
+ // Relations
24
+ organisation Organisation? @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
25
+ candidate User? @relation(fields: [candidate_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
26
+ resume Resume?
27
+ job_description_source JobDescription?
28
+ interview_recording Interview?
29
+ job_application_responses JobApplicationResponse[]
30
+ assignment_solution Assignment? @relation("AssignmentSolutionDocument")
31
+ assignment_zip Assignment? @relation("AssignmentZipDocument")
32
+
33
+ // Indexes
34
+ @@index([candidate_id])
35
+ @@index([organisation_id, candidate_id])
36
+ @@index([file_hash])
37
+ }
@@ -45,7 +45,9 @@ model Interview {
45
45
  actual_end_time DateTime?
46
46
  /// Interview length in minutes (source of truth; not derived from schedule window).
47
47
  duration Int?
48
+ /// @deprecated Prefer `recording_document_id` + `Document` (type INTERVIEW_RECORDING).
48
49
  recording_url String?
50
+ recording_document_id String? @unique
49
51
  evaluation_type EvaluationType? @default(TREADSPACE_AI_ASSISTED)
50
52
  ai_assistance_mode AiAssistanceMode? @default(ASSISTED)
51
53
  interview_status InterviewStatus @default(SCHEDULED)
@@ -85,6 +87,7 @@ model Interview {
85
87
  candidate User? @relation("CandidateInterviews", fields: [candidate_id], references: [id], onDelete: SetNull)
86
88
  interviewer User? @relation("InterviewerInterviews", fields: [interviewer_id], references: [id], onDelete: SetNull)
87
89
  organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
90
+ recording_document Document? @relation(fields: [recording_document_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
88
91
  job_description JobDescription @relation(fields: [job_description_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
89
92
  resume Resume @relation(fields: [resume_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
90
93
  evaluation_plan EvaluationPlan? @relation(fields: [evaluation_plan_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
@@ -0,0 +1,37 @@
1
+ enum JobApplicationFieldType {
2
+ TEXT
3
+ NUMBER
4
+ DATE
5
+ BOOLEAN
6
+ MULTI_SELECT
7
+ FILE
8
+ DROP_DOWN
9
+ }
10
+
11
+ model JobApplicationField {
12
+ /// Primary key (UUID)
13
+ id String @id @default(uuid())
14
+ /// Foreign keys
15
+ organisation_id String
16
+ template_id String
17
+ /// Data fields
18
+ field_type JobApplicationFieldType
19
+ label String
20
+ description String?
21
+ is_mandatory Boolean @default(false)
22
+ is_draft Boolean @default(true)
23
+ options String[]
24
+ /// Audit fields
25
+ is_active Boolean @default(true)
26
+ created_by String
27
+ updated_by String
28
+ created_at DateTime @default(now())
29
+ updated_at DateTime @updatedAt
30
+ /// Relations
31
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
32
+ job_application_template JobApplicationTemplate @relation(fields: [template_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
33
+ job_application_responses JobApplicationResponse[]
34
+
35
+ /// Indexes
36
+ @@index([organisation_id, template_id])
37
+ }
@@ -0,0 +1,33 @@
1
+ model JobApplicationResponse {
2
+ /// Primary key
3
+ id String @id @default(uuid())
4
+ /// Foreign keys
5
+ application_id String
6
+ job_application_field_id String?
7
+ document_id String?
8
+ /// Answer payload
9
+ response Json?
10
+ /// Denormalized question snapshot (immutable on candidate save)
11
+ field_type JobApplicationFieldType?
12
+ label String?
13
+ description String?
14
+ is_mandatory Boolean?
15
+ is_draft Boolean?
16
+ is_submitted Boolean @default(false)
17
+ options String[]
18
+ updated_by_organisation Boolean @default(false)
19
+ /// Audit fields
20
+ created_at DateTime @default(now())
21
+ updated_at DateTime @updatedAt
22
+ created_by String
23
+ updated_by String
24
+ is_active Boolean @default(true)
25
+ /// Relations
26
+ application Application @relation(fields: [application_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
27
+ field JobApplicationField? @relation(fields: [job_application_field_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
28
+ document Document? @relation(fields: [document_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
29
+
30
+ /// Partial unique on (application_id, job_application_field_id) WHERE job_application_field_id IS NOT NULL — see migration SQL
31
+ @@index([application_id])
32
+ @@index([job_application_field_id])
33
+ }
@@ -0,0 +1,30 @@
1
+ enum JobApplicationTemplateScope {
2
+ ORGANIZATION
3
+ JOB
4
+ }
5
+
6
+ model JobApplicationTemplate {
7
+ /// Primary key
8
+ id String @id @default(uuid())
9
+ /// Foreign keys
10
+ organisation_id String
11
+ job_description_id String? @unique
12
+ /// Data fields
13
+ name String
14
+ description String?
15
+ scope JobApplicationTemplateScope @default(ORGANIZATION)
16
+ /// Audit fields
17
+ is_active Boolean @default(true)
18
+ created_by String
19
+ updated_by String
20
+ created_at DateTime @default(now())
21
+ updated_at DateTime @updatedAt
22
+ /// Relations
23
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
24
+ job_description JobDescription? @relation(fields: [job_description_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
25
+ fields JobApplicationField[]
26
+
27
+ /// Indexes
28
+ @@index([organisation_id, scope])
29
+ @@index([job_description_id])
30
+ }
@@ -7,28 +7,31 @@ enum JobDescriptionStatus {
7
7
  }
8
8
 
9
9
  model JobDescription {
10
- id String @id @default(uuid())
10
+ id String @id @default(uuid())
11
11
  organisation_id String
12
12
  hiring_manager_id String?
13
- status JobDescriptionStatus @default(DRAFT)
13
+ status JobDescriptionStatus @default(DRAFT)
14
14
  screeningQuestions String[]
15
15
  recommendedQuestions Json[]
16
+ /// @deprecated Prefer `source_document_id` + `Document` (type JOB_DESCRIPTION).
16
17
  uploaded_job_description_path String?
17
- is_plan_published Boolean @default(false)
18
- is_posted Boolean @default(false)
18
+ source_document_id String? @unique
19
+ is_plan_published Boolean @default(false)
20
+ is_posted Boolean @default(false)
19
21
  summary Json?
20
22
  ai_insight Json?
21
23
  job_fit_comparison Json?
22
24
  // Audit fields
23
- created_at DateTime @default(now())
24
- updated_at DateTime @updatedAt
25
+ created_at DateTime @default(now())
26
+ updated_at DateTime @updatedAt
25
27
  created_by String
26
28
  updated_by String
27
- is_active Boolean @default(true)
28
- openings Int @default(1)
29
+ is_active Boolean @default(true)
30
+ openings Int @default(1)
29
31
  job_profile_id String?
30
- job_profile JobProfile? @relation(fields: [job_profile_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
31
- organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
32
+ job_profile JobProfile? @relation(fields: [job_profile_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
33
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
34
+ source_document Document? @relation(fields: [source_document_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
32
35
  applications Application[]
33
36
  interviews Interview[]
34
37
  assignments Assignment[]
@@ -40,10 +43,11 @@ model JobDescription {
40
43
  approvals Approval[] // one-to-many relation
41
44
  resumes Resume[] // one-to-many link
42
45
  budget Budget?
43
- hiring_manager User? @relation("HiringManager", fields: [hiring_manager_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
46
+ hiring_manager User? @relation("HiringManager", fields: [hiring_manager_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
44
47
  recruiters User[]
45
48
  transcripts Transcript[]
46
49
  integration_job_syncs IntegrationJobSync[]
50
+ job_application_template JobApplicationTemplate?
47
51
  conversations Conversation[]
48
52
  communication_messages CommunicationMessage[]
49
53
 
@@ -0,0 +1,84 @@
1
+ -- CreateSchema
2
+ CREATE SCHEMA IF NOT EXISTS "analytics";
3
+
4
+ -- CreateEnum
5
+ CREATE TYPE "analytics"."RoundResult" AS ENUM ('PASSED', 'FAILED');
6
+
7
+ -- CreateTable
8
+ CREATE TABLE "analytics"."round_analytics" (
9
+ "id" TEXT NOT NULL,
10
+ "organisation_id" TEXT NOT NULL,
11
+ "application_id" TEXT NOT NULL,
12
+ "candidate_id" TEXT NOT NULL,
13
+ "job_description_id" TEXT NOT NULL,
14
+ "evaluation_plan_id" TEXT NOT NULL,
15
+ "round_id" TEXT NOT NULL,
16
+ "round_name" TEXT,
17
+ "evaluation_category" "EvaluationCategory",
18
+ "round_type" "RoundType",
19
+ "assigned_at" TIMESTAMP(3),
20
+ "interview_created_at" TIMESTAMP(3),
21
+ "interview_scheduled_at" TIMESTAMP(3),
22
+ "interview_started_at" TIMESTAMP(3),
23
+ "interview_completed_at" TIMESTAMP(3),
24
+ "interview_evaluated_at" TIMESTAMP(3),
25
+ "round_completed_at" TIMESTAMP(3),
26
+ "round_result" "analytics"."RoundResult",
27
+ "round_result_at" TIMESTAMP(3),
28
+ "scheduling_duration_minutes" INTEGER,
29
+ "interview_duration_minutes" INTEGER,
30
+ "feedback_duration_minutes" INTEGER,
31
+ "decision_duration_minutes" INTEGER,
32
+ "total_round_duration_minutes" INTEGER,
33
+ "is_custom" BOOLEAN NOT NULL DEFAULT false,
34
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
35
+ "updated_at" TIMESTAMP(3) NOT NULL,
36
+
37
+ CONSTRAINT "round_analytics_pkey" PRIMARY KEY ("id")
38
+ );
39
+
40
+ -- CreateTable
41
+ CREATE TABLE "analytics"."job_round_analytics" (
42
+ "id" TEXT NOT NULL,
43
+ "organisation_id" TEXT NOT NULL,
44
+ "job_description_id" TEXT NOT NULL,
45
+ "evaluation_plan_id" TEXT NOT NULL,
46
+ "round_name" TEXT NOT NULL,
47
+ "evaluation_category" "EvaluationCategory",
48
+ "is_custom" BOOLEAN NOT NULL DEFAULT false,
49
+ "assigned_count" INTEGER NOT NULL DEFAULT 0,
50
+ "completed_count" INTEGER NOT NULL DEFAULT 0,
51
+ "passed_count" INTEGER NOT NULL DEFAULT 0,
52
+ "failed_count" INTEGER NOT NULL DEFAULT 0,
53
+ "withdrawn_count" INTEGER NOT NULL DEFAULT 0,
54
+ "no_show_count" INTEGER NOT NULL DEFAULT 0,
55
+ "total_completion_minutes" BIGINT NOT NULL DEFAULT 0,
56
+ "avg_completion_minutes" DOUBLE PRECISION,
57
+ "updated_at" TIMESTAMP(3) NOT NULL,
58
+
59
+ CONSTRAINT "job_round_analytics_pkey" PRIMARY KEY ("id")
60
+ );
61
+
62
+ -- CreateIndex
63
+ CREATE UNIQUE INDEX "round_analytics_round_id_key" ON "analytics"."round_analytics"("round_id");
64
+
65
+ -- CreateIndex
66
+ CREATE INDEX "round_analytics_organisation_id_idx" ON "analytics"."round_analytics"("organisation_id");
67
+
68
+ -- CreateIndex
69
+ CREATE INDEX "round_analytics_job_description_id_idx" ON "analytics"."round_analytics"("job_description_id");
70
+
71
+ -- CreateIndex
72
+ CREATE INDEX "round_analytics_application_id_idx" ON "analytics"."round_analytics"("application_id");
73
+
74
+ -- CreateIndex
75
+ CREATE INDEX "round_analytics_candidate_id_idx" ON "analytics"."round_analytics"("candidate_id");
76
+
77
+ -- CreateIndex
78
+ CREATE INDEX "round_analytics_evaluation_category_idx" ON "analytics"."round_analytics"("evaluation_category");
79
+
80
+ -- CreateIndex
81
+ CREATE INDEX "round_analytics_round_result_idx" ON "analytics"."round_analytics"("round_result");
82
+
83
+ -- CreateIndex
84
+ CREATE UNIQUE INDEX "job_round_analytics_job_description_id_evaluation_plan_id_key" ON "analytics"."job_round_analytics"("job_description_id", "evaluation_plan_id");
@@ -18,33 +18,36 @@ model Organisation {
18
18
  company_values Json[]
19
19
  allowed_email_domains String[]
20
20
 
21
- interviewers User[]
22
- created_at DateTime @default(now())
23
- updated_at DateTime @updatedAt
24
- created_by String
25
- updated_by String
26
- is_active Boolean @default(true)
27
- alias String? @unique
28
- logo String?
29
- applications Application[]
30
- user_roles UserRole[]
31
- job_descriptions JobDescription[]
32
- job_profiles JobProfile[]
33
- assessment_library AssessmentLibrary[]
34
- assignment_library AssignmentLibrary[]
35
- interviews Interview[]
36
- assignments Assignment[]
37
- fit_check FitCheck[] // one-to-many link
38
- resumes Resume[] // one-to-many link
39
- approvals Approval[] // one-to-many link
40
- suggestions Suggestion[]
41
- ongoing_evaluations OngoingEvaluation[] // optional one-to-many
42
- actions Action[]
43
- integration_credentials IntegrationCredential[]
44
- zoho_sync_mappings ZohoSyncMapping[]
45
- assessments Assessment[]
46
- timezone String @default("Asia/Kolkata")
47
- organisation_configs OrganisationConfig[]
21
+ interviewers User[]
22
+ created_at DateTime @default(now())
23
+ updated_at DateTime @updatedAt
24
+ created_by String
25
+ updated_by String
26
+ is_active Boolean @default(true)
27
+ alias String? @unique
28
+ logo String?
29
+ applications Application[]
30
+ user_roles UserRole[]
31
+ job_descriptions JobDescription[]
32
+ job_profiles JobProfile[]
33
+ assessment_library AssessmentLibrary[]
34
+ assignment_library AssignmentLibrary[]
35
+ interviews Interview[]
36
+ assignments Assignment[]
37
+ fit_check FitCheck[] // one-to-many link
38
+ resumes Resume[] // one-to-many link
39
+ approvals Approval[] // one-to-many link
40
+ suggestions Suggestion[]
41
+ ongoing_evaluations OngoingEvaluation[] // optional one-to-many
42
+ actions Action[]
43
+ integration_credentials IntegrationCredential[]
44
+ zoho_sync_mappings ZohoSyncMapping[]
45
+ assessments Assessment[]
46
+ timezone String @default("Asia/Kolkata")
47
+ organisation_configs OrganisationConfig[]
48
+ job_application_fields JobApplicationField[]
49
+ documents Document[]
50
+ job_application_templates JobApplicationTemplate[]
48
51
 
49
52
  channel_provider_configs ChannelProviderConfig[]
50
53
  conversations Conversation[]
@@ -3,8 +3,11 @@ model Resume {
3
3
  user_id String?
4
4
  organisation_id String?
5
5
  job_description_id String?
6
+ /// @deprecated Prefer `document_id` + `Document`. Kept until backfill completes.
6
7
  uploaded_resume_path String?
7
- file_hash String? @unique
8
+ document_id String? @unique
9
+ /// @deprecated Prefer `Document.file_hash`. Kept for legacy read fallback.
10
+ file_hash String?
8
11
  summary Json?
9
12
  created_at DateTime @default(now())
10
13
  updated_at DateTime @updatedAt
@@ -15,6 +18,7 @@ model Resume {
15
18
  user User? @relation(fields: [user_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
16
19
  organisation Organisation? @relation(fields: [organisation_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
17
20
  job_description JobDescription? @relation(fields: [job_description_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
21
+ document Document? @relation(fields: [document_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
18
22
  applications Application[]
19
23
  interviews Interview[]
20
24
  ongoing_evaluations OngoingEvaluation[] // optional one-to-many
@@ -85,6 +85,7 @@ model User {
85
85
  veteran_status String?
86
86
  disability_status String?
87
87
  professional_expertise String?
88
+ documents Document[]
88
89
 
89
90
  @@index([role_id])
90
91
  @@index([permission_id])
@@ -1,131 +0,0 @@
1
- -- CreateEnum
2
- CREATE TYPE "CommChannel" AS ENUM ('WHATSAPP', 'EMAIL', 'SMS', 'CALL');
3
-
4
- -- CreateEnum
5
- CREATE TYPE "CommProvider" AS ENUM ('META_WHATSAPP', 'TWILIO', 'GUPSHUP', 'MTALKZ', 'THREE_SIXTY_DIALOG', 'GMAIL', 'OUTLOOK', 'GENERIC_SMTP', 'GENERIC');
6
-
7
- -- CreateEnum
8
- CREATE TYPE "CommDirection" AS ENUM ('INBOUND', 'OUTBOUND');
9
-
10
- -- CreateEnum
11
- CREATE TYPE "CommMessageStatus" AS ENUM ('QUEUED', 'SENT', 'DELIVERED', 'READ', 'FAILED', 'RECEIVED');
12
-
13
- -- CreateTable
14
- CREATE TABLE "ChannelProviderConfig" (
15
- "id" TEXT NOT NULL,
16
- "organisation_id" TEXT NOT NULL,
17
- "channel" "CommChannel" NOT NULL,
18
- "provider" "CommProvider" NOT NULL,
19
- "credentials" TEXT,
20
- "metadata" JSONB NOT NULL DEFAULT '{}',
21
- "is_active" BOOLEAN NOT NULL DEFAULT true,
22
- "is_default" BOOLEAN NOT NULL DEFAULT true,
23
- "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
24
- "updated_at" TIMESTAMP(3) NOT NULL,
25
- "created_by" TEXT NOT NULL,
26
- "updated_by" TEXT NOT NULL,
27
-
28
- CONSTRAINT "ChannelProviderConfig_pkey" PRIMARY KEY ("id")
29
- );
30
-
31
- -- CreateTable
32
- CREATE TABLE "Conversation" (
33
- "id" TEXT NOT NULL,
34
- "organisation_id" TEXT NOT NULL,
35
- "channel" "CommChannel" NOT NULL,
36
- "provider" "CommProvider" NOT NULL,
37
- "channel_provider_id" TEXT,
38
- "external_id" TEXT NOT NULL,
39
- "contact_user_id" TEXT,
40
- "provider_thread_id" TEXT,
41
- "subject" TEXT,
42
- "status" TEXT NOT NULL DEFAULT 'open',
43
- "unread_count" INTEGER NOT NULL DEFAULT 0,
44
- "last_message_at" TIMESTAMP(3),
45
- "metadata" JSONB NOT NULL DEFAULT '{}',
46
- "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
47
- "updated_at" TIMESTAMP(3) NOT NULL,
48
- "created_by" TEXT NOT NULL,
49
- "updated_by" TEXT NOT NULL,
50
-
51
- CONSTRAINT "Conversation_pkey" PRIMARY KEY ("id")
52
- );
53
-
54
- -- CreateTable
55
- CREATE TABLE "CommunicationMessage" (
56
- "id" TEXT NOT NULL,
57
- "conversation_id" TEXT NOT NULL,
58
- "organisation_id" TEXT NOT NULL,
59
- "channel" "CommChannel" NOT NULL,
60
- "provider" "CommProvider" NOT NULL,
61
- "channel_provider_id" TEXT,
62
- "direction" "CommDirection" NOT NULL,
63
- "status" "CommMessageStatus" NOT NULL,
64
- "body" TEXT,
65
- "from_identifier" TEXT NOT NULL,
66
- "to_identifier" TEXT NOT NULL,
67
- "sender_user_id" TEXT,
68
- "provider_message_id" TEXT,
69
- "template_name" TEXT,
70
- "attachments" JSONB NOT NULL DEFAULT '[]',
71
- "metadata" JSONB NOT NULL DEFAULT '{}',
72
- "error" TEXT,
73
- "sent_at" TIMESTAMP(3),
74
- "delivered_at" TIMESTAMP(3),
75
- "read_at" TIMESTAMP(3),
76
- "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
77
- "updated_at" TIMESTAMP(3) NOT NULL,
78
-
79
- CONSTRAINT "CommunicationMessage_pkey" PRIMARY KEY ("id")
80
- );
81
-
82
- -- CreateIndex
83
- CREATE UNIQUE INDEX "ChannelProviderConfig_organisation_id_channel_provider_key" ON "ChannelProviderConfig"("organisation_id", "channel", "provider");
84
-
85
- -- CreateIndex
86
- CREATE INDEX "ChannelProviderConfig_organisation_id_channel_idx" ON "ChannelProviderConfig"("organisation_id", "channel");
87
-
88
- -- CreateIndex
89
- CREATE INDEX "ChannelProviderConfig_organisation_id_channel_is_active_idx" ON "ChannelProviderConfig"("organisation_id", "channel", "is_active");
90
-
91
- -- CreateIndex
92
- CREATE UNIQUE INDEX "Conversation_organisation_id_channel_provider_external_id_key" ON "Conversation"("organisation_id", "channel", "provider", "external_id");
93
-
94
- -- CreateIndex
95
- CREATE INDEX "Conversation_organisation_id_channel_idx" ON "Conversation"("organisation_id", "channel");
96
-
97
- -- CreateIndex
98
- CREATE INDEX "Conversation_organisation_id_last_message_at_idx" ON "Conversation"("organisation_id", "last_message_at");
99
-
100
- -- CreateIndex
101
- CREATE INDEX "Conversation_external_id_idx" ON "Conversation"("external_id");
102
-
103
- -- CreateIndex
104
- CREATE UNIQUE INDEX "CommunicationMessage_provider_provider_message_id_key" ON "CommunicationMessage"("provider", "provider_message_id");
105
-
106
- -- CreateIndex
107
- CREATE INDEX "CommunicationMessage_conversation_id_created_at_idx" ON "CommunicationMessage"("conversation_id", "created_at");
108
-
109
- -- CreateIndex
110
- CREATE INDEX "CommunicationMessage_organisation_id_channel_created_at_idx" ON "CommunicationMessage"("organisation_id", "channel", "created_at");
111
-
112
- -- CreateIndex
113
- CREATE INDEX "CommunicationMessage_organisation_id_status_idx" ON "CommunicationMessage"("organisation_id", "status");
114
-
115
- -- AddForeignKey
116
- ALTER TABLE "ChannelProviderConfig" ADD CONSTRAINT "ChannelProviderConfig_organisation_id_fkey" FOREIGN KEY ("organisation_id") REFERENCES "Organisation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
117
-
118
- -- AddForeignKey
119
- ALTER TABLE "Conversation" ADD CONSTRAINT "Conversation_organisation_id_fkey" FOREIGN KEY ("organisation_id") REFERENCES "Organisation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
120
-
121
- -- AddForeignKey
122
- ALTER TABLE "Conversation" ADD CONSTRAINT "Conversation_channel_provider_id_fkey" FOREIGN KEY ("channel_provider_id") REFERENCES "ChannelProviderConfig"("id") ON DELETE SET NULL ON UPDATE CASCADE;
123
-
124
- -- AddForeignKey
125
- ALTER TABLE "CommunicationMessage" ADD CONSTRAINT "CommunicationMessage_conversation_id_fkey" FOREIGN KEY ("conversation_id") REFERENCES "Conversation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
126
-
127
- -- AddForeignKey
128
- ALTER TABLE "CommunicationMessage" ADD CONSTRAINT "CommunicationMessage_organisation_id_fkey" FOREIGN KEY ("organisation_id") REFERENCES "Organisation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
129
-
130
- -- AddForeignKey
131
- ALTER TABLE "CommunicationMessage" ADD CONSTRAINT "CommunicationMessage_channel_provider_id_fkey" FOREIGN KEY ("channel_provider_id") REFERENCES "ChannelProviderConfig"("id") ON DELETE SET NULL ON UPDATE CASCADE;