Rework entry types: merge hotel into stay, transport with modes, auto-transport
- Type set is now activity/stay/transport/flight/rental/note; hotel, travel and immigration are removed with idempotent startup data migrations (hotel->stay, travel->transport, immigration->activity with flag prefix) - Transport entries carry an optional mode (train/bus/ferry/taxi/drive/other) that drives the chip/map icon; route stops expose transport_mode - Creating a stay auto-creates a bridging transport to its neighbouring stays unless a transport/flight already covers the gap (one-shot) - Summary: transports count replaces hotels/travelLegs
This commit is contained in:
@@ -45,6 +45,7 @@ CREATE TABLE IF NOT EXISTS entries (
|
||||
split_mode TEXT NOT NULL DEFAULT 'equal',
|
||||
segments TEXT,
|
||||
rental TEXT,
|
||||
transport_mode TEXT,
|
||||
created_at TEXT DEFAULT current_timestamp
|
||||
);
|
||||
|
||||
@@ -70,6 +71,7 @@ const MIGRATIONS = [
|
||||
{ table: 'entries', column: 'segments', ddl: 'ALTER TABLE entries ADD COLUMN segments TEXT' },
|
||||
{ table: 'entries', column: 'rental', ddl: 'ALTER TABLE entries ADD COLUMN rental TEXT' },
|
||||
{ table: 'entries', column: 'end_date', ddl: 'ALTER TABLE entries ADD COLUMN end_date TEXT' },
|
||||
{ table: 'entries', column: 'transport_mode', ddl: 'ALTER TABLE entries ADD COLUMN transport_mode TEXT' },
|
||||
];
|
||||
|
||||
function applyMigrations(db) {
|
||||
@@ -79,6 +81,15 @@ function applyMigrations(db) {
|
||||
}
|
||||
}
|
||||
|
||||
// Data migrations for the 2026-07 entry-type rework (hotel/travel/immigration
|
||||
// removed in favour of stay/transport/activity). Naturally idempotent: after
|
||||
// the first run no rows of the legacy types remain, so re-running is a no-op.
|
||||
export function applyDataMigrations(db) {
|
||||
db.exec("UPDATE entries SET type = 'stay' WHERE type = 'hotel'");
|
||||
db.exec("UPDATE entries SET type = 'transport' WHERE type = 'travel'");
|
||||
db.exec("UPDATE entries SET type = 'activity', title = '🛂 ' || title WHERE type = 'immigration'");
|
||||
}
|
||||
|
||||
// Open (or create) the SQLite database at dbPath and ensure the schema exists.
|
||||
export function openDb(dbPath) {
|
||||
const db = new Database(dbPath);
|
||||
@@ -86,5 +97,6 @@ export function openDb(dbPath) {
|
||||
db.pragma('foreign_keys = ON');
|
||||
db.exec(SCHEMA);
|
||||
applyMigrations(db);
|
||||
applyDataMigrations(db);
|
||||
return db;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user