Files
Davide Scaini 946da685e5 feat(mobile): editable activity title for local activities
Adds edits_json column (migration v3) to store user overrides separately
from detail_json so Option A server re-extraction never clobbers them.

- Tap the title in the detail screen to edit (local activities only, shown
  with a ✎ hint). Saves on keyboard dismiss via onEndEditing.
- Cards and search display user_title ?? title.
- Raw upload: user_title sent to server -> sidecar written so web UI shows
  the correct title (server re-extracts from FIT, which has Karoo's title).
- BAS upload: detail.title overridden before sending, no sidecar needed.
2026-04-27 15:20:19 +02:00

48 lines
1.6 KiB
TypeScript

import type { SQLiteDatabase } from 'expo-sqlite';
export async function migrateDb(db: SQLiteDatabase): Promise<void> {
await db.execAsync('PRAGMA journal_mode = WAL;');
await db.execAsync(`
CREATE TABLE IF NOT EXISTS activities (
id TEXT PRIMARY KEY,
source_hash TEXT NOT NULL,
detail_json TEXT NOT NULL,
timeseries_json TEXT,
geojson TEXT,
original_path TEXT,
synced_at INTEGER,
origin TEXT NOT NULL CHECK(origin IN ('local', 'remote')),
created_at INTEGER NOT NULL DEFAULT (unixepoch())
);
CREATE INDEX IF NOT EXISTS idx_activities_created_at
ON activities(created_at DESC);
CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
);
`);
// Migration v2: source_path stores the original filesystem path a file was
// imported from (e.g. /sdcard/Karoo/Rides/ride.fit), used for watch-folder
// deduplication without re-hashing files.
try {
await db.execAsync('ALTER TABLE activities ADD COLUMN source_path TEXT');
await db.execAsync(
'CREATE INDEX IF NOT EXISTS idx_activities_source_path ON activities(source_path)',
);
} catch {
// Column already exists — migration already ran, ignore.
}
// Migration v3: edits_json stores user overrides (e.g. {"title": "My title"})
// kept separate from detail_json so server re-extraction (Option A) never
// clobbers user edits.
try {
await db.execAsync('ALTER TABLE activities ADD COLUMN edits_json TEXT');
} catch {
// Column already exists — migration already ran, ignore.
}
}