Skip to content

fix(db): rename schema v1_owners_club → v10_owners_club [DB-005 Critical] - #66

Open
UNIFY-MC wants to merge 1 commit into
mainfrom
feat/db-005-rename-v10-owners-club
Open

fix(db): rename schema v1_owners_club → v10_owners_club [DB-005 Critical]#66
UNIFY-MC wants to merge 1 commit into
mainfrom
feat/db-005-rename-v10-owners-club

Conversation

@UNIFY-MC

Copy link
Copy Markdown
Owner

Sumário

  • Rename schema v1_owners_clubv10_owners_club no V1 Core Hub (hkmvszkpxjbxmnixzqbl) — corrige naming conflituante com naming canónico V1-V10 (Owners Club é V10, horizontal de fidelidade, não V1 Core Hub)
  • Actualiza view externa public.v_ofertas (drop + create com nova referência — PostgreSQL não actualiza view definitions automaticamente após rename)
  • Reconfigura pgrst.db_schemas da role authenticator substituindo v1_owners_club por v10_owners_club + NOTIFY pgrst (PostgREST schema exposure conforme ADR-V2-002)

Contexto

DB-005 brownfield Critical (technical-debt-assessment.md, 2026-05-23). Schema com nome errado criava risco real: queries auditivas ou de IAM com WHERE schema_name LIKE 'v1%' apanhariam o Owners Club por engano, e tooling cross-vertical podia assumir wrongly que estes dados pertencem ao Core Hub.

Audit pré-migration (2026-05-24)

Objecto Contagem Notas
Tabelas 3 ofertas (6 rows), pontos_historico (0), resgates (0)
Triggers 9 auto-RI + trg_ofertas_updated_at
Policies RLS 4 preservadas pelo ALTER SCHEMA
FKs internas 1 resgates → ofertas (preservada)
Funções/RPCs com referência ao schema 0 zero dependências externas
Views externas 1 public.v_ofertas (SELECT directo) — actualizada na PARTE 2
Linha em pgrst.db_schemas 1 actualizada na PARTE 3

Estrutura da migration (4 partes)

Parte Comando Efeito
1 ALTER SCHEMA v1_owners_club RENAME TO v10_owners_club renomeia schema + arrastra tabelas, indexes, triggers, policies, FKs automaticamente
2 DROP VIEW public.v_ofertas + CREATE VIEW … FROM v10_owners_club.ofertas + GRANT SELECT TO anon, authenticated actualiza view externa (Postgres não actualiza view defs após rename)
3 ALTER ROLE authenticator SET pgrst.db_schemas = '… v10_owners_club …' reconfigura PostgREST exposed schemas
4 NOTIFY pgrst, 'reload config' recarrega config do pod PostgREST

Validação pós-apply (6 queries — todas PASS)

Verificação Resultado
v10_owners_club existe em pg_namespace PASS
v1_owners_club removido de pg_namespace PASS
3 tabelas preservadas dentro do novo schema PASS
SELECT COUNT(*) FROM v10_owners_club.ofertas 6 (preservado)
SELECT COUNT(*) FROM public.v_ofertas (view reapontada) 6
Policies RLS: 4 / FKs: 3 PASS

Zero perda de dados. Zero perda de policies. View externa funcional.

Rollback

Reversão trivial — documentada no header de supabase/migrations/202605240200_rename_v10_owners_club.sql:

  1. ALTER SCHEMA v10_owners_club RENAME TO v1_owners_club
  2. Recriar public.v_ofertas apontando para v1_owners_club.ofertas
  3. Reverter pgrst.db_schemas + NOTIFY pgrst

Migration idempotente: rerunning falha gracefully (schema já não existe).

Ficheiros tocados

  • supabase/migrations/202605240200_rename_v10_owners_club.sql (novo, 113 linhas)
  • CLAUDE.md (6 linhas) — exemplo SQL canónico pgrst.db_schemas actualizado + nota DB-005

Risk assessment

Low risk:

  • Migration já aplicada e validada em V1 Core Hub (Supabase remoto) antes deste PR
  • V1 Core Hub está vazio (sem clientes em produção) — Owners Club ainda não consumido por nenhuma vertical
  • Zero código aplicacional referencia v1_owners_club (Owners Club é V10 futura)
  • Nenhum impacto em V2 produção (prataowners.pt) — schema isolado em outro projecto Supabase

Refs

  • DB-005 — docs/brownfield-discovery/technical-debt-assessment.md
  • Naming canónico V1-V10 — CLAUDE.md (linhas 11-22)
  • PostgREST schema exposure — .claude/strategy/adrs/ADR-V2-002-postgrest-schema-exposure.md

🤖 Generated with Claude Code

…cal]

DB-005 brownfield Critical (2026-05-23): schema com nome errado conforme naming
canónico V1-V10 do CLAUDE.md. Owners Club = V10 (horizontal de fidelidade),
não V1 (Core Hub). Naming conflituante criava risco de queries WHERE schema
LIKE 'v1%' apanharem o schema errado.

AUDIT pré-migration (2026-05-24):
  - 3 tabelas: ofertas (6 rows), pontos_historico (0), resgates (0)
  - 9 triggers (auto-RI + trg_ofertas_updated_at)
  - 4 policies RLS
  - 0 funções/RPCs com 'v1_owners_club' em prosrc — ZERO dependências externas
  - 1 view externa: public.v_ofertas (SELECT direto de v1_owners_club.ofertas)
  - 1 FK interna (resgates → ofertas) — preservada

MIGRATION 202605240200_rename_v10_owners_club.sql aplicada em V1 Core Hub:
  PARTE 1: ALTER SCHEMA v1_owners_club RENAME TO v10_owners_club
           → renomeia tabelas + indexes + triggers + policies + FKs automaticamente
  PARTE 2: DROP VIEW public.v_ofertas + CREATE VIEW com referência nova
           → PostgreSQL NÃO actualiza view definitions automaticamente
           → GRANT SELECT TO anon, authenticated re-aplicado
  PARTE 3: ALTER ROLE authenticator SET pgrst.db_schemas com v10_owners_club
           → substitui v1_owners_club na lista PostgREST exposed schemas
  PARTE 4: NOTIFY pgrst, 'reload config'

VALIDATION pós-apply (6 queries — todas PASS):
  - schemas: v10_owners_club existe, v1_owners_club desapareceu
  - 3 tabelas preservadas
  - ofertas_count: 6 ✓
  - public.v_ofertas count: 6 ✓
  - policies_count: 4 ✓
  - fks_count: 3 ✓

CLAUDE.md actualizado:
  - Exemplo SQL canónico pgrst.db_schemas: v1_owners_club → v10_owners_club
  - Nota DB-005 explica rename + preservação dados

Reversão trivial documentada no header da migration.
Migration idempotente: rerunning falha gracefully (schema já não existe).

Refs: DB-005 (technical-debt-assessment.md), naming canónico V1-V10 (CLAUDE.md)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel

vercel Bot commented May 24, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
proptech-agentic-ops Error Error May 24, 2026 8:48am
proptech-v5-alpha Error Error May 24, 2026 8:48am

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