@adaptware/eagles-db 0.5.36 → 0.5.37

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.
Files changed (44) hide show
  1. package/client/edge.js +231 -11
  2. package/client/index-browser.js +225 -4
  3. package/client/index.d.ts +107098 -86713
  4. package/client/index.js +231 -11
  5. package/client/libquery_engine-darwin.dylib.node +0 -0
  6. package/client/package.json +1 -1
  7. package/client/schema.prisma +467 -118
  8. package/client/wasm.js +231 -11
  9. package/package.json +1 -1
  10. package/prisma/.DS_Store +0 -0
  11. package/prisma/migrations/20260519120000_migrate_shortlisted_to_selected/migration.sql +2 -0
  12. package/prisma/schema/.DS_Store +0 -0
  13. package/prisma/schema/applications.prisma +29 -34
  14. package/prisma/schema/department.prisma +3 -2
  15. package/prisma/schema/document.prisma +0 -1
  16. package/prisma/schema/jobDescription.prisma +1 -0
  17. package/prisma/schema/licensing/aiCostLedger.prisma +34 -0
  18. package/prisma/schema/licensing/assignmentHistory.prisma +19 -0
  19. package/prisma/schema/licensing/licensePackageCatalog.prisma +62 -0
  20. package/prisma/schema/licensing/licensingEnums.prisma +80 -0
  21. package/prisma/schema/licensing/licensingLedger.prisma +32 -0
  22. package/prisma/schema/licensing/purchasedLicense.prisma +74 -0
  23. package/prisma/schema/licensing/purchasedTopUp.prisma +39 -0
  24. package/prisma/schema/migrations/20260519120000_add_analytics_schema/migration.sql +84 -0
  25. package/prisma/schema/migrations/20260625120000_add_interviewer_analytics/migration.sql +26 -0
  26. package/prisma/schema/migrations/20260629120000_add_user_lifecycle_activity_events/migration.sql +13 -0
  27. package/prisma/schema/migrations/20260629140000_drop_organisation_org_code/migration.sql +2 -0
  28. package/prisma/schema/migrations/20260629160000_employee_codes_dual_interviewer_analytics/migration.sql +87 -0
  29. package/prisma/schema/migrations/20260630120000_add_application_sources/migration.sql +38 -0
  30. package/prisma/schema/migrations/20260701120000_add_source_effectiveness_analytics/migration.sql +40 -0
  31. package/prisma/schema/migrations/20260702120000_add_analytics_daily_tables/migration.sql +232 -0
  32. package/prisma/schema/migrations/20260716120000_evaluation_category_four_values/migration.sql +204 -0
  33. package/prisma/schema/migrations/20260716130000_application_withdrawn_analytics/migration.sql +31 -0
  34. package/prisma/schema/migrations/20260804120000_contact_us_optional_website_subject/migration.sql +3 -0
  35. package/prisma/schema/migrations/20260810120000_add_licensing_schema/migration.sql +237 -0
  36. package/prisma/schema/migrations/20260814153000_add_licensing_ledger/migration.sql +236 -0
  37. package/prisma/schema/migrations/20260828120000_license_package_orgs_cost_price_ai_cost_ledger/migration.sql +74 -0
  38. package/prisma/schema/migrations/20260831120000_ai_cost_ledger_purchase_reason/migration.sql +2 -0
  39. package/prisma/schema/migrations/20260831140000_ai_cost_ledger_nullable_hiring_unit/migration.sql +3 -0
  40. package/prisma/schema/organisation.prisma +6 -0
  41. package/prisma/schema/schema.prisma +1 -1
  42. package/prisma/schema/migrations/.DS_Store +0 -0
  43. package/prisma/schema/migrations/20260826160000_add_application_fit_check_report_document/.DS_Store +0 -0
  44. package/prisma/schema/migrations/20260826160000_add_application_fit_check_report_document/migration.sql +0 -13
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "prisma-client-a836434f24a5c77ffe0f89b3f268e319f17512c16d6bbf540693a0fbe221e090",
2
+ "name": "prisma-client-0fae5beb1aff3688f99d1ad980cc6f865eb79b0a0597d272d2787f77760a1ad8",
3
3
  "main": "index.js",
4
4
  "types": "index.d.ts",
5
5
  "browser": "default.js",
