Skip to content

fix(migrations): baseline_sync no-op + placeholder para versão 20250103#222

Merged
adm01-debug merged 4 commits into
mainfrom
claude/code-review-architecture-Rhqo2
May 15, 2026
Merged

fix(migrations): baseline_sync no-op + placeholder para versão 20250103#222
adm01-debug merged 4 commits into
mainfrom
claude/code-review-architecture-Rhqo2

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

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

Problema

A migration 20250101000000_baseline_sync.sql mergeada no PR #192 continha um INSERT massivo em supabase_migrations.schema_migrations. Isso causa duplicate key violations em qualquer novo Supabase Preview Branch porque o migration runner:

  1. Pre-computa a lista completa de migrations pendentes antes de executar qualquer migration
  2. Executa baseline_sync → insere versões (ex: 20251214183243) em schema_migrations
  3. Tenta inserir seu próprio registro para 20251214183243DUPLICATE KEY 💥

Além disso, a versão 20250103 (8 dígitos) foi registrada em schema_migrations da produção sem um arquivo local correspondente, causando erro Remote migration versions not found in local migrations directory.

Solução

Fix 1 — 20250101000000_baseline_sync.sql → no-op

As 395 versões históricas foram inseridas diretamente em supabase_migrations.schema_migrations da produção via MCP execute_sql com ON CONFLICT DO NOTHING. A versão 20250101000000 agora está registrada em produção, portanto novos previews herdam e pulam este arquivo.

Fix 2 — 20250103_placeholder.sql

Arquivo placeholder de 4 linhas para satisfazer o check do Supabase CLI de versão local ↔ remota para a versão 20250103.

Impacto

  • Novos Supabase Preview Branches não terão mais duplicate key violations
  • Nenhuma alteração funcional de schema

Checklist

  • baseline_sync convertido para SELECT 1 (no-op)
  • Placeholder 20250103_placeholder.sql adicionado
  • 395 versões históricas já inseridas em produção via MCP (ON CONFLICT DO NOTHING)

https://claude.ai/code/session_01EwUnLoFHJ1UF5jzLpwME3x


Generated by Claude Code


Summary by cubic

Make baseline_sync a no-op and add a placeholder migration to stop duplicate key errors in Supabase Preview Branches. Also fix publication-drop syntax, resolve a duplicate migration version, and relocate the migrations README with a CI allowlist update; no schema changes.

  • Bug Fixes
    • Convert 20250101000000_baseline_sync.sql to no-op and add 20250103_placeholder.sql to satisfy the CLI version check and prevent duplicate key errors.
    • 20260405222509_*.sql, 20260411210929_*.sql: replace invalid ALTER PUBLICATION ... DROP TABLE IF EXISTS with a conditional DO $$ using pg_publication_tables.
    • Rename 20260515040000_fix_profiles_user_id_definitive.sql20260515040001_... to resolve a duplicate version conflict.
    • Move README out of migrations (supabase/migrations/README.mdsupabase/MIGRATIONS_README.md) and update CI guard allowlist path in scripts/check-no-db-push.mjs to prevent Supabase CLI aborts.

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

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Melhorias na compatibilidade e confiabilidade das migrações de banco de dados com Supabase.
    • Ajustes na configuração de replicação em tempo real para maior estabilidade.
  • Chores

    • Otimizações em verificações internas de migração.

Review Change Stack

1. Convert 20250101000000_baseline_sync.sql to no-op SELECT 1.
   The INSERT approach was incompatible with Supabase's migration runner:
   it pre-computes the full pending list before executing any migration,
   so inserting versions via baseline_sync and then having the runner try
   to INSERT its own record caused duplicate key violations.
   All historical versions were inserted directly into production's
   schema_migrations via MCP execute_sql (ON CONFLICT DO NOTHING), so
   this file is now skipped by new previews (version already applied).

2. Add 20250103_placeholder.sql for the bare 8-digit version "20250103"
   that was recorded in production schema_migrations. Without a matching
   local file the Supabase CLI branch-action errors with "Remote migration
   versions not found in local migrations directory".

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

vercel Bot commented May 15, 2026

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

