procbay-schema 1.0.165 → 1.0.169

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "procbay-schema",
3
- "version": "1.0.165",
3
+ "version": "1.0.169",
4
4
  "description": "A set of utilities for managing Prisma database schemas, seeding, and maintenance operations for the Procure-to-Pay system",
5
5
  "main": "src/prisma/index.js",
6
6
  "type": "module",
@@ -0,0 +1,55 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the `user_approval_management` table. If the table is not empty, all the data it contains will be lost.
5
+
6
+ */
7
+ -- CreateEnum
8
+ CREATE TYPE "ApprovalManagementStatusEnum" AS ENUM ('PENDING', 'APPROVED', 'REJECTED');
9
+
10
+ -- DropForeignKey
11
+ ALTER TABLE "user_approval_management" DROP CONSTRAINT "user_approval_management_user_id_fkey";
12
+
13
+ -- DropTable
14
+ DROP TABLE "user_approval_management";
15
+
16
+ -- DropEnum
17
+ DROP TYPE "UserApprovalManagementStatusEnum";
18
+
19
+ -- CreateTable
20
+ CREATE TABLE "approval_management" (
21
+ "id" SERIAL NOT NULL,
22
+ "uuid" TEXT NOT NULL,
23
+ "journy_type" TEXT,
24
+ "journey_task" TEXT,
25
+ "parent_id" TEXT,
26
+ "user_id" INTEGER,
27
+ "proposed_payload" JSONB,
28
+ "previous_snapshot" JSONB,
29
+ "estimated_budget" DECIMAL(18,2),
30
+ "batch_id" TEXT,
31
+ "request_status" "ApprovalManagementStatusEnum" NOT NULL DEFAULT 'PENDING',
32
+ "reject_reason" TEXT,
33
+ "created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
34
+ "created_by" INTEGER,
35
+
36
+ CONSTRAINT "approval_management_pkey" PRIMARY KEY ("id")
37
+ );
38
+
39
+ -- CreateIndex
40
+ CREATE UNIQUE INDEX "approval_management_uuid_key" ON "approval_management"("uuid");
41
+
42
+ -- CreateIndex
43
+ CREATE INDEX "approval_management_parent_id_idx" ON "approval_management"("parent_id");
44
+
45
+ -- CreateIndex
46
+ CREATE INDEX "approval_management_journy_type_journey_task_idx" ON "approval_management"("journy_type", "journey_task");
47
+
48
+ -- CreateIndex
49
+ CREATE INDEX "approval_management_batch_id_idx" ON "approval_management"("batch_id");
50
+
51
+ -- CreateIndex
52
+ CREATE INDEX "approval_management_request_status_idx" ON "approval_management"("request_status");
53
+
54
+ -- AddForeignKey
55
+ ALTER TABLE "approval_management" ADD CONSTRAINT "approval_management_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,55 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the `user_approval_management` table. If the table is not empty, all the data it contains will be lost.
5
+
6
+ */
7
+ -- CreateEnum
8
+ CREATE TYPE "ApprovalManagementStatusEnum" AS ENUM ('PENDING', 'APPROVED', 'REJECTED');
9
+
10
+ -- DropForeignKey
11
+ ALTER TABLE "user_approval_management" DROP CONSTRAINT "user_approval_management_user_id_fkey";
12
+
13
+ -- DropTable
14
+ DROP TABLE "user_approval_management";
15
+
16
+ -- DropEnum
17
+ DROP TYPE "UserApprovalManagementStatusEnum";
18
+
19
+ -- CreateTable
20
+ CREATE TABLE "approval_management" (
21
+ "id" SERIAL NOT NULL,
22
+ "uuid" TEXT NOT NULL,
23
+ "journy_type" TEXT,
24
+ "journey_task" TEXT,
25
+ "parent_id" TEXT,
26
+ "user_id" INTEGER,
27
+ "proposed_payload" JSONB,
28
+ "previous_snapshot" JSONB,
29
+ "estimated_budget" DECIMAL(18,2),
30
+ "batch_id" TEXT,
31
+ "request_status" "ApprovalManagementStatusEnum" NOT NULL DEFAULT 'PENDING',
32
+ "reject_reason" TEXT,
33
+ "created_at" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
34
+ "created_by" INTEGER,
35
+
36
+ CONSTRAINT "approval_management_pkey" PRIMARY KEY ("id")
37
+ );
38
+
39
+ -- CreateIndex
40
+ CREATE UNIQUE INDEX "approval_management_uuid_key" ON "approval_management"("uuid");
41
+
42
+ -- CreateIndex
43
+ CREATE INDEX "approval_management_parent_id_idx" ON "approval_management"("parent_id");
44
+
45
+ -- CreateIndex
46
+ CREATE INDEX "approval_management_journy_type_journey_task_idx" ON "approval_management"("journy_type", "journey_task");
47
+
48
+ -- CreateIndex
49
+ CREATE INDEX "approval_management_batch_id_idx" ON "approval_management"("batch_id");
50
+
51
+ -- CreateIndex
52
+ CREATE INDEX "approval_management_request_status_idx" ON "approval_management"("request_status");
53
+
54
+ -- AddForeignKey
55
+ ALTER TABLE "approval_management" ADD CONSTRAINT "approval_management_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -123,7 +123,7 @@ model User {
123
123
  message_recipients MessageRecipient[] @relation("MessageRecipientUser")
