Leave Database Schema Reference
The current Leave EF model contains one DbContext, 12 persisted objects, 16 explicit indexes, four unique indexes, 12 primary keys, no foreign keys, and global tenant filters on 11 objects.
Backend developers, QA, database reviewers, architects, DevOps, and schema-automation authors.
Reference Content
| Key | Repository-relative source |
|---|
| S1 | microservices/src/leave-service/Infrastructure/LeaveDbContext.cs |
| S2 | microservices/src/leave-service/Infrastructure/Migrations/LeaveDbContextModelSnapshot.cs |
| S3 | microservices/src/leave-service/Infrastructure/Persistence.cs |
| S4 | microservices/src/leave-service/Application/LeaveWorkflows.cs |
| S5 | microservices/src/leave-service/Messaging/EmployeeProfileConsumer.cs |
| S6 | Data/AppDbContext.cs |
DbContexts
| Context | Classification | Responsibility | Source |
|---|
| LeaveDbContext | Runtime and design model | All 12 Leave-owned and operational objects | S1 |
The design-time factory creates the same LeaveDbContext; it is not a second persisted model. The monolith AppDbContext is a separate Legacy / Transitional compatibility context, not part of the Leave-owned schema.
| Group | Logical object | Purpose / classification | Tenant scope | Identifier | Logical relationships | Uniqueness/index summary | Source |
|---|
| Leave core | LeaveRequests | Request aggregate / master | Filtered | Integer identity | Employee, timeline, balance, Workflow by identifiers | Three non-unique indexes | S1 |
| Balance/policy | LeaveBalances | Annual employee/type balance / master | Filtered | Integer identity | Employee/type by identifiers | Unique tenant/user/type/year | S1 |
| Balance/policy | LeaveTypes | Type configuration / Foundation | Filtered | Integer identity | Type-name convention | Unique tenant/name | S1 |
| Balance/policy | LeavePolicies | Per-type policy / Foundation | Filtered | Integer identity | Type-name convention | Unique tenant/type | S1 |
| Calendar | Holidays | Tenant calendar / master, Transitional | Filtered | Integer identity | Calculation input | Tenant/date index | S1 |
| Calendar | WeeklyOffs | Recurring tenant day / master, Transitional | Filtered | Integer identity | Calculation input | Tenant/day index | S1 |
| Employee projection | EmployeeProfiles | Leave-local Employee read model | Filtered | Composite tenant/labor | External Employee identity | Tenant/user and tenant/external-ID indexes | S1, S5 |
| Carry/encash | CarryForwards | Year-transfer record / Foundation | Filtered | Integer identity | Balance by user/type/year | Tenant/user/type/target-year index | S1 |
| Carry/encash | Encashments | Encashment aggregate / Foundation | Filtered | Integer identity | Balance by user/type/year | Tenant/user/type/year index | S1 |
| Audit/timeline | AuditLogs | Technical audit / history | Filtered | GUID | Logical entity reference | Tenant/time index | S1 |
| Audit/timeline | LeaveTimeline | Business history / history | Filtered | Integer identity | Logical request/employee references | Tenant/labor/time index | S1 |
| Outbox/inbox | OutboxMessages | Integration delivery / operational | No global filter | GUID | Event/correlation context | Unique event; status/time index | S1, S3 |
No Leave inbox/ProcessedIntegrationEvent object exists. Employee projection last-event fields are object-local idempotency metadata.
| Relationship | Database FK | Actual enforcement | Source |
|---|
| Request to EmployeeProfile | No | Labor identifier convention and application lookup | S3, S4 |
| Request to Timeline | No | Optional request identifier written by application | S4 |
| Request to Workflow | No | Optional external correlation identifier | S1 |
| Balance to EmployeeProfile | No | User identifier bridge | S3 |
| Balance/type/policy/carry/encash | No | Leave-type string and user/year conventions | S1, S3 |
| Holiday/weekly off to requests | No | Date/day calculation queries | S4 |
| Audit to entities | No | String entity type/identifier | S3 |
Foreign-key total: 0. Consequently no cascade, restrict, or set-null relationship is configured in LeaveDbContext.
| Category | Count | Inventory | Source |
|---|
| Primary keys | 12 | One per persisted object; EmployeeProfiles uses a composite key | S1, S2 |
| Unique indexes | 4 | Balance scope; Leave type tenant/name; policy tenant/type; outbox event identity | S1, S2 |
| Non-unique indexes | 12 | Request (3), Holiday, weekly off, profile (2), carry forward, encashment, timeline, audit, outbox status/time | S1, S2 |
| Explicit indexes total | 16 | Current snapshot total | S2 |
There are no check constraints, alternate keys, or concurrency-token mappings in the current model.
| Scope | Count | Predicate model | Source |
|---|
| Business/projection/history/Foundation objects | 11 | Privileged context or current tenant | S1 |
| Operational outbox | 1 unfiltered object | Cross-tenant Pending/Failed polling | S1, S3 |
| Sequence | Migration | Change | Source |
|---|
| 1 | InitialLeaveService | 12 objects and 14 indexes | microservices/src/leave-service/Infrastructure/Migrations/20260702162726_InitialLeaveService.cs |
| 2 | AddEmployeeProfileSyncFields | Projection fields and one index | microservices/src/leave-service/Infrastructure/Migrations/20260703060858_AddEmployeeProfileSyncFields.cs |
| 3 | AddLeaveWorkflowInstance | Correlation field and one index | microservices/src/leave-service/Infrastructure/Migrations/20260706172733_AddLeaveWorkflowInstance.cs |
| Participant | Behavior | Source |
|---|
| Aggregate changes | Tracked and committed by unit of work | S3 |
| Audit/timeline | Same commit when added before SaveChanges | S3, S4 |
| New outbox messages | Added before base save and committed with that save | S1 |
| Balance after decision/cancellation | Separate later save | S4 |
| Attendance/Workflow calls | Outside database transaction | S4 |
| Profile message acknowledgement | After projection/audit save | S5 |
| Object group | Role | Source |
|---|
| Legacy LeaveRequest | Monolith compatibility request state | Models/LeaveRequest.cs |
| Legacy LeaveBalance | Monolith compatibility balance state | Models/LeaveBalance.cs |
| Legacy Holiday/WeeklyOff | Monolith compatibility calendar | Models/Holiday.cs; Models/WeeklyOff.cs |
| AppDbContext | Separate legacy ownership and tenant filters | S6 |
No source-confirmed backfill/synchronization object exists between these stores.
- microservices/src/leave-service/Infrastructure/LeaveDbContext.cs
- microservices/src/leave-service/Infrastructure/Migrations/LeaveDbContextModelSnapshot.cs
- microservices/src/leave-service/Infrastructure/Persistence.cs
- microservices/src/leave-service/Application/LeaveWorkflows.cs
- microservices/src/leave-service/Messaging/EmployeeProfileConsumer.cs
- Data/AppDbContext.cs
- Schema inventory
- Database constraints
- Persisted objects
- Status: Draft
- Last reviewed: 2026-07-15
- Review cycle: Quarterly