fix(rest-native): Phase 2 — resolve ghost aliases + safe RPC stubs + WRITE tables#548
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
…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.
b8a6889 to
bcf4925
Compare
There was a problem hiding this comment.
💡 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 👍 / 👎.
| return { | ||
| ...row, | ||
| table_code: row.codigo_tabela, | ||
| table_code_option: row.codigo_tabela, | ||
| table_fullcode: row.codigo_tabela, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Continuação da Fase 1 (PR #546). Kill-switch
edge_external_db_bridgeOFF desde 2026-05-30.customization_price_tables→ alias paratabela_preco_gravacao_oficial(17 callers). +TABLE_ALIAS, +COLUMN_ALIASES_BY_TABLE (mapeamento EN→PT), +mapRows (projeção EN nos resultados), +SEARCH_COLUMNStecnica_gravacao_variante→ alias paratabela_preco_gravacao_oficial(9 refs). +READ whitelist, +WRITE whitelist, +WRITE_TABLE_ALIASNOT_IN_DBno dispatch table mudados dethrowpara retorno seguro — previne crash emfn_get_customization_price_v2(os 2 🔴 da simulação)v_products_without_videos→ alias parav_products_without_video(typo fix)tabela_preco_gravacao_oficial,tabela_preco_gravacao_oficial_faixa,tecnicas_gravacao,tags,tecnica_gravacao_varianteContagens finais
REST_NATIVE_SAFE_TABLESTABLE_ALIASESWRITE_TABLE_ALIASESREST_NATIVE_WRITE_TABLESValidação
Riscos conhecidos (pré-existentes, não causados por este PR)
customization_price_tablescallers esperamprice_1..5/min_qty_1..5(vêm de tabela separada_faixa) — retornarão nulluseTechniquePricing.ts:65usasupabase.from('customization_price_tables')direto — não passa pelo alias (continua falhando)tabela_preco_gravacao_oficialRLS: só mostraativo=true— admin não verá registros inativosuseVariantesGravacaoINSERT envia colunas inexistentes — PostgREST rejeitará, mas hook é código morto (0 consumers)Rollback
Reverter alterações em
rest-native.tserpc-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
customization_price_tablesandtecnica_gravacao_variantetotabela_preco_gravacao_oficial.v_products_without_videos→v_products_without_video.NOT_IN_DBRPCs (includingfn_get_customization_price_v2) to avoid crashes.New Features
tabela_preco_gravacao_oficial,tabela_preco_gravacao_oficial_faixa,tecnicas_gravacao,tags, and aliastecnica_gravacao_variante.nomefortabela_preco_gravacao_oficialto keep existing callers working.Written for commit bcf4925. Summary will update on new commits.