Project Deployment Actions Updated (UTC)
promo-gifts Error Error May 15, 2026 1:04pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 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: b88e99df-0d27-49d7-a266-42c3ce7e252b

📥 Commits

Reviewing files that changed from the base of the PR and between 840f2ef and ada5bfb.

📒 Files selected for processing (7)
  • scripts/check-no-db-push.mjs
  • supabase/MIGRATIONS_README.md
  • supabase/migrations/20250101000000_baseline_sync.sql
  • supabase/migrations/20250103_placeholder.sql
  • supabase/migrations/20260405222509_610eaeb7-2cad-4cf8-aaf9-f4a4be5b9e55.sql
  • supabase/migrations/20260411210929_9736ba78-4ddb-466f-b54d-c1c5f9d0d35f.sql
  • supabase/migrations/20260515040001_fix_profiles_user_id_definitive.sql

Walkthrough

O PR consolida ajustes operacionais em migrações Supabase e CI: allowlist do script de detecção é expandida para ignorar documentação de migrações, baseline migration é convertida para no-op, placeholder de versão é adicionado, e dois drops de publication ganham proteção condicional contra estados variáveis do banco.

Changes

Ajustes de migração Supabase e CI

Layer / File(s) Sumário
Atualização de allowlist do check de CI
scripts/check-no-db-push.mjs
supabase/MIGRATIONS_README.md é adicionada ao ALLOWLIST para evitar que documentação mencionando supabase db push dispare o check de CI.
Migrations de baseline e placeholder
supabase/migrations/20250101000000_baseline_sync.sql, supabase/migrations/20250103_placeholder.sql
Baseline migration muda de insertor histórico de versões para no-op comentado; nova migration de placeholder 20250103 é adicionada como marcador de versão para o Supabase CLI, ambas evitando incompatibilidades de runner.
Drops condicionais de publication
supabase/migrations/20260405222509_610eaeb7-2cad-4cf8-aaf9-f4a4be5b9e55.sql, supabase/migrations/20260411210929_9736ba78-4ddb-466f-b54d-c1c5f9d0d35f.sql
Ambas as migrations protegem remoção de public.workspace_notifications da supabase_realtime publication com verificação IF EXISTS em pg_publication_tables, prevenindo erros de operação em bancos com diferentes estados de registro.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutos

Possibly related issues

  • adm01-debug/Promo_Gifts#153: O allowlist de supabase/MIGRATIONS_README.md implementa diretamente a mitigação descrita (usar README para avisar contra supabase db push).

Possibly related PRs

✨ 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 claude/code-review-architecture-Rhqo2

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

@supabase
Copy link
Copy Markdown

supabase Bot commented May 15, 2026

Updates to Preview Branch (claude/code-review-architecture-Rhqo2) ↗︎

Deployments Status Updated
Database Fri, 15 May 2026 13:09:22 UTC
Services Fri, 15 May 2026 13:09:22 UTC
APIs Fri, 15 May 2026 13:09:22 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Fri, 15 May 2026 13:09:23 UTC
Migrations Fri, 15 May 2026 13:11:41 UTC
Seeding ⏸️ Fri, 15 May 2026 13:09:15 UTC
Edge Functions ⏸️ Fri, 15 May 2026 13:09:15 UTC

❌ Branch Error • Fri, 15 May 2026 13:11:42 UTC

ERROR: column "created_by" does not exist (SQLSTATE 42703)
At statement: 60
DO $$
BEGIN
  ALTER POLICY "ck_insert_self" ON public."custom_kits" WITH CHECK (((user_id = (SELECT auth.uid())) OR (created_by = (SELECT auth.uid()))));
EXCEPTION WHEN undefined_table OR undefined_object OR undefined_function THEN NULL;
END $$

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

- ALTER PUBLICATION ... DROP TABLE IF EXISTS é sintaxe inválida no
  PostgreSQL — substituído por bloco DO $$ com verificação em
  pg_publication_tables para idempotência segura (afeta migrations
  20260405222509 e 20260411210929)

- Renomear 20260515040000_fix_profiles_user_id_definitive.sql para
  20260515040001 para eliminar conflito de versão duplicada com
  20260515040000_onda19_followup_track_functions_fix_view_security.sql

