From 2a0f7e6d2c09a24153fd09e95363aa6ff95c59d0 Mon Sep 17 00:00:00 2001 From: Marcelo Santos <117441129+marcelo-m7@users.noreply.github.com> Date: Fri, 19 Sep 2025 16:34:05 +0100 Subject: [PATCH] Fix Supabase sync table builder for schema-prefixed tables --- scripts/sync-content.mjs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/sync-content.mjs b/scripts/sync-content.mjs index 93c6dcd8..43076602 100755 --- a/scripts/sync-content.mjs +++ b/scripts/sync-content.mjs @@ -190,9 +190,19 @@ async function parseMarkdown(fullPath) { } } +function getTableBuilder(table) { + if (!table.includes('.')) { + return supabase.from(table); + } + + const [schema, ...rest] = table.split('.'); + const tableName = rest.join('.'); + return supabase.schema(schema).from(tableName); +} + async function upsert(table, rows, options = {}) { if (!rows.length) return; - const { error } = await supabase.from(table).upsert(rows, options); + const { error } = await getTableBuilder(table).upsert(rows, options); if (error) { throw new Error(`Erro ao sincronizar ${table}: ${error.message}`); } @@ -200,7 +210,7 @@ async function upsert(table, rows, options = {}) { async function insert(table, rows) { if (!rows.length) return; - const { error } = await supabase.from(table).insert(rows); + const { error } = await getTableBuilder(table).insert(rows); if (error) { throw new Error(`Erro ao inserir em ${table}: ${error.message}`); } @@ -209,7 +219,7 @@ async function insert(table, rows) { async function purge(table, column, values) { if (!values.length) return; for (const value of values) { - const { error } = await supabase.from(table).delete().eq(column, value); + const { error } = await getTableBuilder(table).delete().eq(column, value); if (error) { throw new Error(`Erro ao limpar ${table} (${column}=${value}): ${error.message}`); }