Skip to main content

Leave Balance Storage

Summary

LeaveBalances stores one database-enforced row per tenant, user, Leave type, and year.

Audience

Backend developers, QA, Payroll integrators, architects, and support engineers.

Reference Content

Persisted values are opening, accrued, used, adjusted, carried-forward, encashed, and last-updated time. Available balance is derived in domain code as the additive credits minus used and encashed units; it is not a stored column. Opening, accrued, and used values are normalized non-negative by application methods, while adjustment may be signed. No database check constraint repeats these rules.

All diagram relationships are logical; no foreign keys exist. The unique index is tenant + user + Leave type + year. Approval increases used units and approved cancellation reverses usage, but those changes occur through a separate SaveChanges call after the request-state commit. No Pending/reserved balance column or insufficient-balance database constraint exists. Carry-forward and encashment columns are present, while their end-to-end processes remain Foundation.

ConcernDatabase enforcementSource
IdentityInteger primary keymicroservices/src/leave-service/Infrastructure/LeaveDbContext.cs
Balance scopeUnique tenant/user/type/yearmicroservices/src/leave-service/Infrastructure/LeaveDbContext.cs
Decimal storageSix numeric values with fixed precisionmicroservices/src/leave-service/Infrastructure/LeaveDbContext.cs
AvailabilityDerived, not persistedmicroservices/src/leave-service/Domain/Leave/LeaveBalance.cs
UpdatesApplication aggregate methods and unit of workmicroservices/src/leave-service/Application/LeaveWorkflows.cs

Source References

  • microservices/src/leave-service/Domain/Leave/LeaveBalance.cs
  • microservices/src/leave-service/Infrastructure/LeaveDbContext.cs
  • microservices/src/leave-service/Application/LeaveWorkflows.cs

See Also

Keywords

  • Leave balance
  • Available balance
  • Unique constraint

Revision Information

  • Status: Draft
  • Last reviewed: 2026-07-15
  • Review cycle: Quarterly