fix(db): backfill 4 orphan migration versions to repair prod integration#334
Conversation
These 4 versions were applied to production via MCP apply_migration but their files were never committed, so the Supabase->prod integration on every main commit failed with "Remote migration versions not found in local migrations directory" (history mismatch): 20260525005350 colapso_fase5_smoke_tests_mensal_history_v2 20260525005426 colapso_fase5_smoke_tests_fix_emoji_parser 20260525005954 colapso_fase5_kill_switch_rollout_gradual 20260525021830 restore_set_quote_number_trigger Back-filled verbatim from production's schema_migrations.statements (same version+name), so the repo ledger matches prod. Content is idempotent (CREATE ... IF NOT EXISTS / OR REPLACE / DROP ... IF EXISTS) for clean replay. https://claude.ai/code/session_01MBTzmQYmrgwLnwfxRS3PNU
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughQuatro migrações Supabase entregam um novo sistema de histórico de smoke tests com automação mensal, correção de parser emoji para resultados de testes, mecanismo de rollout gradual para kill switches, e restauração de um trigger de auto-geração de números de cotação. ChangesSmoke Tests Monthly History
Kill Switch Gradual Rollout
Quote Number Trigger Restore
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds/repairs several Supabase Postgres migrations to restore quote inserts, add gradual kill-switch rollout logic, and improve smoke-test persistence/reporting.
Changes:
- Restores the
set_quote_numbertrigger to auto-populatepublic.quotes.quote_numberon insert. - Introduces gradual (bucketed) kill-switch rollout via
rollout_percentageandfn_should_apply_kill_switch. - Adds smoke-test run history persistence plus views, then adjusts parsing to handle emoji-prefixed results.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| supabase/migrations/20260525021830_restore_set_quote_number_trigger.sql | Recreates trigger to populate quote_number on insert. |
| supabase/migrations/20260525005954_colapso_fase5_kill_switch_rollout_gradual.sql | Adds rollout percentage + routing function for gradual kill-switch application. |
| supabase/migrations/20260525005426_colapso_fase5_smoke_tests_fix_emoji_parser.sql | Updates smoke-test aggregation/views to parse emoji-prefixed results. |
| supabase/migrations/20260525005350_colapso_fase5_smoke_tests_mensal_history_v2.sql | Creates smoke-test run table/RLS, wrapper function, views, and cron jobs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| -- Hash determinístico → bucket 0-99 | ||
| -- Mesmo bucket_key sempre cai no mesmo bucket (estabilidade entre reloads) | ||
| v_bucket := abs(hashtext(coalesce(p_bucket_key, 'anonymous')) % 100); |
| -- 3) Validar: switch atual está enabled=true, então sempre retorna false | ||
| SELECT | ||
| public.fn_should_apply_kill_switch('edge_external_db_bridge', 'test-user-1') AS rollout_test_1, | ||
| public.fn_should_apply_kill_switch('edge_external_db_bridge', 'test-user-2') AS rollout_test_2, | ||
| public.fn_should_apply_kill_switch('non_existent_switch', 'anyone') AS unknown_switch; |
| ALTER TABLE public.smoke_tests_runs ENABLE ROW LEVEL SECURITY; | ||
|
|
||
| DROP POLICY IF EXISTS smoke_tests_runs_read_admin ON public.smoke_tests_runs; | ||
| CREATE POLICY smoke_tests_runs_read_admin | ||
| ON public.smoke_tests_runs FOR SELECT | ||
| TO authenticated | ||
| USING (is_admin_or_above((SELECT auth.uid()))); | ||
|
|
||
| GRANT SELECT ON public.smoke_tests_runs TO authenticated; |
| GRANT USAGE, SELECT ON SEQUENCE public.smoke_tests_runs_id_seq TO authenticated; | ||
|
|
||
| -- Wrapper SECURITY INVOKER (default) | ||
| CREATE OR REPLACE FUNCTION public.fn_run_and_persist_smoke_tests() |
| INSERT INTO public.smoke_tests_runs ( | ||
| ran_at, test_name, test_category, result, details, duration_ms | ||
| ) VALUES ( | ||
| v_ran_at, r.test_name, r.test_category, r.result, r.details, r.duration_ms | ||
| ); |
|
|
||
| -- Grant para admin/postgres executar | ||
| GRANT EXECUTE ON FUNCTION public.fn_run_and_persist_smoke_tests() TO postgres; | ||
| GRANT EXECUTE ON FUNCTION public.fn_run_and_persist_smoke_tests() TO authenticated; |
| IF upper(r.result) = 'PASS' THEN v_passed := v_passed + 1; | ||
| ELSIF upper(r.result) = 'FAIL' THEN | ||
| v_failed := v_failed + 1; | ||
| v_failed_tests := array_append(v_failed_tests, r.test_name); | ||
| ELSIF upper(r.result) IN ('WARN','WARNING') THEN v_warned := v_warned + 1; | ||
| END IF; |
| CASE upper(r.result) | ||
| WHEN 'FAIL' THEN 1 WHEN 'WARN' THEN 2 WHEN 'PASS' THEN 3 ELSE 4 | ||
| END, r.test_name; |
| count(*) FILTER (WHERE upper(result) = 'PASS') AS passed, | ||
| count(*) FILTER (WHERE upper(result) = 'FAIL') AS failed, | ||
| count(*) FILTER (WHERE upper(result) IN ('WARN','WARNING')) AS warned, |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9429982d4e
ℹ️ 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".
|
|
||
| -- Wrapper SECURITY INVOKER (default) | ||
| CREATE OR REPLACE FUNCTION public.fn_run_and_persist_smoke_tests() | ||
| RETURNS TABLE( |
There was a problem hiding this comment.
Drop function before redefining return type
This migration introduces public.fn_run_and_persist_smoke_tests() as RETURNS TABLE (...), but a later migration already in the repo (supabase/migrations/20260525063000_restore_smoke_test_observability_contract.sql) redefines the same zero-argument function as RETURNS void using CREATE OR REPLACE FUNCTION. PostgreSQL does not allow CREATE OR REPLACE to change an existing function’s return type, so a clean migration replay will now fail when it reaches that later file with cannot change return type of existing function.
Useful? React with 👍 / 👎.
| DROP POLICY IF EXISTS smoke_tests_runs_read_admin ON public.smoke_tests_runs; | ||
| CREATE POLICY smoke_tests_runs_read_admin | ||
| ON public.smoke_tests_runs FOR SELECT | ||
| TO authenticated | ||
| USING (is_admin_or_above((SELECT auth.uid()))); |
There was a problem hiding this comment.
Add INSERT policy for smoke_tests_runs before INVOKER writes
RLS is enabled on public.smoke_tests_runs, but this migration only creates a FOR SELECT policy for authenticated. The same migration defines fn_run_and_persist_smoke_tests() as SECURITY INVOKER and grants it to authenticated, and that function performs INSERT into smoke_tests_runs; without a matching FOR INSERT policy, authenticated callers (including admin dashboard users) will hit an RLS violation and the RPC cannot persist results.
Useful? React with 👍 / 👎.
| TO authenticated | ||
| USING (is_admin_or_above((SELECT auth.uid()))); | ||
|
|
||
| GRANT SELECT ON public.smoke_tests_runs TO authenticated; |
There was a problem hiding this comment.
Grant INSERT on smoke_tests_runs for invoker RPC
The migration grants only SELECT on public.smoke_tests_runs to authenticated, but fn_run_and_persist_smoke_tests() is SECURITY INVOKER and executes INSERT into that table. Even if RLS policies are corrected, authenticated users invoking this RPC will still fail with table-permission errors until INSERT privilege is granted.
Useful? React with 👍 / 👎.
Objetivo
Reparar a integração Supabase→produção no
main, que falha a cada commit com "Remote migration versions not found in local migrations directory".Causa
4 versões foram aplicadas em produção via MCP
apply_migration(sessão paralela "colapso fase5" + restore de trigger) sem commitar os arquivos. A integração, ao comparar oschema_migrationsde prod com o repo, encontra essas versões sem arquivo local → history mismatch → MIGRATIONS: FAILED.20260525005350202605250054262026052500595420260525021830Mudança
Back-fill verbatim dos 4 arquivos a partir de
supabase_migrations.schema_migrations.statementsde produção (mesmos version+name), para o ledger do repo casar com prod. O conteúdo é idempotente (CREATE ... IF NOT EXISTS/OR REPLACE/DROP ... IF EXISTS), seguro para replay limpo. Nenhuma alteração em produção — só reflete no repo o que já rodou lá.Após o merge, a integração deve parar de acusar "Remote migration versions not found". (Se restar uma 2ª camada — migrations locais pendentes que falhem ao aplicar em prod — investigo em seguida.)
https://claude.ai/code/session_01MBTzmQYmrgwLnwfxRS3PNU
Generated by Claude Code
Summary by cubic
Backfilled four orphan Supabase migration files so the prod integration stops failing on main. This aligns the repo’s migration history with production without changing prod state.
Written for commit 9429982. Summary will update on new commits. Review in cubic
Summary by CodeRabbit
New Features
Bug Fixes