@@ -414,53 +414,49 @@ enum ApplicationOfferSubstatus {
414
414
 
415
415
  model Application {
416
416
  /// Primary key
417
- id String @id @default(uuid())
417
+ id String @id @default(uuid())
418
418
  /// Foreign keys
419
- organisation_id String
420
- candidate_id String
421
- resume_id String
422
- job_description_id String
423
- evaluation_plan_id String?
424
- recruiter_id String?
425
- source_id String?
419
+ organisation_id String
420
+ candidate_id String
421
+ resume_id String
422
+ job_description_id String
423
+ evaluation_plan_id String?
424
+ recruiter_id String?
425
+ source_id String?
426
426
  /// Data fields
427
- fit_check_score Float?
428
- applied_at DateTime @default(now())
429
- round_no Int @default(0)
430
- is_jaf_completed Boolean @default(false)
431
- proceed_to_next_round Boolean? @default(false)
432
- evaluationComment String?
427
+ fit_check_score Float?
428
+ applied_at DateTime @default(now())
429
+ round_no Int @default(0)
430
+ is_jaf_completed Boolean @default(false)
431
+ proceed_to_next_round Boolean? @default(false)
432
+ evaluationComment String?
433
433
  /// Candidate flag (orthogonal to ApplicationStatus). Latest actor/comment only.
434
- is_flagged Boolean @default(false)
435
- flag_comment String?
436
- flagged_at DateTime?
437
- flagged_by String?
438
- unflag_comment String?
439
- unflagged_at DateTime?
440
- unflagged_by String?
441
- fit_check_status FitCheckStatus?
442
- status ApplicationStatus @default(PENDING)
434
+ is_flagged Boolean @default(false)
435
+ flag_comment String?
436
+ flagged_at DateTime?
437
+ flagged_by String?
438
+ unflag_comment String?
439
+ unflagged_at DateTime?
440
+ unflagged_by String?
441
+ fit_check_status FitCheckStatus?
442
+ status ApplicationStatus @default(PENDING)
443
443
  /// Fine-grained offer-stage state. Meaningful only when status = OFFER (or was OFFER for a terminal-substatus that flipped to REJECTED / JOINED).
444
- offer_substatus ApplicationOfferSubstatus?
444
+ offer_substatus ApplicationOfferSubstatus?
445
445
  /// Audit fields
446
- created_at DateTime @default(now())
447
- updated_at DateTime @updatedAt
448
- created_by String
449
- updated_by String
450
- is_active Boolean @default(true)
451
- fit_check_report_document_id String? @unique
452
- fit_check_report_updated_flag Boolean @default(false)
453
- fit_check_report_data Json? @default("{}")
454
-
446
+ created_at DateTime @default(now())
447
+ updated_at DateTime @updatedAt
448
+ created_by String
449
+ updated_by String
450
+ is_active Boolean @default(true)
455
451
  /// Relations
456
- evaluation_plan EvaluationPlan? @relation(fields: [evaluation_plan_id], references: [id])
457
- candidate User @relation(fields: [candidate_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
458
- organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
459
- resume Resume @relation(fields: [resume_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
460
- job_description JobDescription @relation(fields: [job_description_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
452
+ evaluation_plan EvaluationPlan? @relation(fields: [evaluation_plan_id], references: [id])
453
+ candidate User @relation(fields: [candidate_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
454
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
455
+ resume Resume @relation(fields: [resume_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
456
+ job_description JobDescription @relation(fields: [job_description_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
461
457
  fit_check FitCheck?
462
- recruiter User? @relation("ApplicationRecruiter", fields: [recruiter_id], references: [id])
463
- source Source? @relation(fields: [source_id], references: [id], onDelete: SetNull)
458
+ recruiter User? @relation("ApplicationRecruiter", fields: [recruiter_id], references: [id])
459
+ source Source? @relation(fields: [source_id], references: [id], onDelete: SetNull)
464
460
  interviews Interview[]
465
461
  assignments Assignment[]
466
462
  ongoing_evaluations OngoingEvaluation[]
@@ -470,7 +466,6 @@ model Application {
470
466
  communication_messages CommunicationMessage[]
471
467
  job_application_responses JobApplicationResponse[]
472
468
  offer Offer?
473
- fit_check_report_document Document? @relation("ApplicationFitCheckReportDocument", fields: [fit_check_report_document_id], references: [id], onDelete: SetNull)
474
469
 
475
470
  @@unique([candidate_id, job_description_id]) // Ensures candidate applies only once per job
476
471
  @@index([candidate_id])
@@ -1284,24 +1279,25 @@ enum HiringPlanSectionStatus {
1284
1279
  /// Replaces the free-text `business_unit` string on HiringPlanLine / Employee.
1285
1280
  /// Headship lives on DepartmentMember.is_head (at most one per dept, enforced in service).
1286
1281
  model Department {
1287
- id String @id @default(uuid())
1288
- organisation_id String
1289
- name String
1290
- code String?
1282
+ id String @id @default(uuid())
1283
+ organisation_id String
1284
+ name String
1285
+ code String?
1291
1286
  /// Global display order across departments within the org (drag-reorder in plan grid).
1292
- sort_order Int @default(0)
1293
- created_at DateTime @default(now())
1294
- updated_at DateTime @updatedAt
1295
- created_by String
1296
- updated_by String
1297
- is_active Boolean @default(true)
1298
- organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1299
- members DepartmentMember[]
1300
- hiring_plan_lines HiringPlanLine[]
1301
- employees Employee[]
1302
- job_descriptions JobDescription[]
1303
- job_profiles JobProfile[]
1304
- sections HiringPlanSection[]
1287
+ sort_order Int @default(0)
1288
+ created_at DateTime @default(now())
1289
+ updated_at DateTime @updatedAt
1290
+ created_by String
1291
+ updated_by String
1292
+ is_active Boolean @default(true)
1293
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Cascade, onUpdate: Cascade)
1294
+ members DepartmentMember[]
1295
+ hiring_plan_lines HiringPlanLine[]
1296
+ employees Employee[]
1297
+ job_descriptions JobDescription[]
1298
+ job_profiles JobProfile[]
1299
+ sections HiringPlanSection[]
1300
+ assigned_hiring_units PurchasedHiringUnit[]
1305
1301
 
1306
1302
  @@unique([organisation_id, name])
1307
1303
  @@index([organisation_id])
@@ -1405,7 +1401,6 @@ model Document {
1405
1401
  offer_letters OfferLetter[] @relation("OfferLetterPdf")
1406
1402
  offer_letter_template_snapshots OfferLetter[] @relation("OfferLetterTemplateSnapshot")
1407
1403
  offer_draft_edited_html Offer[] @relation("OfferDraftEditedHtml")
1408
- application_fit_check_report Application? @relation("ApplicationFitCheckReportDocument")
1409
1404
 
1410
1405
  // Indexes
1411
1406
  @@index([candidate_id])
@@ -2539,6 +2534,7 @@ model JobDescription {
2539
2534
  hiring_plan_line HiringPlanLine? @relation("PlanLineRequisitions", fields: [hiring_plan_line_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
2540
2535
  /// Plan lines that use this JD as the role template/reference.
2541
2536
  referenced_by_plan_lines HiringPlanLine[] @relation("PlanLineTemplateJd")
2537
+ linked_hiring_units PurchasedHiringUnit[]
2542
2538
 
2543
2539
  @@index([organisation_id])
2544
2540
  @@index([hiring_manager_id])
@@ -2730,6 +2726,353 @@ model JobRoundAnalyticsDaily {
2730
2726
  @@schema("analytics")
2731
2727
  }
2732
2728
 
2729
+ /// Append-only book of AI workflow cost (org pool, optionally a hiring unit).
2730
+ /// Covers every workflow (including license-included names). Amount is always USD.
2731
+ /// total_cost(unit) = SUM(DEBIT amount) - SUM(CREDIT amount) for that unit.
2732
+ /// CREDIT / PURCHASE is full package internal cost (USD) per hiring unit.
2733
+ /// DEBIT / USAGE is every workflow's Orion totalCost (USD), nothing excluded.
2734
+ model AiCostLedgerEntry {
2735
+ id String @id @default(uuid())
2736
+ organisation_id String
2737
+ purchased_hiring_unit_id String?
2738
+ workflow_name String
2739
+ direction LicensingLedgerDirection
2740
+ /// Always non-negative. USD.
2741
+ amount Decimal @db.Decimal(20, 4)
2742
+ reason AiCostLedgerReason
2743
+ occurred_at DateTime @default(now())
2744
+ source_type String?
2745
+ source_id String?
2746
+ description String?
2747
+ idempotency_key String @unique
2748
+ created_at DateTime @default(now())
2749
+ updated_at DateTime @default(now()) @updatedAt
2750
+ created_by String
2751
+ updated_by String
2752
+ is_active Boolean @default(true)
2753
+
2754
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2755
+ purchased_hiring_unit PurchasedHiringUnit? @relation(fields: [purchased_hiring_unit_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2756
+
2757
+ @@index([purchased_hiring_unit_id, occurred_at], map: "ai_cost_ledger_unit_occurred_idx")
2758
+ @@index([purchased_hiring_unit_id, workflow_name, occurred_at], map: "ai_cost_ledger_unit_workflow_occurred_idx")
2759
+ @@index([organisation_id, occurred_at], map: "ai_cost_ledger_org_occurred_idx")
2760
+ @@map("ai_cost_ledger")
2761
+ @@schema("licensing")
2762
+ }
2763
+
2764
+ /// Immutable assignment history for Hiring Unit department/job changes.
2765
+ model PurchasedHiringUnitAssignmentEvent {
2766
+ id String @id @default(uuid())
2767
+ purchased_hiring_unit_id String
2768
+ event_kind PurchasedHiringUnitAssignmentEventKind
2769
+ previous_department_id String?
2770
+ new_department_id String?
2771
+ previous_job_description_id String?
2772
+ new_job_description_id String?
2773
+ effective_at DateTime @default(now())
2774
+ created_by String
2775
+
2776
+ purchased_hiring_unit PurchasedHiringUnit @relation(fields: [purchased_hiring_unit_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2777
+
2778
+ @@index([purchased_hiring_unit_id], map: "purchased_hu_assignment_events_unit_id_idx")
2779
+ @@index([purchased_hiring_unit_id, effective_at], map: "purchased_hu_assignment_events_unit_effective_idx")
2780
+ @@map("purchased_hiring_unit_assignment_events")
2781
+ @@schema("licensing")
2782
+ }
2783
+
2784
+ /// Product catalogue: one wide row per (code, version) with fixed per-hiring-unit entitlements.
2785
+ /// See eagles-db/docs/eagles-db/licensing-catalog.md for column → usage metric_key mapping at purchase.
2786
+ model LicensePackage {
2787
+ id String @id @default(uuid())
2788
+ code String
2789
+ version Int
2790
+ name String
2791
+ description String?
2792
+ price Decimal @db.Decimal(18, 2)
2793
+ /// Internal cost of the package. Same currency as `currency`. Not for org-facing catalogue APIs.
2794
+ cost_price Decimal @default(0) @db.Decimal(18, 2)
2795
+ currency String @default("INR")
2796
+ status LicensePackageStatus @default(DRAFT)
2797
+ /// Number of PurchasedHiringUnit rows created per package purchase.
2798
+ units_per_purchase Int
2799
+
2800
+ /// Per-hiring-unit entitlements. null = not included; 0 = explicitly zero.
2801
+ interview_ai_assisted_hours Decimal? @db.Decimal(20, 4)
2802
+ interview_full_ai_hours Decimal? @db.Decimal(20, 4)
2803
+ interview_non_ai_hours Decimal? @db.Decimal(20, 4)
2804
+ assignment_count Decimal? @db.Decimal(20, 4)
2805
+ test_count Decimal? @db.Decimal(20, 4)
2806
+ resume_count Decimal? @db.Decimal(20, 4)
2807
+ credits Decimal? @db.Decimal(20, 4)
2808
+
2809
+ created_at DateTime @default(now())
2810
+ updated_at DateTime @updatedAt
2811
+ created_by String
2812
+ updated_by String
2813
+ is_active Boolean @default(true)
2814
+
2815
+ purchased_license_packages PurchasedLicensePackage[]
2816
+ organisations LicensePackageOrganisation[]
2817
+
2818
+ @@unique([code, version])
2819
+ @@index([code])
2820
+ @@index([status])
2821
+ @@map("license_packages")
2822
+ @@schema("licensing")
2823
+ }
2824
+
2825
+ /// Many-to-many: which organisations may see this catalogue package.
2826
+ /// Zero rows = visible to nobody except platform list (enforced later in eagles-backend).
2827
+ model LicensePackageOrganisation {
2828
+ id String @id @default(uuid())
2829
+ license_package_id String
2830
+ organisation_id String
2831
+
2832
+ created_at DateTime @default(now())
2833
+ updated_at DateTime @updatedAt
2834
+ created_by String
2835
+ updated_by String
2836
+ is_active Boolean @default(true)
2837
+
2838
+ license_package LicensePackage @relation(fields: [license_package_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2839
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2840
+
2841
+ @@unique([license_package_id, organisation_id], map: "license_package_orgs_pkg_org_key")
2842
+ @@index([organisation_id])
2843
+ @@map("license_package_organisations")
2844
+ @@schema("licensing")
2845
+ }
2846
+
2847
+ enum LicensePackageStatus {
2848
+ DRAFT
2849
+ ACTIVE
2850
+ ARCHIVED
2851
+
2852
+ @@schema("licensing")
2853
+ }
2854
+
2855
+ enum PurchasedLicensePackageStatus {
2856
+ ACTIVE
2857
+ EXPIRED
2858
+ CANCELLED
2859
+
2860
+ @@schema("licensing")
2861
+ }
2862
+
2863
+ enum PurchasedHiringUnitStatus {
2864
+ AVAILABLE
2865
+ ASSIGNED
2866
+ ACTIVE
2867
+ EXPIRED
2868
+
2869
+ @@schema("licensing")
2870
+ }
2871
+
2872
+ enum PurchasedTopUpStatus {
2873
+ ACTIVE
2874
+ DEPLETED
2875
+ CANCELLED
2876
+
2877
+ @@schema("licensing")
2878
+ }
2879
+
2880
+ enum PurchasedHiringUnitAssignmentEventKind {
2881
+ DEPARTMENT_ASSIGNED
2882
+ DEPARTMENT_UNASSIGNED
2883
+ JOB_LINKED
2884
+ JOB_UNLINKED
2885
+
2886
+ @@schema("licensing")
2887
+ }
2888
+
2889
+ enum LicensingLedgerEntitlementType {
2890
+ INTERVIEW_AI_ASSISTED_HOURS
2891
+ INTERVIEW_FULL_AI_HOURS
2892
+ INTERVIEW_NON_AI_HOURS
2893
+ ASSIGNMENT_COUNT
2894
+ TEST_COUNT
2895
+ RESUME_COUNT
2896
+ CREDITS
2897
+
2898
+ @@schema("licensing")
2899
+ }
2900
+
2901
+ enum LicensingLedgerDirection {
2902
+ CREDIT
2903
+ DEBIT
2904
+
2905
+ @@schema("licensing")
2906
+ }
2907
+
2908
+ enum LicensingLedgerReason {
2909
+ PURCHASE
2910
+ TOP_UP
2911
+ USAGE
2912
+ ADJUSTMENT
2913
+ REFUND
2914
+ EXPIRY
2915
+
2916
+ @@schema("licensing")
2917
+ }
2918
+
2919
+ enum AiCostLedgerReason {
2920
+ PURCHASE
2921
+ USAGE
2922
+ ADJUSTMENT
2923
+ REFUND
2924
+
2925
+ @@schema("licensing")
2926
+ }
2927
+
2928
+ /// Append-only book of hiring-unit entitlement movements.
2929
+ /// remaining(unit, type) = SUM(CREDIT amount) - SUM(DEBIT amount).
2930
+ /// See eagles-db/docs/eagles-db/licensing-hiring-unit.md.
2931
+ model LicensingLedgerEntry {
2932
+ id String @id @default(uuid())
2933
+ organisation_id String
2934
+ /// Null for org-level rows (e.g. unallocated top-ups later).
2935
+ purchased_hiring_unit_id String?
2936
+ entitlement_type LicensingLedgerEntitlementType
2937
+ direction LicensingLedgerDirection
2938
+ /// Always non-negative. CREDIT of 0 means the stem is included at zero.
2939
+ amount Decimal @db.Decimal(20, 4)
2940
+ reason LicensingLedgerReason
2941
+ occurred_at DateTime @default(now())
2942
+ source_type String?
2943
+ source_id String?
2944
+ description String?
2945
+ idempotency_key String @unique
2946
+ created_at DateTime @default(now())
2947
+ updated_at DateTime @default(now()) @updatedAt
2948
+ created_by String
2949
+ updated_by String
2950
+ is_active Boolean @default(true)
2951
+
2952
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2953
+ purchased_hiring_unit PurchasedHiringUnit? @relation(fields: [purchased_hiring_unit_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2954
+
2955
+ @@index([purchased_hiring_unit_id, entitlement_type, occurred_at], map: "licensing_ledger_unit_type_occurred_idx")
2956
+ @@index([organisation_id, entitlement_type, occurred_at], map: "licensing_ledger_org_type_occurred_idx")
2957
+ @@map("licensing_ledger")
2958
+ @@schema("licensing")
2959
+ }
2960
+
2961
+ /// Historical package purchase by an organisation (independent per transaction).
2962
+ model PurchasedLicensePackage {
2963
+ id String @id @default(uuid())
2964
+ organisation_id String
2965
+ license_package_id String
2966
+ /// Snapshot of catalogue identity at purchase time.
2967
+ package_code String
2968
+ package_version Int
2969
+ package_name String
2970
+ price Decimal @db.Decimal(18, 2)
2971
+ currency String @default("INR")
2972
+ units_per_purchase Int
2973
+ /// How many package instances were bought in this transaction.
2974
+ package_quantity Int @default(1)
2975
+ purchased_at DateTime @default(now())
2976
+ status PurchasedLicensePackageStatus @default(ACTIVE)
2977
+ created_at DateTime @default(now())
2978
+ updated_at DateTime @updatedAt
2979
+ created_by String
2980
+ updated_by String
2981
+ is_active Boolean @default(true)
2982
+
2983
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2984
+ license_package LicensePackage @relation(fields: [license_package_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
2985
+ hiring_units PurchasedHiringUnit[]
2986
+
2987
+ @@index([organisation_id])
2988
+ @@index([organisation_id, status])
2989
+ @@index([organisation_id, purchased_at])
2990
+ @@map("purchased_license_packages")
2991
+ @@schema("licensing")
2992
+ }
2993
+
2994
+ /// Runtime hiring unit identity and allocation. Entitlement balances live on
2995
+ /// `licensing.licensing_ledger` (Prisma model `LicensingLedgerEntry`).
2996
+ /// See eagles-db/docs/eagles-db/licensing-hiring-unit.md.
2997
+ model PurchasedHiringUnit {
2998
+ id String @id @default(uuid())
2999
+ organisation_id String
3000
+ purchased_license_package_id String
3001
+ status PurchasedHiringUnitStatus @default(AVAILABLE)
3002
+ /// Current department allocation (licensing allocation, not hiring manager).
3003
+ department_id String?
3004
+ /// Set once when department_id is first assigned; not cleared on reassignment.
3005
+ first_assigned_at DateTime?
3006
+ /// Optional unit expiry.
3007
+ expiry_at DateTime?
3008
+ /// Optional job association (distinct from JobDescription.hiring_manager_id).
3009
+ job_description_id String?
3010
+
3011
+ created_at DateTime @default(now())
3012
+ updated_at DateTime @updatedAt
3013
+ created_by String
3014
+ updated_by String
3015
+ is_active Boolean @default(true)
3016
+
3017
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
3018
+ purchased_license_package PurchasedLicensePackage @relation(fields: [purchased_license_package_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
3019
+ department Department? @relation(fields: [department_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
3020
+ job_description JobDescription? @relation(fields: [job_description_id], references: [id], onDelete: SetNull, onUpdate: Cascade)
3021
+ assignment_events PurchasedHiringUnitAssignmentEvent[]
3022
+ ledger_entries LicensingLedgerEntry[]
3023
+ ai_cost_ledger_entries AiCostLedgerEntry[]
3024
+
3025
+ @@index([organisation_id])
3026
+ @@index([purchased_license_package_id])
3027
+ @@index([department_id])
3028
+ @@index([job_description_id])
3029
+ @@index([organisation_id, status])
3030
+ @@index([organisation_id, department_id])
3031
+ @@index([organisation_id, job_description_id])
3032
+ @@map("purchased_hiring_units")
3033
+ @@schema("licensing")
3034
+ }
3035
+
3036
+ /// Wide top-up purchase: org-level per-metric pool (purchased / remaining) before allocation to hiring units.
3037
+ model PurchasedTopUp {
3038
+ id String @id @default(uuid())
3039
+ organisation_id String
3040
+ purchased_at DateTime @default(now())
3041
+ status PurchasedTopUpStatus @default(ACTIVE)
3042
+ total_price Decimal? @db.Decimal(18, 2)
3043
+ currency String? @default("INR")
3044
+ description String?
3045
+
3046
+ interview_ai_assisted_hours_purchased Decimal? @db.Decimal(20, 4)
3047
+ interview_full_ai_hours_purchased Decimal? @db.Decimal(20, 4)
3048
+ interview_non_ai_hours_purchased Decimal? @db.Decimal(20, 4)
3049
+ assignment_count_purchased Decimal? @db.Decimal(20, 4)
3050
+ test_count_purchased Decimal? @db.Decimal(20, 4)
3051
+ resume_count_purchased Decimal? @db.Decimal(20, 4)
3052
+ credits_purchased Decimal? @db.Decimal(20, 4)
3053
+
3054
+ interview_ai_assisted_hours_remaining Decimal? @db.Decimal(20, 4)
3055
+ interview_full_ai_hours_remaining Decimal? @db.Decimal(20, 4)
3056
+ interview_non_ai_hours_remaining Decimal? @db.Decimal(20, 4)
3057
+ assignment_count_remaining Decimal? @db.Decimal(20, 4)
3058
+ test_count_remaining Decimal? @db.Decimal(20, 4)
3059
+ resume_count_remaining Decimal? @db.Decimal(20, 4)
3060
+ credits_remaining Decimal? @db.Decimal(20, 4)
3061
+
3062
+ created_at DateTime @default(now())
3063
+ updated_at DateTime @updatedAt
3064
+ created_by String
3065
+ updated_by String
3066
+ is_active Boolean @default(true)
3067
+
3068
+ organisation Organisation @relation(fields: [organisation_id], references: [id], onDelete: Restrict, onUpdate: Cascade)
3069
+
3070
+ @@index([organisation_id])
3071
+ @@index([organisation_id, status])
3072
+ @@map("purchased_top_ups")
3073
+ @@schema("licensing")
3074
+ }
3075
+
2733
3076
  model LiveAnalysis {
2734
3077
  id String @id @default(uuid())
2735
3078
  //foreign keys
@@ -3152,65 +3495,71 @@ enum OrganisationSize {
3152
3495
  }
3153
3496
 
3154
3497
  model Organisation {
3155
- id String @id @default(uuid())
3156
- name String @unique
3157
- industry String
3158
- about String
3159
- website String
3160
- size OrganisationSize @default(ONE_TO_TEN)
3161
- phone String
3162
- address String
3163
- company_values Json[]
3164
- allowed_email_domains String[]
3165
- send_email Boolean @default(true)
3166
- interviewers User[]
3167
- created_at DateTime @default(now())
3168
- updated_at DateTime @updatedAt
3169
- created_by String
3170
- updated_by String
3171
- is_active Boolean @default(true)
3172
- alias String? @unique
3173
- logo String?
3174
- job_sequence Int @default(1)
3175
- employee_sequence Int @default(1)
3176
- applications Application[]
3177
- user_roles UserRole[]
3178
- job_descriptions JobDescription[]
3179
- job_profiles JobProfile[]
3180
- assessment_library AssessmentLibrary[]
3181
- assignment_library AssignmentLibrary[]
3182
- interviews Interview[]
3183
- assignments Assignment[]
3184
- fit_check FitCheck[] // one-to-many link
3185
- resumes Resume[] // one-to-many link
3186
- approvals Approval[] // one-to-many link
3187
- suggestions Suggestion[]
3188
- ongoing_evaluations OngoingEvaluation[] // optional one-to-many
3189
- actions Action[]
3190
- integration_credentials IntegrationCredential[]
3191
- zoho_sync_mappings ZohoSyncMapping[]
3192
- assessments Assessment[]
3193
- timezone String @default("Asia/Kolkata")
3498
+ id String @id @default(uuid())
3499
+ name String @unique
3500
+ industry String
3501
+ about String
3502
+ website String
3503
+ size OrganisationSize @default(ONE_TO_TEN)
3504
+ phone String
3505
+ address String
3506
+ company_values Json[]
3507
+ allowed_email_domains String[]
3508
+ send_email Boolean @default(true)
3509
+ interviewers User[]
3510
+ created_at DateTime @default(now())
3511
+ updated_at DateTime @updatedAt
3512
+ created_by String
3513
+ updated_by String
3514
+ is_active Boolean @default(true)
3515
+ alias String? @unique
3516
+ logo String?
3517
+ job_sequence Int @default(1)
3518
+ employee_sequence Int @default(1)
3519
+ applications Application[]
3520
+ user_roles UserRole[]
3521
+ job_descriptions JobDescription[]
3522
+ job_profiles JobProfile[]
3523
+ assessment_library AssessmentLibrary[]
3524
+ assignment_library AssignmentLibrary[]
3525
+ interviews Interview[]
3526
+ assignments Assignment[]
3527
+ fit_check FitCheck[] // one-to-many link
3528
+ resumes Resume[] // one-to-many link
3529
+ approvals Approval[] // one-to-many link
3530
+ suggestions Suggestion[]
3531
+ ongoing_evaluations OngoingEvaluation[] // optional one-to-many
3532
+ actions Action[]
3533
+ integration_credentials IntegrationCredential[]
3534
+ zoho_sync_mappings ZohoSyncMapping[]
3535
+ assessments Assessment[]
3536
+ timezone String @default("Asia/Kolkata")
3194
3537
  /// ISO 3166-1 alpha-2 (e.g. IN).
3195
- country_code String @default("IN")
3196
- organisation_configs OrganisationConfig[]
3197
- activity_events ActivityEvent[]
3198
- usage_ledger_entries UsageLedgerEntry[]
3199
- usage_aggregates UsageAggregate[]
3200
- channel_provider_configs ChannelProviderConfig[]
3201
- conversations Conversation[]
3202
- communication_messages CommunicationMessage[]
3203
- job_application_fields JobApplicationField[]
3204
- documents Document[]
3205
- job_application_templates JobApplicationTemplate[]
3206
- offer_letter_templates OfferLetterTemplate[]
3207
- offers Offer[]
3208
- sources Source[]
3209
- evaluation_criteria EvaluationCriteria[]
3210
- departments Department[]
3211
- hiring_plans HiringPlan[]
3212
- employees Employee[]
3213
- competency_dictionaries CompetencyDictionary[]
3538
+ country_code String @default("IN")
3539
+ organisation_configs OrganisationConfig[]
3540
+ activity_events ActivityEvent[]
3541
+ usage_ledger_entries UsageLedgerEntry[]
3542
+ usage_aggregates UsageAggregate[]
3543
+ channel_provider_configs ChannelProviderConfig[]
3544
+ conversations Conversation[]
3545
+ communication_messages CommunicationMessage[]
3546
+ job_application_fields JobApplicationField[]
3547
+ documents Document[]
3548
+ job_application_templates JobApplicationTemplate[]
3549
+ offer_letter_templates OfferLetterTemplate[]
3550
+ offers Offer[]
3551
+ sources Source[]
3552
+ evaluation_criteria EvaluationCriteria[]
3553
+ departments Department[]
3554
+ hiring_plans HiringPlan[]
3555
+ employees Employee[]
3556
+ competency_dictionaries CompetencyDictionary[]
3557
+ purchased_license_packages PurchasedLicensePackage[]
3558
+ purchased_hiring_units PurchasedHiringUnit[]
3559
+ purchased_top_ups PurchasedTopUp[]
3560
+ licensing_ledger_entries LicensingLedgerEntry[]
3561
+ license_package_organisations LicensePackageOrganisation[]
3562
+ ai_cost_ledger_entries AiCostLedgerEntry[]
3214
3563
 
3215
3564
  @@index([name])
3216
3565
  @@schema("public")
@@ -3675,7 +4024,7 @@ datasource db {
3675
4024
  provider = "postgresql"
3676
4025
  url = env("DATABASE_URL")
3677
4026
 
3678
- schemas = ["public", "analytics", "usage"]
4027
+ schemas = ["public", "analytics", "usage", "licensing"]
3679
4028
  }
3680
4029
 
3681
4030
  enum SourceCategory {