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.
| Concern | Database enforcement | Source |
|---|---|---|
| Identity | Integer primary key | microservices/src/leave-service/Infrastructure/LeaveDbContext.cs |
| Balance scope | Unique tenant/user/type/year | microservices/src/leave-service/Infrastructure/LeaveDbContext.cs |
| Decimal storage | Six numeric values with fixed precision | microservices/src/leave-service/Infrastructure/LeaveDbContext.cs |
| Availability | Derived, not persisted | microservices/src/leave-service/Domain/Leave/LeaveBalance.cs |
| Updates | Application aggregate methods and unit of work | microservices/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
Related Articles
See Also
Keywords
- Leave balance
- Available balance
- Unique constraint
Revision Information
- Status: Draft
- Last reviewed: 2026-07-15
- Review cycle: Quarterly