Employee Database Overview
Summary
Employee Service uses EF Core code-first persistence with the Npgsql PostgreSQL provider. One context owns the Employee bounded-context schema and coordinates aggregate state, audit records, timeline entries, and outbox records.
Audience
- Backend developers and QA engineers
- DevOps engineers and solution architects
Overview
EmployeeDbContext is registered per request. Repository adapters expose Employee, Department, Designation, and timeline persistence ports. UnitOfWork delegates one commit to the context; the context converts queued domain events into outbox messages before saving. Read paths use tenant-filtered queries and frequent no-tracking projections.
Persistence responsibilities
| Concern | Confirmed implementation | Source |
|---|---|---|
| Provider | Npgsql EF Core provider for PostgreSQL | microservices/src/employee-service/employee-service.csproj |
| Schema | Default employee schema | microservices/src/employee-service/Infrastructure/EmployeeDbContext.cs |
| Mapping | Fluent configuration in OnModelCreating | same |
| Repositories | EF-backed aggregate and organization adapters | microservices/src/employee-service/Infrastructure/Persistence.cs |
| Unit of work | One SaveChangesAsync boundary per handler commit | same |
| Search | Composable no-tracking Employee queries | microservices/src/employee-service/Infrastructure/PostgresEmployeeSearchProvider.cs |
| Evolution | Two code-first migrations plus current snapshot | microservices/src/employee-service/Infrastructure/Migrations/ |
Tenant and history behavior
Global query filters cover Employee roots, Employee child objects, Departments, Designations, and audit logs. Timeline records are child objects and inherit the child filter. Outbox processing uses a separate operational query path. See Tenant isolation.
Legacy relationship
The monolith AppDbContext still owns Legacy Labor, Department, Designation, and related document records. Those are separate models with numeric identifiers. Coexistence does not establish shared-table access or automatic synchronization.
Source References
microservices/src/employee-service/Program.csmicroservices/src/employee-service/employee-service.csprojmicroservices/src/employee-service/Infrastructure/EmployeeDbContext.csmicroservices/src/employee-service/Infrastructure/Persistence.csmicroservices/src/employee-service/Infrastructure/PostgresEmployeeSearchProvider.csData/AppDbContext.cs
Related Articles
See Also
Keywords
- EmployeeDbContext
- PostgreSQL persistence
- EF Core code first
Revision Information
- Status: Draft
- Last reviewed: 2026-07-15
- Review cycle: Quarterly