← Back to Pull requests

fix(db): cria user_known_devices.is_trusted, usada pelo front e ausente em produção #3582

Closed
unknown closed this pull request without merging on Nov 14, 2026 20:07 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 07:26 UTC
Author

📋 Descrição

Problema: o botão "Confiar neste dispositivo" falha e o selo "confiável" nunca aparece.

Causa, com evidência:

  • src/hooks/useDeviceDetection.ts:177 grava .update({ is_trusted: true }).

  • KnownDevicesManager.tsx:31,152,176 lê a coluna is_trusted.

  • Em produção, user_known_devices só tem id, user_id, fingerprint, device_name, last_seen_at e created_at (consulta só de leitura em information_schema.columns, 14/11).

  • A migration 20261110024530 da adm01-debug/Promo_Gifts_V4#3390 criava a coluna, mas nunca foi aplicada e não entrou na #3548.
  • Correção: migration 20261114031000 com ALTER TABLE public.user_known_devices ADD COLUMN IF NOT EXISTS is_trusted boolean NOT NULL DEFAULT false.

  • No PG ≥ 11 isso só altera metadado: não reescreve a tabela.

  • A policy existente "Users can manage their own devices" (ALL, auth.uid() = user_id) já cobre o UPDATE. Não há grant novo.
  • 🎯 Tipo de mudança

  • 🐛 fix — correção de bug
  • 🌐 Sistemas afetados

  • Supabase (DB, Edge Functions, RLS, migrations)
  • 🧭 Contratos, impacto e autorizações

  • Contrato tocado: coluna nova user_known_devices.is_trusted, com default false, então nenhuma linha existente muda de comportamento.

  • [AUTORIZAÇÃO BD]: o dono aprovou no chat da sessão Claude em 2026-11-14 ("Eu aprovo todas!"). A migration vai a produção só pelo db-apply-migration.yml.

  • Forward-only e versão única: 20261114031000 não está no ledger.
  • 🧪 Como testar

    1. node scripts/preflight-migration-apply.mjs --version=20261114031000, com o ledger ao vivo → passed.
    2. GITHUB_BASE_REF=main node scripts/check-migrations-sync-log-gate.mjs → passed, também após o rebase sobre o main de 14/11 07:10Z.
    3. check-migration-filename-contract e check-migration-path-references → ok. check-migration-receipts → static-pass.
    4. Revisão independente: aprovada para abrir. Única observação: os tipos gerados (types.ts) ainda não têm is_trusted; eles são regenerados depois de aplicar a migration.

    🔄 Plano de rollback

    supabase/rollbacks/20261114031000_rollback.sql remove a coluna com DROP COLUMN IF EXISTS is_trusted.

    ⚠️ Notas para o reviewer

  • Pós-merge: rodar o db-apply-migration.yml com version=20261114031000, conferir a coluna em information_schema.columns e depois regenerar types.ts.
  • 🤖 Generated with Claude Code

    https://claude.ai/code/session_01VXkRxXLTPrNUgWhbASkaJg
    <!-- devin-review-badge-begin -->

    ---

    <a href="https://app.devin.ai/review/adm01-debug/promo_gifts_v4/pull/3582" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a>
    <!-- devin-review-badge-end -->

    Diff: 359 lines (+269 / -90) across 4 files Reviewer: adm01-debug Review duration: 761m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 359 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.352
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3582"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.6% (MEDIUM) · Higher = larger blast radius
    42.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%