Skip to content

ci(deploy): gate on the real schema, not on a DB secret - #90

Merged
juancodedev merged 1 commit into
mainfrom
chore/deploy-migration-gate
Nov 13, 2026
Merged

juancodedev merged 1 commit into
mainfrom
chore/deploy-migration-gate

Conversation

@juancodedev

Copy link
Copy Markdown
Owner

Reemplaza el gate del #89, que quedó en main y rompió el deploy (de1f1f7) porque exigía el secret SUPABASE_DB_URL, que no existe.

En vez de comparar el historial de migraciones contra la base, compara el contrato de la app contra el esquema que producción sirve de verdad. Reutiliza NEXT_PUBLIC_SUPABASE_URL y SUPABASE_SERVICE_ROLE_KEY, que el deploy ya tiene: cero secrets nuevos, cero passwords.

src/infrastructure/database/database.types.ts es el contrato contra el que está tipada toda la app. Si producción no tiene una tabla o columna declarada ahí, el deploy falla antes de buildear y lista exactamente qué falta:

::error::Production is missing 7 schema object(s) the app requires:
  table api_keys
  leads.external_id
  leads.city
  leads.industry
  leads.opportunity_score
  leads.rating
  leads.reviews_count

Ese output es el del esquema de la semana pasada, reproducido offline con --spec: el gate habría frenado el PR #87.

Cambios

Archivo Qué
src/lib/deploy/schema-drift.ts parseo del contrato, del spec de PostgREST y diff (funciones puras)
src/lib/deploy/__tests__/schema-drift.spec.ts 9 tests, uno corre contra el database.types.ts real
scripts/check-schema-drift.mjs runner, con --spec para verificar sin red
.github/workflows/deploy.yml primer paso del job
README.md sección de migraciones y deploy
scripts/check-pending-migrations.sh eliminado

Verificación

  • jest — 112 suites / 825 tests
  • tsc --noEmit limpio
  • eslint . --max-warnings 30 — 0 errores, 12 warnings preexistentes
  • Runner offline: spec completo → exit 0; sin las columnas nuevas → exit 1 con la lista
  • Deploy roto de de1f1f7 eliminado

Risk: item 5 (CI/deploy).

Merging to main deploys to production with no schema gate: the CRM hardening
PR shipped code writing six columns the database did not have, and every lead
write answered PGRST204 until the migrations were applied by hand.

The deploy workflow now compares database.types.ts — the contract the whole
codebase is typed against — with the PostgREST root spec of the target
project, and fails before building when a table or column the app needs is
absent.

It reuses the service role key the deploy already has, so it needs no new
secret and no database password. Parsing and diffing are pure and unit
tested; the runner also accepts --spec for an offline check.
@juancodedev
juancodedev force-pushed the chore/deploy-migration-gate branch from 3118abd to 59a39e8 Compare November 13, 2026 01:26
@juancodedev
juancodedev merged commit a5596b8 into main Nov 13, 2026
4 checks passed
@juancodedev
juancodedev deleted the chore/deploy-migration-gate branch November 13, 2026 01:41
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