https://claude.ai/code/session_01EwUnLoFHJ1UF5jzLpwME3x
Supabase CLI emite "Skipping migration README.md" e falha
imediatamente no run incremental do CI. O arquivo não segue
o padrão '<timestamp>_name.sql' e parece causar abort prematuro.
Movido para supabase/MIGRATIONS_README.md.

https://claude.ai/code/session_01EwUnLoFHJ1UF5jzLpwME3x
…nho do README

O README de migrations foi movido de supabase/migrations/README.md para
supabase/MIGRATIONS_README.md para corrigir falha do Supabase Preview CI.
Atualiza a allowlist do check-no-db-push.mjs para refletir o novo caminho.

https://claude.ai/code/session_01EwUnLoFHJ1UF5jzLpwME3x
@adm01-debug adm01-debug marked this pull request as ready for review May 15, 2026 14:04
Copilot AI review requested due to automatic review settings May 15, 2026 14:04
@adm01-debug adm01-debug merged commit 611c3eb into main May 15, 2026
19 of 24 checks passed
@adm01-debug adm01-debug deleted the claude/code-review-architecture-Rhqo2 branch May 15, 2026 14:04
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 7 files

Re-trigger cubic

Copy link
Copy Markdown

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

Resolves Supabase Preview Branch failures caused by PR #192's baseline_sync migration (which inserted historical versions and produced duplicate-key errors) and a missing local file for the remote-only 20250103 version. The fix neutralizes the bulk INSERT (replacing it with a no-op), adds a placeholder file for the orphan 20250103 version, hardens two prior ALTER PUBLICATION ... DROP TABLE IF EXISTS migrations (invalid syntax) into idempotent DO blocks, renames a duplicated 20260515040000_* migration to 20260515040001_*, and relocates the migrations README to avoid being picked up by Supabase CLI (with a corresponding ALLOWLIST update in the db push guard).

Changes:

  • Make 20250101000000_baseline_sync.sql a no-op and add 20250103_placeholder.sql to satisfy the CLI local↔remote version check.
  • Replace invalid ALTER PUBLICATION ... DROP TABLE IF EXISTS with conditional DO $$ blocks using pg_publication_tables (in 20260405222509_* and 20260411210929_*).
  • Move supabase/migrations/README.mdsupabase/MIGRATIONS_README.md and update the check-no-db-push allowlist; rename profiles fix migration to 20260515040001_*.

Reviewed changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
supabase/migrations/20250101000000_baseline_sync.sql Strip 395-row INSERT; keep file as SELECT 1 no-op to avoid duplicate-key on previews.
supabase/migrations/20250103_placeholder.sql New 4-line placeholder so CLI accepts the remote-only 20250103 version.
supabase/migrations/20260405222509_*.sql Wrap publication drop in DO $$ with pg_publication_tables guard (valid PG syntax).
supabase/migrations/20260411210929_*.sql Same idempotent guard for the workspace_notifications drop.
supabase/migrations/20260515040001_fix_profiles_user_id_definitive.sql Renamed from 20260515040000_* to resolve duplicate version with 20260515040000_onda19_*.
supabase/MIGRATIONS_README.md New location for the README outside supabase/migrations/ to avoid CLI ingestion.
scripts/check-no-db-push.mjs Update allowlist to the new README path.

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

'docs/redeploy/REDEPLOY-FASE2-EXECUTION-LOG.md',
'docs/redeploy/REDEPLOY-FASE3-FINAL.md',
'supabase/migrations/README.md',
'supabase/MIGRATIONS_README.md',
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: ada5bfb41a

ℹ️ 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".

Comment on lines +1 to +3
-- Placeholder for version 20250103.
-- This version was recorded in production schema_migrations by baseline sync.
-- File exists only to satisfy Supabase CLI local/remote version check.
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 Add the missing 20251227 placeholder

This placeholder fixes the remote/local check for 20250103, but the baseline list removed in this same commit also included a bare remote version 20251227. The current migrations directory only has 202512271... timestamped files, which are different versions, so any Supabase command that compares production schema_migrations against local files will still fail with a missing local migration for 20251227 after the production baseline insert described in the commit.

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