Skip to content

fix(db): guard DDL on orphan tables for clean replay (granular)#313

Merged
adm01-debug merged 1 commit into
mainfrom
claude/replay-drift-tables
May 25, 2026
Merged

fix(db): guard DDL on orphan tables for clean replay (granular)#313
adm01-debug merged 1 commit into
mainfrom
claude/replay-drift-tables

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

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

Objetivo

Continuação granular (de baixo risco) da limpeza de drift de replay — classe tabelas órfãs. Após você considerar o baseline arriscado, seguimos por correções pontuais que não tocam produção.

Contexto

Funções (636), enums (5) e guards dos batches t37 já estão em main (#298, #305). O replay agora avança até onda13 e falha em audit_log_gravacao (tabela criada fora de migration). Auditoria mostrou que só 5 migrations pós-baseline fazem DDL em tabelas órfãs:

  • t38 → já auto-guardado (IF EXISTS).
  • 20260519163704 → falso positivo (tags é coluna de products).
  • 3 bloqueios reais corrigidos aqui.

Mudança (guards, sem reconstruir tabelas, sem tocar prod)

  • onda13: CREATE POLICY em audit_log_gravacao/seo_audit_log → guardado por to_regclass(...) IS NOT NULL.
  • onda19: DROP/CREATE TRIGGER + ALTER em kit_component_print_areas, supplier_technique_mappings, tabela_preco_gravacao_oficial, variant_supplier_sources + a view que lê tabela_preco_gravacao_oficial(_faixa) → guardados por EXCEPTION WHEN undefined_table. ALTERs de tabelas existentes (quotes, etc.) ficam intactas.
  • harden_anon_graphql_exposure: todos os REVOKE ... FROM anon guardados (idempotente; no-op quando a tabela está ausente).

Em produção (onde as tabelas existem) o comportamento é idêntico; num replay limpo, vira no-op em vez de abortar.

Validação

Vou monitorar o preview (replay fresco) e iterar granular caso surja a próxima classe (views/policies/triggers órfãos remanescentes).

https://claude.ai/code/session_01MBTzmQYmrgwLnwfxRS3PNU


Generated by Claude Code


Summary by cubic

Guards DDL in three migrations so a clean DB replay doesn’t fail on orphan tables created out-of-band. Production behavior is unchanged; on fresh replay these statements no-op instead of aborting.

  • Bug Fixes
    • onda13: Wrapped CREATE POLICY on audit_log_gravacao and seo_audit_log with to_regclass(...) IS NOT NULL.
    • onda19: Wrapped DROP/CREATE TRIGGER and ALTERs for kit_component_print_areas, supplier_technique_mappings, tabela_preco_gravacao_oficial, variant_supplier_sources, and view v_audit_paradoxos_gravacao in DO blocks with EXCEPTION WHEN undefined_table; left other ALTERs intact.
    • harden_anon_graphql_exposure: Wrapped all REVOKE ... FROM anon in guarded DO blocks; no-op when tables are absent.

Written for commit ba5a589. Summary will update on new commits. Review in cubic

Audit found only 5 post-baseline migrations doing DDL on tables that exist in
prod but were never created by a migration (created out-of-band). Of those,
t38 already self-guards (IF EXISTS) and 20260519163704 was a false positive
(`tags` is a column of products). The 3 real blockers are guarded so a fresh
replay no-ops on the missing table instead of aborting; production (where the
tables exist) behaves identically:

- onda13: CREATE POLICY on audit_log_gravacao / seo_audit_log -> wrapped in
  to_regclass(...) IS NOT NULL guards.
- onda19: DROP/CREATE TRIGGER + ALTER on kit_component_print_areas,
  supplier_technique_mappings, tabela_preco_gravacao_oficial,
  variant_supplier_sources, and the view reading tabela_preco_gravacao_oficial
  -> wrapped in EXCEPTION WHEN undefined_table guards (non-orphan ALTERs left
  intact).
- harden_anon_graphql_exposure: all REVOKE ... FROM anon wrapped (idempotent;
  no-op when the table is absent).

https://claude.ai/code/session_01MBTzmQYmrgwLnwfxRS3PNU
@vercel
Copy link
Copy Markdown

vercel Bot commented May 24, 2026

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

Project Deployment Actions Updated (UTC)
we-dream-big Ready Ready Preview, Comment May 24, 2026 9:55pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

Warning

Review limit reached

@adm01-debug, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 5 reviews of capacity. Refill in 18 minutes and 32 seconds.

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

⌛ How to resolve this issue?

After more review capacity refills, 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 have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1fb51166-dde7-4503-92fd-7caec45d37c4

📥 Commits

Reviewing files that changed from the base of the PR and between 3b74653 and ba5a589.

📒 Files selected for processing (3)
  • supabase/migrations/20260514220543_onda13_rls_audit_logs_admin_only.sql
  • supabase/migrations/20260515030000_onda19_numeric_precision.sql
  • supabase/migrations/20260524210100_harden_anon_graphql_exposure.sql
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/replay-drift-tables

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

@supabase
Copy link
Copy Markdown

supabase Bot commented May 24, 2026

This pull request has been ignored for the connected project doufsxqlfjyuvxuezpln due to reaching the limit of concurrent preview branches.
Go to Project Integrations Settings ↗︎ if you wish to update this limit.


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

@adm01-debug adm01-debug marked this pull request as ready for review May 25, 2026 00:27
Copilot AI review requested due to automatic review settings May 25, 2026 00:27
@adm01-debug adm01-debug merged commit 8268480 into main May 25, 2026
31 of 39 checks passed
@adm01-debug adm01-debug review requested due to automatic review settings May 25, 2026 00:50
@adm01-debug adm01-debug deleted the claude/replay-drift-tables branch May 25, 2026 18:17
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