Fix FR24 cabin-class import mapping + repair script #24

Merged
ronnyandre merged 1 commit from fix/fr24-cabin-class-mapping into main 2026-06-04 09:49:31 +02:00
Owner

The bug

The FR24 importer's parseFlightClass assumed flightdiary's numeric "Flight class" codes were in rank order (1/2/3/4 = economy/premium/business/first). They are not — flightdiary added Economy Plus later and appended it as code 4 instead of inserting it. The correct mapping (cross-checked against AirTrail's reverse-engineered importer, FR24_FLIGHT_CLASS_MAP) is:

FR24 code Real class We stored (bug)
1 economy economy ✓
2 business premium_economy ✗
3 first business ✗
4 economy+ first ✗

So every non-economy imported flight was mislabelled — including the reported symptom (Economy Plus flights showing as First).

Changes

  • src/lib/fr24-parser.ts — corrected the mapping + explanatory comment; updated fr24-parser.test.ts.
  • scripts/fix-fr24-cabin.ts — one-off repair for already-imported rows (bijection → rotate back: premium_economy→business, business→first, first→premium_economy; economy/NULL unchanged). 3-cycle, not idempotent — a marker file blocks a second run. Dry-run by default; --apply writes.
  • package.json — db:fix:fr24-cabin convenience script. .gitignore — ignore the repair marker.

How to apply in production

pnpm db:backup
pnpm tsx scripts/fix-fr24-cabin.ts           # dry run
pnpm tsx scripts/fix-fr24-cabin.ts --apply   # perform the rotation

Verification

  • pnpm typecheck ✅ · pnpm lint ✅ · pnpm test ✅
  • Exercised on a throwaway DB copy: 3-cycle rotates correctly in one atomic pass; marker blocks a second --apply.
## The bug The FR24 importer's `parseFlightClass` assumed flightdiary's numeric "Flight class" codes were in rank order (`1/2/3/4 = economy/premium/business/first`). They are **not** — flightdiary added Economy Plus later and appended it as code `4` instead of inserting it. The correct mapping (cross-checked against [AirTrail's reverse-engineered importer](https://github.com/johanohly/AirTrail/blob/main/src/lib/import/fr24.ts), `FR24_FLIGHT_CLASS_MAP`) is: | FR24 code | Real class | We stored (bug) | |---|---|---| | 1 | economy | economy ✓ | | 2 | business | **premium_economy** ✗ | | 3 | first | **business** ✗ | | 4 | economy+ | **first** ✗ | So every non-economy imported flight was mislabelled — including the reported symptom (Economy Plus flights showing as **First**). ## Changes - **`src/lib/fr24-parser.ts`** — corrected the mapping + explanatory comment; updated `fr24-parser.test.ts`. - **`scripts/fix-fr24-cabin.ts`** — one-off repair for already-imported rows (bijection → rotate back: `premium_economy→business`, `business→first`, `first→premium_economy`; economy/NULL unchanged). 3-cycle, **not idempotent** — a marker file blocks a second run. Dry-run by default; `--apply` writes. - **`package.json`** — `db:fix:fr24-cabin` convenience script. **`.gitignore`** — ignore the repair marker. ## How to apply in production ```sh pnpm db:backup pnpm tsx scripts/fix-fr24-cabin.ts # dry run pnpm tsx scripts/fix-fr24-cabin.ts --apply # perform the rotation ``` ## Verification - `pnpm typecheck` ✅ · `pnpm lint` ✅ · `pnpm test` ✅ - Exercised on a throwaway DB copy: 3-cycle rotates correctly in one atomic pass; marker blocks a second `--apply`.
parseFlightClass assumed FR24's "Flight class" codes were rank-ordered
(1/2/3/4 = economy/premium/business/first). They are not: flightdiary
appended Economy Plus as code 4 instead of inserting it. The correct
mapping — cross-checked against AirTrail's reverse-engineered importer
(FR24_FLIGHT_CLASS_MAP) — is:

  1 = economy   2 = business   3 = first   4 = premium_economy (economy+)

So every non-economy imported flight was mislabelled (Economy Plus → First,
Business → Premium Economy, First → Business). Fix the parser + its test.

Add scripts/fix-fr24-cabin.ts to repair already-imported rows. The old map
was a bijection, so the stored value identifies the original code and we can
rotate back: premium_economy→business, business→first, first→premium_economy
(economy/NULL unchanged). It is a 3-cycle (NOT idempotent), so a marker file
next to the DB blocks an accidental second run; dry-run by default, --apply to
write. Run manually post-deploy: `pnpm tsx scripts/fix-fr24-cabin.ts --apply`.
ronnyandre deleted branch fix/fr24-cabin-class-mapping 2026-06-04 09:49:32 +02:00
ronnyandre changed title from Fix FR24 cabin-class import mapping + repair script to Tail callbacks + first-time achievements + persistent SEEN BEFORE (roadmap #1) 2026-06-04 13:21:34 +02:00
ronnyandre changed title from Tail callbacks + first-time achievements + persistent SEEN BEFORE (roadmap #1) to Fix FR24 cabin-class import mapping + repair script 2026-06-04 13:22:07 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ronnyandre/fliary!24
No description provided.