124
124
  blanket_po BlanketPurchaseOrder[]
125
125
  purchase_intake_initiated_by PurchaseIntake[] @relation("purchase_intake_initiated_by")
126
- user_approval_managements UserApprovalManagement[]
126
+ approval_management ApprovalManagement[]
127
127
 
128
128
  @@map("users")
129
129
  }
@@ -319,30 +319,30 @@ model Industry {
319
319
 
320
320
  //---------------------------------- CATEGORY MODEL START ----------------------------------
321
321
  model Category {
322
- id Int @id @default(autoincrement())
323
- uuid String? @unique @default(uuid())
324
- industry_id Int?
325
- industry Industry? @relation(fields: [industry_id], references: [id])
326
- name String? @unique
327
- slug String?
328
- is_active Boolean @default(true)
329
- parent_id Int @default(0)
330
- description String?
331
- image_url String?
332
- created_by Int?
333
- created_at DateTime @default(now()) @db.Timestamptz(6)
334
- updated_by Int?
335
- updated_at DateTime @updatedAt @db.Timestamptz(6)
336
- is_deleted Boolean @default(false)
337
- deleted_by Int?
338
- deleted_at DateTime? @db.Timestamptz(6)
339
- attributes Attribute[]
340
- category_uom UomCategory[]
341
- category_budget CategoryBudget[]
342
- item_category Item[] @relation("ItemCategory")
343
- item_sub_category Item[] @relation("ItemSubCategory")
344
- boq_event_items_as_category BoqEventItem[] @relation("CategoryBoqEventItemAsCategory")
345
- boq_event_items_as_sub_category BoqEventItem[] @relation("SubCategoryBoqEventItemAsSubCategory")
322
+ id Int @id @default(autoincrement())
323
+ uuid String? @unique @default(uuid())
324
+ industry_id Int?
325
+ industry Industry? @relation(fields: [industry_id], references: [id])
326
+ name String? @unique
327
+ slug String?
328
+ is_active Boolean @default(true)
329
+ parent_id Int @default(0)
330
+ description String?
331
+ image_url String?
332
+ created_by Int?
333
+ created_at DateTime @default(now()) @db.Timestamptz(6)
334
+ updated_by Int?
335
+ updated_at DateTime @updatedAt @db.Timestamptz(6)
336
+ is_deleted Boolean @default(false)
337
+ deleted_by Int?
338
+ deleted_at DateTime? @db.Timestamptz(6)
339
+ attributes Attribute[]
340
+ category_uom UomCategory[]
341
+ category_budget CategoryBudget[]
342
+ item_category Item[] @relation("ItemCategory")
343
+ item_sub_category Item[] @relation("ItemSubCategory")
344
+ boq_event_items_as_category BoqEventItem[] @relation("CategoryBoqEventItemAsCategory")
345
+ boq_event_items_as_sub_category BoqEventItem[] @relation("SubCategoryBoqEventItemAsSubCategory")
346
346
 
347
347
  @@map("categories")
348
348
  }
@@ -670,7 +670,7 @@ model EmailTemplate {
670
670
  subject String?
671
671
  html_content String?
672
672
  macro String?
673
- module_name String?
673
+ module_name String?
674
674
  is_active Boolean? @default(true)
675
675
  is_deleted Boolean? @default(false)
676
676
  created_at DateTime? @default(now()) @db.Timestamptz(6)
@@ -1366,46 +1366,45 @@ model EventItems {
1366
1366
  //---------------------------------- BOQ EVENT ITEMS MODEL START ------------------------------------------------
1367
1367
  /// BOQ lines for events without item-master linkage (free-text / JSON fields), parallel to Sourcebay-style event items.
1368
1368
  model BoqEventItem {
1369
- id Int @id @default(autoincrement())
1370
- uuid String? @unique @default(uuid())
1371
- category_id Int?
1372
- category Category? @relation("CategoryBoqEventItemAsCategory",fields: [category_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1373
- sub_category_id Int?
1374
- sub_category Category? @relation("SubCategoryBoqEventItemAsSubCategory",fields: [sub_category_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1375
- event_id Int?
1376
- event Event? @relation(fields: [event_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1377
- part_name String?
1378
- description String? @db.Text
1379
- part_no String?
1380
- quantity Decimal? @db.Decimal(18, 4)
1381
- uom String?
1382
- dynamic_fields Json?
1383
- version Int @default(1)
1369
+ id Int @id @default(autoincrement())
1370
+ uuid String? @unique @default(uuid())
1371
+ category_id Int?
1372
+ category Category? @relation("CategoryBoqEventItemAsCategory", fields: [category_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1373
+ sub_category_id Int?
1374
+ sub_category Category? @relation("SubCategoryBoqEventItemAsSubCategory", fields: [sub_category_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1375
+ event_id Int?
1376
+ event Event? @relation(fields: [event_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1377
+ part_name String?
1378
+ description String? @db.Text
1379
+ part_no String?
1380
+ quantity Decimal? @db.Decimal(18, 4)
1381
+ uom String?
1382
+ dynamic_fields Json?
1383
+ version Int @default(1)
1384
1384
  parent_version_id Int?
1385
- parent_version BoqEventItem? @relation("BoqEventItemVersionRelation",fields: [parent_version_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1386
- sort_order Int @default(0)
1387
- is_active Boolean? @default(true)
1388
- created_at DateTime? @default(now()) @db.Timestamptz(6)
1389
- created_by Int?
1390
- updated_at DateTime? @updatedAt @db.Timestamptz(6)
1391
- updated_by Int?
1392
- is_deleted Boolean? @default(false)
1393
- deleted_at DateTime? @db.Timestamptz(6)
1394
- deleted_by Int?
1395
-
1396
- bids Bid[]
1397
- bid_logs BidLog[]
1398
- quotations Quotation[]
1399
- quotation_logs QuotationLog[]
1385
+ parent_version BoqEventItem? @relation("BoqEventItemVersionRelation", fields: [parent_version_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1386
+ sort_order Int @default(0)
1387
+ is_active Boolean? @default(true)
1388
+ created_at DateTime? @default(now()) @db.Timestamptz(6)
1389
+ created_by Int?
1390
+ updated_at DateTime? @updatedAt @db.Timestamptz(6)
1391
+ updated_by Int?
1392
+ is_deleted Boolean? @default(false)
1393
+ deleted_at DateTime? @db.Timestamptz(6)
1394
+ deleted_by Int?
1395
+
1396
+ bids Bid[]
1397
+ bid_logs BidLog[]
1398
+ quotations Quotation[]
1399
+ quotation_logs QuotationLog[]
1400
1400
  purchase_order_items PurchaseOrderItem[]
1401
- boq_event_items BoqEventItem[] @relation("BoqEventItemVersionRelation")
1401
+ boq_event_items BoqEventItem[] @relation("BoqEventItemVersionRelation")
1402
1402
 
1403
1403
  @@index([event_id])
1404
1404
  @@map("boq_event_items")
1405
1405
  }
1406
1406
 
1407
1407
  //---------------------------------- BOQ EVENT ITEMS MODEL END ------------------------------------------------
1408
-
1409
1408
 
1410
1409
  //---------------------------------- VENDOR EVENTS MODEL START ------------------------------------------------
1411
1410
 
@@ -1802,28 +1801,28 @@ enum BidStatus {
1802
1801
  }
1803
1802
 
1804
1803
  model Bid {
1805
- id Int @id @default(autoincrement())
1806
- uuid String? @unique @default(uuid())
1807
- event_id Int?
1808
- event Event? @relation(fields: [event_id], references: [id], onDelete: Cascade)
1809
- event_item_id Int?
1810
- event_item EventItems? @relation(fields: [event_item_id], references: [id], onDelete: Cascade)
1804
+ id Int @id @default(autoincrement())
1805
+ uuid String? @unique @default(uuid())
1806
+ event_id Int?
1807
+ event Event? @relation(fields: [event_id], references: [id], onDelete: Cascade)
1808
+ event_item_id Int?
1809
+ event_item EventItems? @relation(fields: [event_item_id], references: [id], onDelete: Cascade)
1811
1810
  boq_event_item_id Int?
1812
- boq_event_item BoqEventItem? @relation(fields: [boq_event_item_id], references: [id], onDelete: Cascade)
1813
- event_type EventType?
1814
- event_vendor_id Int?
1815
- event_vendor EventVendors? @relation(fields: [event_vendor_id], references: [id], onDelete: Cascade)
1816
- bid_log_id Int? // Reference to BidLog for detailed bid history
1817
- bid_log BidLog? @relation(fields: [bid_log_id], references: [id], onDelete: Cascade)
1818
- bid_amount Float?
1819
- version Int @default(0) // For optimistic locking
1820
- created_at DateTime @default(now()) @db.Timestamptz(6)
1821
- created_by Int?
1822
- updated_at DateTime @updatedAt @db.Timestamptz(6)
1823
- updated_by Int?
1824
- is_deleted Boolean @default(false)
1825
- deleted_at DateTime? @db.Timestamptz(6)
1826
- deleted_by Int?
1811
+ boq_event_item BoqEventItem? @relation(fields: [boq_event_item_id], references: [id], onDelete: Cascade)
1812
+ event_type EventType?
1813
+ event_vendor_id Int?
1814
+ event_vendor EventVendors? @relation(fields: [event_vendor_id], references: [id], onDelete: Cascade)
1815
+ bid_log_id Int? // Reference to BidLog for detailed bid history
1816
+ bid_log BidLog? @relation(fields: [bid_log_id], references: [id], onDelete: Cascade)
1817
+ bid_amount Float?
1818
+ version Int @default(0) // For optimistic locking
1819
+ created_at DateTime @default(now()) @db.Timestamptz(6)
1820
+ created_by Int?
1821
+ updated_at DateTime @updatedAt @db.Timestamptz(6)
1822
+ updated_by Int?
1823
+ is_deleted Boolean @default(false)
1824
+ deleted_at DateTime? @db.Timestamptz(6)
1825
+ deleted_by Int?
1827
1826
 
1828
1827
  @@index([event_id, event_item_id])
1829
1828
  @@index([event_id, boq_event_item_id])
@@ -1841,7 +1840,7 @@ model BidLog {
1841
1840
  event Event? @relation(fields: [event_id], references: [id], onDelete: Cascade)
1842
1841
  event_item_id Int?
1843
1842
  event_item EventItems? @relation(fields: [event_item_id], references: [id], onDelete: Cascade)
1844
- boq_event_item_id Int?
1843
+ boq_event_item_id Int?
1845
1844
  boq_event_item BoqEventItem? @relation(fields: [boq_event_item_id], references: [id], onDelete: Cascade)
1846
1845
  event_type EventType?
1847
1846
  event_vendor_id Int?
@@ -1897,7 +1896,7 @@ model Quotation {
1897
1896
  event_item_id Int?
1898
1897
  event_item EventItems? @relation(fields: [event_item_id], references: [id], onDelete: Cascade)
1899
1898
  boq_event_item_id Int?
1900
- boq_event_item BoqEventItem? @relation(fields: [boq_event_item_id], references: [id], onDelete: Cascade)
1899
+ boq_event_item BoqEventItem? @relation(fields: [boq_event_item_id], references: [id], onDelete: Cascade)
1901
1900
  event_type EventType? // Should be RFQ, RFI, or RFP
1902
1901
  event_vendor_id Int?
1903
1902
  event_vendor EventVendors? @relation(fields: [event_vendor_id], references: [id], onDelete: Cascade)
@@ -1935,8 +1934,8 @@ model QuotationLog {
1935
1934
  event Event? @relation(fields: [event_id], references: [id], onDelete: Cascade)
1936
1935
  event_item_id Int?
1937
1936
  event_item EventItems? @relation(fields: [event_item_id], references: [id], onDelete: Cascade)
1938
- boq_event_item_id Int?
1939
- boq_event_item BoqEventItem? @relation(fields: [boq_event_item_id], references: [id], onDelete: Cascade)
1937
+ boq_event_item_id Int?
1938
+ boq_event_item BoqEventItem? @relation(fields: [boq_event_item_id], references: [id], onDelete: Cascade)
1940
1939
  event_type EventType?
1941
1940
  event_vendor_id Int?
1942
1941
  event_vendor EventVendors? @relation(fields: [event_vendor_id], references: [id], onDelete: Cascade)
@@ -2969,6 +2968,10 @@ model Catalogue {
2969
2968
  enum CatalogueVendorStatusEnum {
2970
2969
  ACTIVE
2971
2970
  INACTIVE
2971
+ BLOCKED
2972
+ SUSPENDED
2973
+ PENDING_FOR_APPROVAL
2974
+ REJECTED_FOR_APPROVAL
2972
2975
  }
2973
2976
 
2974
2977
  model CatalogueVendor {
@@ -3419,7 +3422,7 @@ model BlanketPurchaseOrder {
3419
3422
  terms_conditions String?
3420
3423
  notes String?
3421
3424
  business_entity_id Int?
3422
- business_entity BusinessEntity? @relation(fields: [business_entity_id], references: [id], onDelete: Cascade)
3425
+ business_entity BusinessEntity? @relation(fields: [business_entity_id], references: [id], onDelete: Cascade)
3423
3426
  created_at DateTime @default(now()) @db.Timestamptz(6)
3424
3427
  created_by Int?
3425
3428
  user User? @relation(fields: [created_by], references: [id], onDelete: Cascade)
@@ -3544,12 +3547,12 @@ model GRN {
3544
3547
  uuid String @unique @default(uuid())
3545
3548
 
3546
3549
  // GRN details
3547
- grn_number String? @unique
3550
+ grn_number String? @unique
3548
3551
  purchase_order_id Int?
3549
- purchase_order PurchaseOrder? @relation(fields: [purchase_order_id], references: [id], onDelete: Cascade)
3550
- dispatch_date_time DateTime? @db.Timestamptz(6)
3551
- expected_arrival_date DateTime? @db.Timestamptz(6)
3552
- received_date_time DateTime? @db.Timestamptz(6)
3552
+ purchase_order PurchaseOrder? @relation(fields: [purchase_order_id], references: [id], onDelete: Cascade)
3553
+ dispatch_date_time DateTime? @db.Timestamptz(6)
3554
+ expected_arrival_date DateTime? @db.Timestamptz(6)
3555
+ received_date_time DateTime? @db.Timestamptz(6)
3553
3556
  received_by String?
3554
3557
  remarks String?
3555
3558
  start_point String?
@@ -3563,8 +3566,8 @@ model GRN {
3563
3566
  driver_contact_number String?
3564
3567
  e_way_bill_number String?
3565
3568
  tracking_link String?
3566
- delivery_challan_documents Json? @db.JsonB
3567
- grn_status GRNStatus @default(PENDING)
3569
+ delivery_challan_documents Json? @db.JsonB
3570
+ grn_status GRNStatus @default(PENDING)
3568
3571
  delivery_challan_number String?
3569
3572
 
3570
3573
  // inspection details
@@ -3747,24 +3750,24 @@ model Invoice {
3747
3750
  // ------------------------------------ INVOICE ITEM MODEL START ------------------------------------
3748
3751
 
3749
3752
  model InvoiceItem {
3750
- id Int @id @default(autoincrement())
3751
- uuid String @unique @default(uuid())
3753
+ id Int @id @default(autoincrement())
3754
+ uuid String @unique @default(uuid())
3752
3755
  invoice_id Int?
3753
- invoice Invoice? @relation(fields: [invoice_id], references: [id], onDelete: Cascade)
3756
+ invoice Invoice? @relation(fields: [invoice_id], references: [id], onDelete: Cascade)
3754
3757
  purchase_order_item_id Int?
3755
- purchase_order_item PurchaseOrderItem? @relation(fields: [purchase_order_item_id], references: [id])
3756
- ordered_quantity Int? @default(0)
3757
- invoice_quantity Int? @default(0)
3758
+ purchase_order_item PurchaseOrderItem? @relation(fields: [purchase_order_item_id], references: [id])
3759
+ ordered_quantity Int? @default(0)
3760
+ invoice_quantity Int? @default(0)
3758
3761
  uom String?
3759
- unit_amount Decimal @default(0) @db.Decimal(15, 2)
3760
- total_amount Decimal @default(0) @db.Decimal(15, 2)
3761
- po_quantity Int? @default(0)
3762
- grn_quantity Int? @default(0)
3763
- quality_quantity Int? @default(0)
3764
- matching_status InvoiceMatchingStatus @default(MISMATCHED)
3762
+ unit_amount Decimal @default(0) @db.Decimal(15, 2)
3763
+ total_amount Decimal @default(0) @db.Decimal(15, 2)
3764
+ po_quantity Int? @default(0)
3765
+ grn_quantity Int? @default(0)
3766
+ quality_quantity Int? @default(0)
3767
+ matching_status InvoiceMatchingStatus @default(MISMATCHED)
3765
3768
  resolution_action String?
3766
3769
  resolution_remarks String?
3767
- resolved_at DateTime? @db.Timestamptz(6)
3770
+ resolved_at DateTime? @db.Timestamptz(6)
3768
3771
  resolved_by Int?
3769
3772
 
3770
3773
  created_at DateTime @default(now()) @db.Timestamptz(6)
@@ -3783,29 +3786,36 @@ model InvoiceItem {
3783
3786
 
3784
3787
  // ------------------------------------ INVOICE ITEM MODEL END ------------------------------------
3785
3788
 
3786
- // ------------------------------------ USER APPROVAL MANAGEMENT MODEL START ---------------------------
3789
+ // ------------------------------------ APPROVAL MANAGEMENT MODEL START --------------------------------
3787
3790
 
3788
- enum UserApprovalManagementStatusEnum {
3791
+ enum ApprovalManagementStatusEnum {
3789
3792
  PENDING
3790
3793
  APPROVED
3791
3794
  REJECTED
3792
3795
  }
3793
- model UserApprovalManagement {
3794
- id Int @id @default(autoincrement())
3795
- uuid String @unique @default(uuid())
3796
- user_id Int?
3797
- user User? @relation(fields: [user_id], references: [id], onDelete: Cascade)
3798
- batch_id String?
3799
- task_type String?
3800
- proposed_payload Json?
3801
- previous_snapshot Json?
3802
- request_status UserApprovalManagementStatusEnum @default(PENDING)
3803
- reject_reason String?
3804
- created_at DateTime @default(now()) @db.Timestamptz(6)
3805
- created_by Int?
3806
3796
 
3807
- @@map("user_approval_management")
3808
- }
3797
+ model ApprovalManagement {
3798
+ id Int @id @default(autoincrement())
3799
+ uuid String @unique @default(uuid())
3800
+ journy_type String? // module e.g. user-management, event-management
3801
+ journey_task String? // task e.g. user-updation-approval, event-bid-award-approval
3802
+ parent_id String? // parent entity uuid (user, event, PI, etc.)
3803
+ user_id Int? // optional when subject is a user
3804
+ user User? @relation(fields: [user_id], references: [id], onDelete: Cascade)
3805
+ proposed_payload Json?
3806
+ previous_snapshot Json?
3807
+ estimated_budget Decimal? @db.Decimal(18, 2)
3808
+ batch_id String?
3809
+ request_status ApprovalManagementStatusEnum @default(PENDING)
3810
+ reject_reason String?
3811
+ created_at DateTime @default(now()) @db.Timestamptz(6)
3812
+ created_by Int?
3809
3813
 
3810
- // ------------------------------------ USER APPROVAL MANAGEMENT MODEL END ---------------------------
3814
+ @@index([parent_id])
3815
+ @@index([journy_type, journey_task])
3816
+ @@index([batch_id])
3817
+ @@index([request_status])
3818
+ @@map("approval_management")
3819
+ }
3811
3820
 
3821
+ // ------------------------------------ APPROVAL MANAGEMENT MODEL END ----------------------------------
@@ -1,12 +1,42 @@
1
1
  import { PrismaPg } from "@prisma/adapter-pg";
2
- import { PrismaClient } from "./generated/prisma/client.bundle.mjs";
2
+ import { PrismaClient as BasePrismaClient } from "./generated/prisma/client.bundle.mjs";
3
3
 
4
4
  /**
5
- * Create a PrismaClient for PostgreSQL (Prisma ORM v7 driver adapter).
6
- * @param {string} [connectionString] - Defaults to DEFAULT_DATABASE_URL
7
- * @param {object} [options] - PrismaClient options (log, etc.). Legacy v6 `datasources` / `datasourceUrl` are supported.
5
+ * Prisma 7 `@prisma/adapter-pg` does not read `?schema=` from the connection URL.
6
+ * Tenant URLs from microservices include `schema=procbay_schema`; pass it explicitly.
8
7
  */
9
- export function createPrismaClient(connectionString, options = {}) {
8
+ function getPgSchemaFromUrl(urlString) {
9
+ try {
10
+ return new URL(urlString).searchParams.get("schema") || undefined;
11
+ } catch {
12
+ return undefined;
13
+ }
14
+ }
15
+
16
+ function createPgAdapter(connectionString) {
17
+ const schema = getPgSchemaFromUrl(connectionString);
18
+ const pgOptions = schema ? { schema } : undefined;
19
+
20
+ /** @type {import('pg').PoolConfig} */
21
+ const poolConfig = { connectionString };
22
+ if (schema) {
23
+ // Adapter `schema` fixes prisma.user.findMany() etc.; $queryRaw uses plain SQL
24
+ // and still resolves unqualified names via connection search_path (not ?schema= URL).
25
+ poolConfig.options = `-c search_path=${schema}`;
26
+ }
27
+
28
+ return new PrismaPg(poolConfig, pgOptions);
29
+ }
30
+
31
+ /**
32
+ * Normalize PrismaClient constructor args for Prisma ORM v7 (driver adapter).
33
+ * Strips legacy v6 `datasources` / `datasourceUrl` and builds a `PrismaPg` adapter.
34
+ *
35
+ * @param {string|object} [connectionString]
36
+ * @param {object} [options]
37
+ * @returns {object} Options accepted by the generated PrismaClient
38
+ */
39
+ function buildPrismaClientOptions(connectionString, options = {}) {
10
40
  if (
11
41
  connectionString &&
12
42
  typeof connectionString === "object" &&
@@ -17,21 +47,45 @@ export function createPrismaClient(connectionString, options = {}) {
17
47
  }
18
48
 
19
49
  const legacyUrl =
20
- options.datasourceUrl ??
21
- options.datasources?.db?.url;
22
- const { datasources, datasourceUrl, ...prismaOptions } = options;
50
+ options.datasourceUrl ?? options.datasources?.db?.url;
51
+ const { datasources, datasourceUrl, adapter, ...prismaOptions } = options;
52
+
53
+ if (adapter) {
54
+ return { adapter, ...prismaOptions };
55
+ }
23
56
 
24
57
  const url =
25
58
  connectionString ?? legacyUrl ?? process.env.DEFAULT_DATABASE_URL;
26
59
 
27
60
  if (!url) {
28
61
  throw new Error(
29
- "Database URL is required. Set DEFAULT_DATABASE_URL or pass a connection string.",
62
+ "Database URL is required. Set DEFAULT_DATABASE_URL or pass a connection string / datasources.db.url.",
30
63
  );
31
64
  }
32
65
 
33
- const adapter = new PrismaPg({ connectionString: url });
34
- return new PrismaClient({ adapter, ...prismaOptions });
66
+ return {
67
+ adapter: createPgAdapter(url),
68
+ ...prismaOptions,
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Create a PrismaClient for PostgreSQL (Prisma ORM v7 driver adapter).
74
+ * @param {string} [connectionString] - Defaults to DEFAULT_DATABASE_URL
75
+ * @param {object} [options] - PrismaClient options (log, etc.). Legacy v6 `datasources` / `datasourceUrl` are supported.
76
+ */
77
+ export function createPrismaClient(connectionString, options = {}) {
78
+ return new BasePrismaClient(
79
+ buildPrismaClientOptions(connectionString, options),
80
+ );
35
81
  }
36
82
 
37
- export { PrismaClient };
83
+ /**
84
+ * PrismaClient with backward-compatible v6 constructor options (`datasources`, `datasourceUrl`).
85
+ * Microservices can keep using `new PrismaClient({ datasources: { db: { url } } })`.
86
+ */
87
+ export class PrismaClient extends BasePrismaClient {
88
+ constructor(connectionString, options = {}) {
89
+ super(buildPrismaClientOptions(connectionString, options));
90
+ }
91
+ }
@@ -568,7 +568,7 @@ export type Invoice = Prisma.InvoiceModel
568
568
  */
569
569
  export type InvoiceItem = Prisma.InvoiceItemModel
570
570
  /**
571
- * Model UserApprovalManagement
571
+ * Model ApprovalManagement
572
572
  *
573
573
  */
574
- export type UserApprovalManagement = Prisma.UserApprovalManagementModel
574
+ export type ApprovalManagement = Prisma.ApprovalManagementModel