fix(supabase): realinha frontend ao schema ao vivo (regenera types.ts + restaura untypedFrom)#323
fix(supabase): realinha frontend ao schema ao vivo (regenera types.ts + restaura untypedFrom)#323adm01-debug wants to merge 2 commits into
Conversation
O frontend estava desalinhado com o Supabase por dois motivos: 1. types.ts desatualizado e curado à mão (142 tabelas vs 250 no banco). 24 tabelas consumidas pelo front não existiam nos tipos (bitrix_clients, personalization_simulations, companies, roles, sales_goals, user_2fa_settings, grupos de personalização, etc.) e os enums role_migration_status/_item_status divergiam do banco. Regenerado via "supabase gen types typescript" a partir do projeto ao vivo, agora refletindo schema, nulabilidade e enums reais. 2. 3 arquivos do mecanismo untypedFrom foram commitados como base64 (regressão do #319), quebrando 48 call sites e o CI: - src/lib/supabase-untyped.ts (untypedFrom deixou de ser exportado) - scripts/lint-untyped-from.sh - .github/workflows/lint-untyped-from.yml Decodificados de volta para o conteúdo real. Com types.ts regenerado, todas as 8 tabelas usadas via untypedFrom() existem no schema, então o guard lint-untyped-from passa naturalmente — removido o continue-on-error para torná-lo required (conforme TODO). Baseline de tsc atualizado para absorver os deltas de nulabilidade que os tipos precisos passaram a expor (mudança de tipos/restauração de fonte válida, sem alteração de comportamento em runtime). https://claude.ai/code/session_01DMrBVhLd8cL6JniJ63ZJrp
…s tabelas Conclui a migração documentada nos próprios arquivos: system_kill_switches e kill_switch_hits foram incluídas no types.ts regenerado, então os casts `supabase as any` (que existiam só porque as tabelas não estavam tipadas) foram removidos em favor de supabase.from() tipado. Também: - useKillSwitchBanner: KillSwitchActiveError vira import type (só usado como tipo). - kill-switch-telemetry: eslint-disable naming-convention no helper de teste __resetKillSwitchTelemetry (mesmo padrão de __resetSchemaStatsForTests). Resolve os 4 problemas novos do gate de ESLint que bloqueavam o push. https://claude.ai/code/session_01DMrBVhLd8cL6JniJ63ZJrp
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Your plan includes 5 reviews of capacity. Refill in 26 minutes and 52 seconds. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more review capacity refills, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ 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
Realigns the frontend with the live Supabase schema by regenerating src/integrations/supabase/types.ts, restoring three files that had been accidentally committed as base64 (supabase-untyped.ts, lint-untyped-from.sh, lint-untyped-from.yml), removing two supabase as any casts in the kill-switch client/telemetry, and updating the TSC baseline to absorb new nullability deltas.
Changes:
- Restore base64-corrupted files to their real source (fixes
untypedFromexport and CI lint job) and promote thelint-untyped-fromworkflow from advisory to required. - Drop
supabase as anycasts inkill-switch-client.tsandkill-switch-telemetry.tsnow thatsystem_kill_switches/kill_switch_hitsexist in regenerated types. - Update
.tsc-baseline.json(508 → 545) to reflect new nullability errors surfaced by accurate generated types.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/supabase-untyped.ts | Decoded from base64; UntypedTable = never, untypedFrom<T>() exported again. |
| scripts/lint-untyped-from.sh | Decoded from base64; cross-checks untypedFrom("X") calls against generated types.ts table names. |
| .github/workflows/lint-untyped-from.yml | Decoded from base64; removed continue-on-error: true to make the check required. |
| src/lib/external-db/kill-switch-client.ts | Replaced supabase as any cast with typed supabase.from('system_kill_switches'); reformat. |
| src/lib/external-db/kill-switch-telemetry.ts | Replaced supabase as any cast with typed supabase.from('kill_switch_hits'); added eslint-disable on __resetKillSwitchTelemetry naming. |
| src/hooks/useKillSwitchBanner.ts | Switched KillSwitchActiveError import to type-only. |
| .tsc-baseline.json | Re-generated baseline (508 → 545) absorbing new nullability deltas from regenerated types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 552beb233c
ℹ️ 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".
| grep -E '^ [a-z_][a-z0-9_]+: \{$' "$TYPES_FILE" \ | ||
| | sed -E 's/^ ([a-z_][a-z0-9_]+):.*/\1/' \ | ||
| | sort -u > "$tmp_schema" |
There was a problem hiding this comment.
Restrict schema extraction to tables only
The tmp_schema list is built by matching any line shaped like <name>: { in types.ts, which also captures Views, Functions, and other sections, not just public.Tables. In this repo’s current generated file that pattern yields 793 names while only 295 are actual tables, so a call like untypedFrom("<rpc_name>") can incorrectly pass this guard even though supabase.from() will fail at runtime because no table exists. The extraction should be scoped to the Tables block (and schema) before diffing.
Useful? React with 👍 / 👎.
| --include='*.ts' --include='*.tsx' --exclude='supabase-untyped.ts' 2>/dev/null \ | ||
| | sed -E "s/.*untypedFrom[^(]*\(['\"]([a-z_][a-z0-9_]+)['\"].*/\1/" \ |
There was a problem hiding this comment.
Match untypedFrom calls with whitespace before literals
The call-site regex only detects untypedFrom("x")/untypedFrom('x') where the quote appears immediately after (, so valid formatting like untypedFrom( "x") or multiline argument layouts is skipped. Skipped calls never enter tmp_called, which lets CI pass even if a newly introduced untyped table is missing from types.ts, undermining this check as a required gate.
Useful? React with 👍 / 👎.
| # 1) Tabelas chamadas via untypedFrom("...") ou untypedFrom('...') em src/ | ||
| # (exclui a própria definição em supabase-untyped.ts) | ||
| grep -rhE "untypedFrom[^(]*\(['\"]([a-z_][a-z0-9_]*)['\"]" "$SRC_DIR" \ | ||
| --include='*.ts' --include='*.tsx' --exclude='supabase-untyped.ts' 2>/dev/null \ |
There was a problem hiding this comment.
Fail when untypedFrom argument is non-literal
The extraction only recognizes quoted literals, so dynamic calls like untypedFrom(table) are silently ignored. This is already happening in the repo (for example, src/pages/bi/TrendsPage.tsx uses untypedFrom(table)), which means the guard undercounts call sites and can miss regressions if a variable later resolves to a table absent from types.ts. As a required gate, this should either reject non-literal arguments or resolve them explicitly.
Useful? React with 👍 / 👎.
|
Superseded por #329 — esse PR foi reescrito em iteração mais nova (1h20 depois) cobrindo mais arquivos (40 vs 8) e incluindo todas as correções deste:
Fechando para evitar trabalho em paralelo. Toda revisão deve ir para #329. |
Contexto
O frontend estava desalinhado com o Supabase (projeto
doufsxqlfjyuvxuezpln). Investiguei toda a superfície de integração (tabelas.from(), RPCs.rpc(), bucketsstorage.from(), edge functions) contra o schema ao vivo. Tabelas/RPCs/buckets já existiam todos — o desalinhamento estava em duas frentes:Bugs corrigidos
1.
types.tsdesatualizado (curado à mão, fora de sincronia)src/integrations/supabase/types.tstinha apenas 142 tabelas vs 250 no banco. 24 tabelas consumidas pelo frontend não existiam nos tipos, forçandountypedFrom, castsas anye erros silenciados no tsc-baseline:bitrix_clients,personalization_simulations,companies,roles,sales_goals,user_2fa_settings,system_kill_switches,kill_switch_hits,ai_providers,ai_models,notifications, grupos de personalização (product_group_*,product_component_location_techniques), etc.Além disso, os enums
role_migration_status/role_migration_item_statusdivergiam do banco (partial/dry_runno front vscancelledno banco real).Fix: regenerado via
supabase gen types typescripta partir do projeto ao vivo. Agora reflete schema, nulabilidade e enums reais.2. Três arquivos commitados como base64 (regressão do #319)
O mecanismo
untypedFromfoi corrompido — os arquivos continham texto base64 em vez do código real, quebrando 48 call sites (untypedFromnão era exportado → TS2305) e o CI:src/lib/supabase-untyped.tsscripts/lint-untyped-from.sh.github/workflows/lint-untyped-from.ymlFix: decodificados de volta para o conteúdo real.
3. Conclusão da migração documentada
Com
types.tsregenerado:untypedFrom()agora existem no schema → o guardlint-untyped-frompassa naturalmente. Removido ocontinue-on-errorpara torná-lo required (conforme TODO no próprio workflow).supabase as anyemkill-switch-client.tsekill-switch-telemetry.ts(os comentários pediam isso "quando rodar gen types"), agora usandosupabase.from()tipado.Notas
profiles.user_id/full_name/emailsãostring | nullno banco, mas várias interfaces locais assumiam não-null). São mudanças só de tipo / restauração de fonte válida — sem alteração de comportamento em runtime. Recomendo endurecer esses pontos de nulabilidade incrementalmente em PRs de follow-up.Test plan
npm run typecheck(gate de baseline tsc) — sem regressõesnpm run lint:baseline(gate de baseline ESLint) — sem regressõesbash scripts/lint-untyped-from.sh— todas as 8 tabelas existem no schemahttps://claude.ai/code/session_01DMrBVhLd8cL6JniJ63ZJrp
Generated by Claude Code
Summary by cubic
Realigned the frontend with the live Supabase schema by regenerating
src/integrations/supabase/types.tsand restoring theuntypedFromtooling. This fixes silent failures, removesas anycasts, and makes the schema guard required.Bug Fixes
types.tsfrom the live DB to add missing tables, correct nullability and enums; kill-switch tables are now typed andsupabase.from()is used instead of casts.src/lib/supabase-untyped.ts,scripts/lint-untyped-from.sh, and.github/workflows/lint-untyped-from.ymlfrom base64 to source, fixing the export and CI job.Migration
lint-untyped-fromworkflow is now required. AnyuntypedFrom("X")not present intypes.tswill block PRs.supabase gen types typescript --project-id <id> > src/integrations/supabase/types.ts, or add a migration for the table.supabase.from()where tables exist intypes.ts; keepuntypedFromonly as a temporary bridge.Written for commit 552beb2. Summary will update on new commits. Review in cubic