sessionMigrations top-level property
All session migrations in order.
Implementation
final sessionMigrations = <Migration>[
// v1 → v2: Add token tracking, cost field
Migration(
fromVersion: 1,
toVersion: 2,
description: 'Add token tracking and cost fields',
migrate: (data) async {
final result = Map<String, dynamic>.from(data);
result.putIfAbsent('totalInputTokens', () => 0);
result.putIfAbsent('totalOutputTokens', () => 0);
result.putIfAbsent('totalCost', () => 0.0);
result.putIfAbsent('cacheReadTokens', () => 0);
result.putIfAbsent('cacheCreationTokens', () => 0);
// Add model field to each message if missing
final messages = result['messages'] as List?;
if (messages != null) {
for (final msg in messages) {
if (msg is Map && !msg.containsKey('model')) {
msg['model'] = result['model'] ?? 'unknown';
}
}
}
result['sessionVersion'] = 2;
return result;
},
),
];