Skip to content

refactor(engraving): migra selects diretos do external-db-bridge para invokeExternalDb#521

Merged
adm01-debug merged 1 commit into
mainfrom
chore/migrate-engraving-selects
May 30, 2026
Merged

refactor(engraving): migra selects diretos do external-db-bridge para invokeExternalDb#521
adm01-debug merged 1 commit into
mainfrom
chore/migrate-engraving-selects

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

@adm01-debug adm01-debug commented May 30, 2026

Contexto

A Edge Function external-db-bridge foi descontinuada (HTTP 410). O useEngravingWizard ainda fazia 2 SELECTs chamando supabase.functions.invoke('external-db-bridge') diretamente, então essas leituras quebravam em runtime.

Mudança (1 arquivo, cirúrgica)

src/components/admin/products/sections/engraving/useEngravingWizard.ts:

  • + import { invokeExternalDb } from '@/lib/external-db';
  • SELECT do catálogo de técnicas (tecnicas_gravacao) → invokeExternalDb
  • SELECT das áreas salvas (print_area_techniques, filtrado por product_id) → invokeExternalDb

Ambas as tabelas já estão na whitelist do REST-nativo (rest-native.ts); tecnicas_gravacao usa o adaptador de colunas PT (ONDA-17). invokeExternalDb<T>() retorna { records, count }, então o consumo passou de data.data?.records para result.records.

Fora de escopo (intencional)

As mutações (insert/update/delete de print_area_techniques) permanecem inalteradas no bridge — a lacuna de escrita pós-bridge é tratada separadamente. Nenhum outro arquivo foi tocado.

Validação

  • Diff mínimo e revisado; type-strip local OK.
  • Draft de propósito: deixo o CI (build/tsc Vite) validar antes do merge, já que não rodo o build do projeto no meu ambiente.

Merge sugerido: Squash and merge (o commit final em main fica ... (#NNN) e passa no Branch Protection Sentinel).


Summary by cubic

Migra os 2 SELECTs do wizard de gravação do external-db-bridge descontinuado para invokeExternalDb (PostgREST), corrigindo erros 410 e restaurando as leituras de dados.

  • Bug Fixes
    • Técnicas (tecnicas_gravacao) e áreas salvas (print_area_techniques) agora usam invokeExternalDb; ambas já na whitelist do REST nativo.
    • Retorno ajustado para result.records; sem outras mudanças de lógica.
    • Mutations de print_area_techniques permanecem no bridge e serão tratadas separadamente.

Written for commit 3889bca. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Refactor
    • Otimização interna no carregamento de dados de técnicas de gravação e áreas de produto, melhorando a eficiência do processamento de informações do catálogo e configurações salvas.

Review Change Stack

… invokeExternalDb

useEngravingWizard fazia 2 SELECTs chamando supabase.functions.invoke('external-db-bridge')
diretamente — a Edge Function foi descontinuada (410), entao essas queries quebravam.

Migra os 2 SELECTs (catalogo de tecnicas em 'tecnicas_gravacao' e areas salvas em
'print_area_techniques') para invokeExternalDb (PostgREST nativo). Ambas as tabelas ja
estao na whitelist do rest-native; 'tecnicas_gravacao' usa o adaptador de colunas PT.
As MUTACOES (insert/update/delete) permanecem inalteradas — a lacuna de escrita pos-bridge
e tratada separadamente.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
we-dream-big Building Building Preview, Comment May 30, 2026 3:15pm

@supabase
Copy link
Copy Markdown

supabase Bot commented May 30, 2026

This pull request has been ignored for the connected project doufsxqlfjyuvxuezpln because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2a5b2bfe-5c39-4298-82ca-512deb8d6d9f

📥 Commits

Reviewing files that changed from the base of the PR and between f20301a and 3889bca.

📒 Files selected for processing (1)
  • src/components/admin/products/sections/engraving/useEngravingWizard.ts

Walkthrough

O hook useEngravingWizard é refatorado para usar um novo cliente invokeExternalDb em substituição ao bridge Supabase Functions anterior. Dois fluxos de carregamento de dados são atualizados: técnicas de gravação e áreas salvas do produto, alterando como as respostas externas são interpretadas.

Changes

Refatoração External DB

Layer / File(s) Summary
Migração para invokeExternalDb
src/components/admin/products/sections/engraving/useEngravingWizard.ts
Import de invokeExternalDb adicionado. Dois queryFn substituídos: carregamento de técnicas (table: 'tecnicas_gravacao') e áreas salvas (table: 'print_area_techniques' com filtro product_id e ordenação technique_order), ambos retornando `result.records

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • adm01-debug/promo-gifts-v4#489: Modifica também useEngravingWizard e operações via bridge externo (ex: flushLocalAreas), com possível sobreposição na refatoração do mesmo hook.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/migrate-engraving-selects

Comment @coderabbitai help to get the list of available commands and usage tips.

@adm01-debug adm01-debug marked this pull request as ready for review May 30, 2026 15:15
Copilot AI review requested due to automatic review settings May 30, 2026 15:15
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@adm01-debug adm01-debug merged commit 0e5b31f into main May 30, 2026
36 of 43 checks passed
@adm01-debug adm01-debug deleted the chore/migrate-engraving-selects branch May 30, 2026 15:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates engraving wizard read queries away from direct external-db-bridge invocation to the shared invokeExternalDb helper, aligning these SELECT paths with the REST-native external DB access layer.

Changes:

  • Adds invokeExternalDb import.
  • Migrates the techniques catalog SELECT to invokeExternalDb.
  • Migrates saved print area techniques SELECT to invokeExternalDb.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +78 to +85
const result = await invokeExternalDb<PrintAreaTechnique>({
table: 'print_area_techniques',
operation: 'select',
filters: { product_id: productId },
orderBy: { column: 'technique_order', ascending: true },
limit: 100,
});
if (error) throw new Error(error.message);
if (!data?.success) throw new Error(data?.error || 'Erro ao buscar áreas');
const records: PrintAreaTechnique[] = data.data?.records || [];
const records: PrintAreaTechnique[] = result.records || [];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants