procbay-schema 1.0.164 → 1.0.166

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,9 +1,15 @@
1
1
  {
2
2
  "name": "procbay-schema",
3
- "version": "1.0.164",
3
+ "version": "1.0.166",
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",
7
+ "exports": {
8
+ ".": "./src/prisma/index.js",
9
+ "./src/create-prisma-client.js": "./src/create-prisma-client.js",
10
+ "./prisma/seeders/seed.js": "./prisma/seeders/seed.js",
11
+ "./prisma/seeders/utils/seeder-config-mapper.js": "./prisma/seeders/utils/seeder-config-mapper.js"
12
+ },
7
13
  "bin": {
8
14
  "prisma-sync": "scripts/sync-schemas.js",
9
15
  "prisma-seed": "scripts/seed-databases.js",
@@ -23,6 +29,7 @@
23
29
  "LICENSE"
24
30
  ],
25
31
  "devDependencies": {
32
+ "esbuild": "^0.25.0",
26
33
  "@types/bcrypt": "^5.0.2",
27
34
  "@types/jest": "^30.0.0",
28
35
  "eslint": "^9.30.1",
@@ -47,7 +54,7 @@
47
54
  "seed-database": "tsx scripts/seed-databases.js",
48
55
  "truncate-tables": "tsx scripts/truncate-tables.js",
49
56
  "test": "echo \"Error: no test specified\" && exit 1",
50
- "prepare": "prisma generate",
57
+ "prepare": "prisma generate && node scripts/bundle-prisma-client.mjs",
51
58
  "patch": "npm version patch && npm publish"
52
59
  },
53
60
  "keywords": [
@@ -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
  }
@@ -3783,29 +3783,36 @@ model InvoiceItem {
3783
3783
 
3784
3784
  // ------------------------------------ INVOICE ITEM MODEL END ------------------------------------
3785
3785
 
3786
- // ------------------------------------ USER APPROVAL MANAGEMENT MODEL START ---------------------------
3786
+ // ------------------------------------ APPROVAL MANAGEMENT MODEL START --------------------------------
3787
3787
 
3788
- enum UserApprovalManagementStatusEnum {
3788
+ enum ApprovalManagementStatusEnum {
3789
3789
  PENDING
3790
3790
  APPROVED
3791
3791
  REJECTED
3792
3792
  }
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
3793
 
3807
- @@map("user_approval_management")
3808
- }
3794
+ model ApprovalManagement {
3795
+ id Int @id @default(autoincrement())
3796
+ uuid String @unique @default(uuid())
3797
+ journy_type String? // module e.g. user-management, event-management
3798
+ journey_task String? // task e.g. user-updation-approval, event-bid-award-approval
3799
+ parent_id String? // parent entity uuid (user, event, PI, etc.)
3800
+ user_id Int? // optional when subject is a user
3801
+ user User? @relation(fields: [user_id], references: [id], onDelete: Cascade)
3802
+ proposed_payload Json?
3803
+ previous_snapshot Json?
3804
+ estimated_budget Decimal? @db.Decimal(18, 2)
3805
+ batch_id String?
3806
+ request_status ApprovalManagementStatusEnum @default(PENDING)
3807
+ reject_reason String?
3808
+ created_at DateTime @default(now()) @db.Timestamptz(6)
3809
+ created_by Int?
3809
3810
 
3810
- // ------------------------------------ USER APPROVAL MANAGEMENT MODEL END ---------------------------
3811
+ @@index([parent_id])
3812
+ @@index([journy_type, journey_task])
3813
+ @@index([batch_id])
3814
+ @@index([request_status])
3815
+ @@map("approval_management")
3816
+ }
3811
3817
 
3818
+ // ------------------------------------ APPROVAL MANAGEMENT MODEL END ----------------------------------
@@ -1,3 +1,4 @@
1
+ // tenant-config-patch: geographic seeders must throw on SQL errors
1
2
  import { createPrismaClient } from "../../src/create-prisma-client.js";
2
3
  import {
3
4
  createProgressTracker,
@@ -65,7 +66,7 @@ async function processBatch(
65
66
  error.message
66
67
  );
67
68
  tracker.update(batch.length);
68
- return { success: false, error: error.message };
69
+ throw error;
69
70
  }
70
71
 
71
72
  // Wait before retry with exponential backoff
@@ -1,3 +1,4 @@
1
+ // tenant-config-patch: geographic seeders must throw on SQL errors
1
2
  import { createPrismaClient } from "../../src/create-prisma-client.js";
2
3
  import { loadGeoData } from "./utils/json-loader.js";
3
4
  import {
@@ -106,7 +107,7 @@ async function processBatchOptimized(
106
107
  return { success: true, created: result.count };
107
108
  } catch (error) {
108
109
  logEntityError("country batch", "N/A", error.message);
109
- return { success: false, error: error.message };
110
+ throw error;
110
111
  }
111
112
  }
112
113
 
@@ -1,3 +1,4 @@
1
+ // tenant-config-patch: geographic seeders must throw on SQL errors
1
2
  import { createPrismaClient } from "../../src/create-prisma-client.js";
2
3
  import fs from "fs";
3
4
  import path from "path";
@@ -51,8 +52,8 @@ export async function seedRegions(prismaClient, seederManager = null) {
51
52
  // Store the mapping between JSON ID and database ID
52
53
  regionIdMap.set(jsonId, dbRegion.id);
53
54
  } catch (error) {
54
- // Log error but don't interrupt progress bar
55
55
  logEntityError("regions", region.name, error.message);
56
+ throw error;
56
57
  }
57
58
  tracker.update();
58
59
  }
@@ -1,3 +1,4 @@
1
+ // tenant-config-patch: geographic seeders must throw on SQL errors
1
2
  import { createPrismaClient } from "../../src/create-prisma-client.js";
2
3
  import {
3
4
  createProgressTracker,
@@ -61,7 +62,7 @@ async function processBatchOptimized(
61
62
  } catch (error) {
62
63
  logEntityError("state batch", "N/A", error.message);
63
64
  tracker.update(batch.length);
64
- return { success: false, error: error.message };
65
+ throw error;
65
66
  }
66
67
  }
67
68
  tracker.update(batch.length);
@@ -157,15 +158,12 @@ export async function seedStates(
157
158
  // Execute batches and monitor memory
158
159
  const results = await Promise.allSettled(batchPromises);
159
160
 
160
- // Check for failed batches
161
161
  const failedBatches = results.filter(
162
162
  (result) => result.status === "rejected"
163
163
  );
164
164
  if (failedBatches.length > 0) {
165
- console.warn(`${failedBatches.length} state batches failed`);
166
- failedBatches.forEach((result, index) => {
167
- console.error(`Batch ${index} error:`, result.reason);
168
- });
165
+ const reason = failedBatches[0].reason;
166
+ throw reason instanceof Error ? reason : new Error(String(reason));
169
167
  }
170
168
 
171
169
  // Final memory cleanup
@@ -1,3 +1,4 @@
1
+ // tenant-config-patch: geographic seeders must throw on SQL errors
1
2
  import { createPrismaClient } from "../../src/create-prisma-client.js";
2
3
  import {
3
4
  createProgressTracker,
@@ -65,8 +66,8 @@ export async function seedSubregions(
65
66
  // Store the mapping between JSON ID and database ID
66
67
  subregionIdMap.set(jsonId, dbSubregion.id);
67
68
  } catch (error) {
68
- // Log error but don't interrupt progress bar
69
69
  logEntityError("subregion", subregion.name, error.message);
70
+ throw error;
70
71
  }
71
72
  tracker.update();
72
73
  }
@@ -1,5 +1,5 @@
1
1
  import { PrismaPg } from "@prisma/adapter-pg";
2
- import { PrismaClient } from "./generated/prisma/client.ts";
2
+ import { PrismaClient } from "./generated/prisma/client.bundle.mjs";
3
3
 
4
4
  /**
5
5
  * Create a PrismaClient for PostgreSQL (Prisma ORM v7 driver adapter).
@@ -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