Skip to content

fix(rest-native): Phase 2 — resolve ghost aliases + safe RPC stubs + WRITE tables#548

Merged
adm01-debug merged 1 commit into
mainfrom
claude/exciting-wright-xA6by
May 31, 2026
Merged

fix(rest-native): Phase 2 — resolve ghost aliases + safe RPC stubs + WRITE tables#548
adm01-debug merged 1 commit into
mainfrom
claude/exciting-wright-xA6by

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

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

Summary

Continuação da Fase 1 (PR #546). Kill-switch edge_external_db_bridge OFF desde 2026-05-30.

  • ETAPA 5: customization_price_tables → alias para tabela_preco_gravacao_oficial (17 callers). +TABLE_ALIAS, +COLUMN_ALIASES_BY_TABLE (mapeamento EN→PT), +mapRows (projeção EN nos resultados), +SEARCH_COLUMNS
  • ETAPA 6: tecnica_gravacao_variante → alias para tabela_preco_gravacao_oficial (9 refs). +READ whitelist, +WRITE whitelist, +WRITE_TABLE_ALIAS
  • ETAPA 8: 6 RPCs NOT_IN_DB no dispatch table mudados de throw para retorno seguro — previne crash em fn_get_customization_price_v2 (os 2 🔴 da simulação)
  • ETAPA 9: v_products_without_videos → alias para v_products_without_video (typo fix)
  • ETAPA 10: +5 tabelas WRITE: tabela_preco_gravacao_oficial, tabela_preco_gravacao_oficial_faixa, tecnicas_gravacao, tags, tecnica_gravacao_variante

Contagens finais

Estrutura Antes Depois
REST_NATIVE_SAFE_TABLES 68 71
TABLE_ALIASES 6 9
WRITE_TABLE_ALIASES 3 4
REST_NATIVE_WRITE_TABLES 22 27

Validação

  • TypeScript: 0 erros, 0 regressões (baseline: 62 erros pré-existentes)
  • Simulação: 87 cenários, 0 regressões. Funcionalidades afetadas já retornavam vazio — este PR restaura dados parciais.

Riscos conhecidos (pré-existentes, não causados por este PR)

  1. customization_price_tables callers esperam price_1..5 / min_qty_1..5 (vêm de tabela separada _faixa) — retornarão null
  2. useTechniquePricing.ts:65 usa supabase.from('customization_price_tables') direto — não passa pelo alias (continua falhando)
  3. tabela_preco_gravacao_oficial RLS: só mostra ativo=true — admin não verá registros inativos
  4. useVariantesGravacao INSERT envia colunas inexistentes — PostgREST rejeitará, mas hook é código morto (0 consumers)

Rollback

Reverter alterações em rest-native.ts e rpc-native.ts. Nenhuma migração de DB.


Generated by Claude Code


Summary by cubic

Fix broken data access by resolving ghost table aliases and adding safe RPC fallbacks to prevent crashes. Enable WRITE support for price tables and related tables.

  • Bug Fixes

    • Map customization_price_tables and tecnica_gravacao_variante to tabela_preco_gravacao_oficial.
    • Fix view alias v_products_without_videosv_products_without_video.
    • Return safe values for 6 NOT_IN_DB RPCs (including fn_get_customization_price_v2) to avoid crashes.
  • New Features

    • Allow WRITE to tabela_preco_gravacao_oficial, tabela_preco_gravacao_oficial_faixa, tecnicas_gravacao, tags, and alias tecnica_gravacao_variante.
    • Add PT→EN column mapping, row projection, and search on nome for tabela_preco_gravacao_oficial to keep existing callers working.

Written for commit bcf4925. Summary will update on new commits.

Review in cubic

@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

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

Project Deployment Actions Updated (UTC)
we-dream-big Error Error May 31, 2026 8:00pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 31, 2026

Review Change Stack

Warning

Review limit reached

@adm01-debug, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 36 minutes and 32 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1138236c-db2a-4f99-a049-4f7f334c64fc

📥 Commits

Reviewing files that changed from the base of the PR and between 3d681b1 and bcf4925.

📒 Files selected for processing (2)
  • src/lib/external-db/rest-native.ts
  • src/lib/external-db/rpc-native.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/exciting-wright-xA6by

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

@supabase
Copy link
Copy Markdown

supabase Bot commented May 31, 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 ↗︎.

@adm01-debug adm01-debug marked this pull request as ready for review May 31, 2026 19:57
Copilot AI review requested due to automatic review settings May 31, 2026 19:57
…WRITE tables

ETAPA 5: customization_price_tables → tabela_preco_gravacao_oficial (17 refs)
  +TABLE_ALIAS, +COLUMN_ALIASES, +mapRows, +SEARCH_COLUMNS
ETAPA 6: tecnica_gravacao_variante → tabela_preco_gravacao_oficial (9 refs)
  +TABLE_ALIAS, +READ whitelist, +WRITE whitelist
ETAPA 8: fn_get_customization_price_v2 throw → safe return (prevents crash)
  All 6 NOT_IN_DB RPCs now return safe values instead of throwing
ETAPA 9: v_products_without_videos → v_products_without_video (typo alias)
ETAPA 10: +5 WRITE tables (tabela_preco_*, tecnicas_gravacao, tags)

Simulation: 87 scenarios, 0 regressions. All affected features already
returned empty arrays — this restores partial data.
@adm01-debug adm01-debug force-pushed the claude/exciting-wright-xA6by branch from b8a6889 to bcf4925 Compare May 31, 2026 19:58
@adm01-debug adm01-debug merged commit f0509d8 into main May 31, 2026
37 of 46 checks passed
@adm01-debug adm01-debug deleted the claude/exciting-wright-xA6by branch May 31, 2026 20:00
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8a6889f48

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

'product_images', 'product_videos', 'product_materials',
'product_kit_components', 'kit_component_media', 'kit_component_print_areas',
// ── FASE 2 ETAPA 6+10: WRITE para gravação ──
'tecnica_gravacao_variante', // alias → tabela_preco_gravacao_oficial
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Do not write variant mutations into price tables

Adding tecnica_gravacao_variante to the native write whitelist makes invokeExternalDbDelete('tecnica_gravacao_variante', id) and the update/toggle/reorder mutations in src/hooks/gravacao/useVariantesGravacao.ts execute against tabela_preco_gravacao_oficial via WRITE_TABLE_ALIASES. In any UI/admin path that passes a returned variant id, this can delete or update an official price-table row instead of a variant, while inserts/updates also send variant-only columns such as tecnica_gravacao_id/produtos_tipicos that the target table does not define. Keep this table non-write-eligible unless there is a schema-compatible target and payload mapping.

Useful? React with 👍 / 👎.

customization_price_tiers: 'tabela_preco_gravacao_oficial_faixa',
personalization_techniques: 'tecnicas_gravacao',
// ── FASE 2: aliases para tabelas/views fantasma ──
customization_price_tables: 'tabela_preco_gravacao_oficial', // ETAPA 5: 17 refs, bridge → tabela_preco_fornecedores_gravacao (não existe)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Map tier ordering before enabling price-table alias

Once customization_price_tables becomes REST-native, existing callers like fetchPromobrindPriceTables order by tier_1_min_qty; remapOrderByCol does not translate that column, so the native query sends .order('tier_1_min_qty') to tabela_preco_gravacao_oficial, whose documented expected columns do not include any tier_* fields. With the bridge kill-switch off, this PostgREST error is swallowed into an empty result, so advanced price search and any pricing flow using that helper lose all price tables for a selected technique.

Useful? React with 👍 / 👎.

Comment on lines +199 to +203
return {
...row,
table_code: row.codigo_tabela,
table_code_option: row.codigo_tabela,
table_fullcode: row.codigo_tabela,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Populate legacy price tiers before returning tables

For callers such as useTabelasPreco, the new customization_price_tables alias now returns rows from tabela_preco_gravacao_oficial, but this projection only adds table metadata and never reconstructs the legacy min_qty_1..15, price_1..15, and sla_1..15 fields from tabela_preco_gravacao_oficial_faixa. rawToTabelaPrecoTecnica builds its faixas array exclusively from those fields, so these rows produce empty tiers and pricing calculators either throw "Tabela de preço sem faixas configuradas" or show unusable pricing; fetch/join the faixa rows or do not serve this alias to tiered price-table consumers.

Useful? React with 👍 / 👎.

setup_price: row.custo_setup,
handling_price: row.custo_manuseio,
price_by_color: row.cobra_por_cor,
price_by_area: row.usa_faixa_dimensional,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the area-pricing flag in the projection

The legacy table adapters and consumers read price_by_area as the English mirror of cobra_por_area, but this projection fills it from usa_faixa_dimensional instead. In pricing/technique flows that rely on precoPorArea or price_by_area to decide whether a technique charges by area, rows whose cobra_por_area is true but usa_faixa_dimensional is false/absent are reported as not area-priced, hiding the area-pricing controls and producing the wrong pricing metadata; mirror cobra_por_area here and expose dimensional support separately if needed.

Useful? React with 👍 / 👎.

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.

3 participants