Skip to content

fix(cutover): make pg17 stageA idempotent (clean v17 db + pg16 guard)#28

Merged
valvesss merged 1 commit into
mainfrom
fix/pg17-stagea-idempotent
Jul 8, 2026
Merged

fix(cutover): make pg17 stageA idempotent (clean v17 db + pg16 guard)#28
valvesss merged 1 commit into
mainfrom
fix/pg17-stagea-idempotent

Conversation

@valvesss

@valvesss valvesss commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Contexto

Achado ao validar E2E o cli cutover no logcheck (1ª execução real do comando — stageA/B/rollback todos verdes). O único gap de código que a validação expôs.

Problema

stageA criava o db no v17 só quando ausente, depois fazia pg_restore por cima. Se db_<name> já existe no v17 (um stageA anterior, ou um dump pré-staged à mão), o restore bate em objeto duplicado → pg_restore exit≠0 → stageA falha. No logcheck o db_logcheck já existia no v17 (Stage A manual de 02/jul) e tive que dropar à mão antes.

Morde também: zyramed (tem Stage A manual antigo no v17) e qualquer re-run pós-falha parcial.

Fix

  • stageA passo 3 agora drop+recreate do db v17 a cada run (from template0) → idempotente e re-runnable.
  • Guard: recusa stageA se o projeto já está em pg17 (senão sobrescreveria o db vivo do v17 com um snapshot stale do pg16). Rollback primeiro se for re-run intencional.
  • Seguro: durante stageA o app serve do pg16, nada vivo depende da cópia v17; WITH (FORCE) só limpa conexão idle solta.

Validação

stageA/stageB/rollback rodados ao vivo no logcheck via cli cutover (39 tabelas row-parity; GoTrue boot limpo no v17; PostgREST servindo v17; rollback drenou v17 a zero). logcheck deixado no baseline pg16.

🤖 Generated with Claude Code

stageA created the v17 db only when absent, then pg_restore'd into it. A
leftover copy (an earlier stageA, or a hand-staged dump) made the restore
fail on duplicate objects — hit live validating the logcheck cutover, where
db_logcheck already existed on v17 from a July-2 hand run and had to be
dropped manually first.

stageA now drops+recreates the v17 db from template0 every run, so it is
cleanly re-runnable (and works for the pre-staged logcheck/zyramed dbs). A
guard refuses stageA when the project is already bound to pg17, so a re-run
can never overwrite a live v17 db with a stale pg16 snapshot — roll back
first. Safe because during stageA the app still serves from pg16; WITH
(FORCE) just clears any idle leftover connection.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@valvesss valvesss merged commit b1c8511 into main Jul 8, 2026
3 checks passed
@valvesss valvesss deleted the fix/pg17-stagea-idempotent branch July 8, 2026 16:01
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.

1 participant