Data integrity
Employee lifecycle management
Modelling employment status transitions and future-dated changes so HR can plan ahead while every historical record stays intact.
01Problem
Employees progress from part-time to probation to permanent, and some transitions issue a new staff code. HR often decides a change weeks ahead of its effective date.
The system needed to represent these changes without rewriting history, without letting two people edit the same pending change at once, and without making a former staff code ambiguous.
02User Needs
- HR: record a change today or schedule it for a future date, then edit, cancel or apply it early.
- Employees: keep their login, sessions and records unchanged until the change takes effect.
- Payroll and audit: see what the employee's status and code were on any given date.
03Constraints
- Staff codes are business identifiers. Once replaced, a code must never be reissued to someone else.
- A scheduled change must not conflict with other lifecycle edits, such as a position change, made in the meantime.
- The daily apply job runs unattended, so one failure must not leave the record half-applied.
- Existing employees with incomplete legacy data needed a safe, auditable way into the new model.
04Technical Decision
Treat an employment change as a first-class record with a state: scheduled, applied or cancelled. The employee row is never edited directly for these transitions.
Put the invariants in the database where possible. A partial unique index allows at most one scheduled change per employee, and a reservation table holds new staff codes permanently from the moment they are scheduled.
Edits use optimistic concurrency with an expected revision, so stale screens are rejected instead of overwriting newer decisions.
Status transitions and change states
Employment changes are records with their own lifecycle; the employee row changes only when one is applied.
Scheduled
Future date · staff code reserved · conflicting edits refused
Applied
Same day or by the daily job · one transaction · audited
Cancelled
Row kept · reservation released
05Implementation
- Immediate changes for today or a past date, and scheduled changes for future dates, with no arbitrary maximum date.
- While a change is scheduled, conflicting lifecycle edits are refused with a clear message instead of being silently merged.
- A daily scheduled job applies due changes in date order, one transaction each. Business problems leave the change scheduled with a 'needs HR review' reason; technical failures roll back completely.
- The job endpoint fails closed when its credential is missing and returns counts only.
- A separate guided action lets HR set the initial status for legacy records that had none, recorded as an audit event rather than a fake transition.
06Validation
- Unit tests for the pure transition rules, plus route and concurrency tests against a disposable database.
- A dry-run operator script that needs an explicit confirmation token before it writes anything.
- Read-only checks before and after the production release, comparing record counts and fingerprints.
- Pre-merge acceptance runs on local data, with screenshots, for the HR-facing screens.
07Outcome
- Released to production after a gated database release, with checks before and after deployment and an authenticated run of the empty scheduler.
- The full employment history is preserved, and replaced staff codes remain permanently reserved.
- An automatic 'revert' prototype was deliberately removed before release. Reverting safely needed locking coordinated with leave writes, so a documented manual review replaced it.
08Lessons Learned
- Database constraints were the most reliable documentation of the business rules: the application could not drift from them.
- Choosing to ship less by removing the revert action was the right call when the safe version needed more design.
- Fixing legacy data through a guided, audited UI let HR own the decisions record by record, instead of applying a bulk script on their behalf.
Based on the project history and release documentation. Identifiers, credentials, configuration values and open findings are intentionally omitted.
Next case studyProduction reliability