diff --git a/src/persistence/supabase/settings-repo.ts b/src/persistence/supabase/settings-repo.ts index 23a2f0c..b3b21f0 100644 --- a/src/persistence/supabase/settings-repo.ts +++ b/src/persistence/supabase/settings-repo.ts @@ -5,12 +5,21 @@ const DEFAULT_SETTINGS: AppSettings = { id: 'singleton', groupLabel: 'Cliente' } export const supabaseSettingsRepo = { async get(): Promise { - const { data } = await supabase + const { data, error } = await supabase .from('app_settings') .select('id, group_label') .eq('id', 'singleton') .single() - if (!data) return DEFAULT_SETTINGS + + // PGRST116 = 0 rows — singleton aún no existe, crearlo y retornar el default + if (error?.code === 'PGRST116' || !data) { + await supabase.from('app_settings').upsert({ + id: 'singleton', + group_label: 'Cliente', + }) + return DEFAULT_SETTINGS + } + return { id: 'singleton', groupLabel: (data.group_label as string) ?? 'Cliente' } },