upsertSession method
Idempotent session insert for the offline-outbox flow. data must
include id (a client-generated UUID) so a replay of an already-
applied write is a no-op rather than a duplicate-key error. Does
not return the row — the caller already knows the id and any
server-defaulted fields (e.g. started_at) it needs were provided
at enqueue time.
Implementation
Future<void> upsertSession(Map<String, dynamic> data) async {
assert(data.containsKey('id'), 'upsertSession requires data["id"]');
final userId = _client.auth.currentUser?.id;
final payload = {'user_id': userId, ...data};
await _client
.from('learning_sessions')
.upsert(payload, onConflict: 'id', ignoreDuplicates: true);
}