diff --git a/src-tauri/src/plugins/supabase.rs b/src-tauri/src/plugins/supabase.rs index 2e580a1..5790326 100644 --- a/src-tauri/src/plugins/supabase.rs +++ b/src-tauri/src/plugins/supabase.rs @@ -397,6 +397,48 @@ impl SupabaseClient { } } + /// Tenta forçar PostgREST a recarregar schema com novas colunas (vendas, edited_at, edited_by). + /// Estratégia: INSERT com novas colunas → se PGRST204, espera 1.5s → retry. + /// Fire-and-forget — falha não bloqueia. + pub fn run_migration(&self) { + let payload = serde_json::json!({ + "id_fechamento": "_mig_probe_1900", + "loja": "_probe_", + "data": "1900-01-01", + "operador": "_probe_", + "vendas": 0, + "edited_at": null, + "edited_by": null + }); + let r1 = self.http + .post(&format!("{}/rest/v1/fechamentos_web", self.base_url)) + .headers(self.headers(true)) + .header("Prefer", "resolution=merge-duplicates") + .json(&payload) + .send(); + if let Ok(resp) = r1 { + if resp.status().as_u16() == 400 { + std::thread::sleep(std::time::Duration::from_millis(1500)); + let _ = self.http + .post(&format!("{}/rest/v1/fechamentos_web", self.base_url)) + .headers(self.headers(true)) + .header("Prefer", "resolution=merge-duplicates") + .json(&serde_json::json!({ + "id_fechamento": "_mig_probe_1900", + "vendas": 0, + "edited_at": null, + "edited_by": null + })) + .send(); + } + } + // Limpa probe + let _ = self.http + .delete(&format!("{}/rest/v1/fechamentos_web?id_fechamento=eq._mig_probe_1900", self.base_url)) + .headers(self.headers(true)) + .send(); + } + /// Verifica se está online. pub fn health_check(&self) -> bool { let url = format!("{}/rest/v1/?limit=0", self.base_url); diff --git a/src/index.html b/src/index.html index b04b82a..28ff288 100644 --- a/src/index.html +++ b/src/index.html @@ -433,7 +433,7 @@