diff --git a/src/lib/supabase.ts b/src/lib/supabase.ts index 9e24ec2..d10ef56 100644 --- a/src/lib/supabase.ts +++ b/src/lib/supabase.ts @@ -1,4 +1,5 @@ import { refreshSession, getStoredSession } from './auth'; +import { COLUMNS } from '../types'; const SUPABASE_URL = 'https://hwithddwaapyhnfwcesj.supabase.co'; const SUPABASE_ANON_KEY = 'sb_publishable_fGXkh0bSrAOqSk2jWKAzSg_NJD9YPCv'; @@ -323,6 +324,17 @@ export async function getHistoryDataForMerge(): Promise for (const idx of changedIndices) { target[idx] = entry.new_data?.[idx]; } + + // CPNP values were saved through multiple code paths over time. + // Preserve the latest non-empty value even when a given history row + // does not surface it as a changed index. + const latestCpnp = + entry.new_data?.[COLUMNS.CPNP_NO] ?? + entry.old_data?.[COLUMNS.CPNP_NO]; + + if (latestCpnp !== undefined && latestCpnp !== null && latestCpnp !== '') { + target[COLUMNS.CPNP_NO] = latestCpnp; + } } return result;