From a17bfdb1a1f5a10a0f8e9551f6364749650186ce Mon Sep 17 00:00:00 2001 From: Ida Rogalska Date: Tue, 11 Aug 2026 18:45:56 +0200 Subject: [PATCH] db: add incoming_leg_transport_mode to day_assignments --- server/src/db/migrations.ts | 11 +++++++ .../integration/leg-mode-incoming.test.ts | 30 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 server/tests/integration/leg-mode-incoming.test.ts diff --git a/server/src/db/migrations.ts b/server/src/db/migrations.ts index 75f466c7d..50aaffe4a 100644 --- a/server/src/db/migrations.ts +++ b/server/src/db/migrations.ts @@ -3772,6 +3772,17 @@ function runMigrations(db: Database.Database): void { if (!err.message?.includes('duplicate column name')) throw err; } }, + // Per-segment travel mode for boundary legs: a leg whose ORIGIN is not a place + // (booking arrival, morning hotel) stores its mode on the DESTINATION stop. + // NULL = inherit the day default. INERT whenever the previous timeline element + // is itself a place (that place's outgoing leg_transport_mode wins). + () => { + try { + db.exec('ALTER TABLE day_assignments ADD COLUMN incoming_leg_transport_mode TEXT'); + } catch (err: any) { + if (!err.message?.includes('duplicate column name')) throw err; + } + }, // School holidays are a visual Vacay calendar layer. Keep them separate from // public holidays so applyHolidayCalendars never removes vacation entries for // school-break dates. Appended LAST: this branch was cut before #1435/#1281 diff --git a/server/tests/integration/leg-mode-incoming.test.ts b/server/tests/integration/leg-mode-incoming.test.ts new file mode 100644 index 000000000..de5daf021 --- /dev/null +++ b/server/tests/integration/leg-mode-incoming.test.ts @@ -0,0 +1,30 @@ +/** + * Migration test for incoming_leg_transport_mode on day_assignments. + */ +import { describe, it, expect, beforeAll, afterAll } from 'vitest'; + +const Database = require('better-sqlite3'); + +import { createTables } from '../../src/db/schema'; +import { runMigrations } from '../../src/db/migrations'; + +let testDb: any; + +beforeAll(() => { + testDb = new Database(':memory:'); + testDb.exec('PRAGMA journal_mode = WAL'); + testDb.exec('PRAGMA foreign_keys = ON'); + createTables(testDb); + runMigrations(testDb); +}); + +afterAll(() => { + testDb.close(); +}); + +describe('incoming_leg_transport_mode migration', () => { + it('adds a nullable incoming_leg_transport_mode column to day_assignments', () => { + const cols = testDb.prepare(`PRAGMA table_info(day_assignments)`).all() as { name: string }[]; + expect(cols.map(c => c.name)).toContain('incoming_leg_transport_mode'); + }); +});