# Database change log

Every change to the V2 database after the first design. Newest first.

## 2026-12-02 (later): trainee delete and editable roles

No table changed. New permission `trainee.delete`, held only by the system administrator (as `delete:trainees` in V1). Deleting a trainee removes their rows from `attendance_marks`, `attendance_corrections`, `outcome_report_lines` (and placement answers), `verification_subjects` (calls, answers, evidence links), `verification_frame_members`, `verification_run_dropouts`, `duplicate_candidates`, `roster_snapshot_members`, `roster_change_requests`, `trainee_status`, `trainee_class_history` and `trainees`; report, session, class-list and open-sample totals are counted again. A full copy of every removed row is written to the audit event `trainee_deleted`. Permission names in `permissions.label` are now plain English and refreshed on every API start.

## 2026-12-02: evidence uploads

No table changed. `verification_evidence.evidence_type` now holds V1's kinds (`call_recording`, `field_visit`, `document`, `photo`, `other`); an activity without listed file types accepts any type, as V1 did. Database in use: `v2_prod_202612012131` (export of 2026-12-01 21:21 UTC, 180 of 180 checks, 28 of 28 evidence files).

## 2026-12-01 (later): job title of a placement

`outcome_placement_details.job_title` added (text, required for wage employment, optional for the other types). The file has 29 columns: `job_title` is column 16, after `employment_type_other_text`. Applied with `npm run upgrade:placement`.

## 2026-12-01: job linkage and decent job became one result, `employment_placement`

Scripts: `migration/sql/01c_employment_placement.sql` (structure), `migration/steps/58_employment_placement.step.ts` (indicators).
The live V2 database was upgraded on 2026-12-01 (the one-time tool is removed). A new conversion (`convert:production`) does it by itself.
Safety: no report, record or sample of the two old types existed in V1 or V2. The upgrade and the conversion both stop if one ever does.
Backup made before: `pbps-v2-backups/before_employment_placement_2026-12-01.sql`. V1 was not changed, and every V1 table stays in the archive database.

| Table | Before | Now |
|---|---|---|
| `trainee_status` (one row per trainee with every result) | `job_linkage_status`, `job_linkage_date`, `job_linkage_source`, `decent_job_m1_status`, `decent_job_m1_source`, `decent_job_m2_status`, `decent_job_m2_source` | Removed. One result: `placement_status`, `placement_source`, `placement_report_id` |
| `trainee_status` | `employment_type` wage or self | `employment_type` with the four types of the report; `job_start_date` is the employment start date |
| `outcome_reports.report_type` | `job_linkage`, `decent_job` | Removed; `employment_placement` added |
| `outcome_placement_details` | did not exist | New. One row per report line: 7 support answers, employment type, start date, income, contract, employer, legal form, licence, notes |
| `indicator_definitions` | `job_linkage_rate` (14), `decent_job_placement_rate` (15) | One: `employment_placement_rate` (14). Retention 15, post-placement support 16, locality 17, timely grievance 18 |
| `indicator_definitions` formulas | `trainees.job_linked`, `trainees.decent_job_final` | `trainees.placed` |
| `indicator_stages` | 30 and 60 days of decent job | Removed |
| `indicator_targets`, `verification_plans`, `kpi_snapshots`, `activity_definitions` | old codes | new code; rows of the removed indicator deleted |

Rules: placement needs certification = Yes. Locality and retention need placement = Yes. The indicator divides by completers (up to the contract target), as both old ones did. Target 80 %.
