Skip to content

fix: guard types generation and fix tRPC feedback schema - #719

Closed
blink-dev wants to merge 3 commits into
mainfrom
fix/regenerate-stale-types
Closed

blink-dev wants to merge 3 commits into
mainfrom
fix/regenerate-stale-types

Conversation

@blink-dev

Copy link
Copy Markdown
Collaborator

Closes #707

@blink-dev
blink-dev requested a review from thinkclay as a code owner September 9, 2026 08:47
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@thinkclay

Copy link
Copy Markdown
Contributor

This is now CONFLICTING against main, and about half of it has landed by other routes since it was opened. Breaking it down so a rebase keeps only what still adds value:

Already on main — drop on rebase

Still wanted — keep

  • scripts/generate-supabase-types.mjs and the supa:generate rewiring. Neither guard exists on main: supa:generate is still the raw supabase gen types … > types.ts, so the types.ts is stale: #703's moderation tables are missing, and regenerating locally deletes application_status #707 failure mode (a behind database silently deleting objects from types.ts) is still one command away. The "refuse if migrations aren't applied" and "refuse on removals unless --allow-removals" checks are exactly right.
  • api-tests.yml: the "types.ts matches the migrations" CI check. Same reason — nothing on main catches a migration merged without regenerating.
  • feedback.router.ts logs → core: still wrong on main (lines 111 and 151 read .schema('logs'); migration 350 moved user_feedback to core). It is the legacy tRPC router, but it is a real fix.
  • migrations-README.md paragraph.

So: rebase onto main, drop the types.ts and guard-test hunks, keep the rest, and retitle — it no longer closes #707 (closed by #736); it adds the guard that would have prevented it.

One thing to check when you do: run the new script once against the current local database and confirm it exits 0 with no removals on a clean regeneration — main's types.ts should be exactly what the migrations produce now, so that is a real end-to-end test of the guard.

@stanicb

stanicb commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

@thinkclay are we good to merge this?

@thinkclay

Copy link
Copy Markdown
Contributor

Picked this up while clearing the PR queue. The guard here is worth having, but the branch has gone stale in a way that makes merging it actively harmful, so I've salvaged it into #771 rather than rebasing.

Why not a rebase: main is 28 commits past this branch's base, #707 closed on 09-10, and the one merge conflict is the part that has to be dropped.

table-references-exist.test.ts here restores four BASELINE_BROKEN entries that main has since resolved for real:

entry resolved by
core.soft_skills_ratings migration 354 creates it (#658)
core.profile_import_data migration 354 creates it (#658)
core.inquiries routes deleted — the feature was never built (#476)
core.profile_completion_nudges route retired, nothing reached it

The baseline is empty on main and the test fails on stale entries as well as new ones, so merging that file would fail the test it edits.

packages/supabase/types.ts is redundant now — main already has content_reports, user_blocks, user_feedback, soft_skills_ratings and profile_import_data.

And package.json here predates lint:migrations; taking it wholesale would delete that script and its call from lint. In #771 only the supa:generate line is changed.

What #771 keeps, unchanged: scripts/generate-supabase-types.mjs, the api-tests.yml types-staleness check, and the expo install --check addition to ci.yml, with you credited as co-author. I exercised the generator rather than trusting it — with no local stack it exits 1 with "Refusing to generate: could not read the migration list" and leaves types.ts untouched.

It also carries the feedback.router.ts logs → core fix from here, which is still needed and is my own loose end: migration 350 moved user_feedback with ALTER TABLE ... SET SCHEMA and I never swept for readers. Those two lines were the last ones left.

Closing in favour of #771 — nothing in it is lost except the two files above, and those would regress main.

@thinkclay thinkclay closed this Sep 15, 2026
thinkclay added a commit that referenced this pull request Sep 15, 2026
…#771)

* ci(types): guard types.ts generation, and finish migration 350's move

Salvages the parts of #719 that are still true. That PR has been open since
2026-09-09, its issue (#707) closed on 09-10, and `main` has moved 28 commits
past its base — so most of it is now either redundant or a regression, but the
guard at its centre never landed and is still the only thing standing between
this repo and a repeat of #707.

**Taken**

`scripts/generate-supabase-types.mjs` (blink-dev's, unchanged). `supabase gen
types` reports what the database in front of it contains, so pointing it at a
database behind the migrations silently deletes every object added since,
straight over types.ts with no diff to review. The script refuses to run when
the migration list and the applied set disagree, generates in memory, and
refuses to write when a table, view, enum or function would disappear —
`--allow-removals` for the deliberate case, like migration 344 dropping
core.application_status. `supa:generate` and the supabase project.json target
now point at it.

Exercised rather than assumed: with no local stack it exits 1 with "Refusing to
generate: could not read the migration list", and types.ts is untouched
afterwards.

The CI halves come too — api-tests.yml regenerates against a fresh
`supabase start` and fails on a diff, and ci.yml adds `expo install --check`
for the Expo SDK skew behind #683/#689.

`feedback.router.ts` moves off `.schema('logs')`. That one is mine to own:
migration 350 moved `user_feedback` to `core` with `ALTER TABLE ... SET SCHEMA`
and I never swept for readers. These two lines are the last ones left on main —
dormant, since `trpc` is not in deploy-functions.sh's deploy list any more, but
wrong.

**Not taken**

`packages/supabase/types.ts` — redundant. main already carries content_reports,
user_blocks, user_feedback, soft_skills_ratings and profile_import_data.

`table-references-exist.test.ts` — this is the conflict, and taking it would go
backwards. #719 restores four BASELINE_BROKEN entries that main has since
resolved properly: soft_skills_ratings and profile_import_data exist as of
migration 354 (#658), core.inquiries' routes were deleted (#476), and
profile_completion_nudges' route was retired. The baseline is empty on main and
fails on stale entries, so merging that file would fail the very test it edits.

`package.json` was applied by hand for the same reason — #719's copy predates
`lint:migrations` and would have deleted both the script and its call from
`lint`. Only the `supa:generate` line is changed here.

Co-Authored-By: blink-dev <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>

* ci(types): compare only the schemas this repo owns

The staleness check failed on its first run, and it was the check that was
wrong, not types.ts. Every difference was in `storage`:

    +          versioning_status: string
    +          archived_at: string | null
    +          is_delete_marker: boolean
    +          is_versioned: boolean

Supabase introspects `storage`, `auth` and `realtime` from whichever
postgres-meta image the CLI pulls — v0.98.0 on that runner — so those schemas
move when the platform ships, not when a migration lands. Regenerating would
not have fixed it, and it would have failed again on the next image bump. A
check that fails for something nobody can act on is one people learn to skip.

`scripts/types-owned-schemas.mjs` slices a generated file down to `public`,
`core`, `community`, `onet` and `logs` — the schemas
packages/supabase/migrations is responsible for — and the workflow compares
those slices instead of the whole file.

Probed in both directions rather than assumed:

  * adding a column to `core.jobs` in a copy → detected
  * adding a column to `storage` in a copy    → ignored

It also generates to /tmp now instead of redirecting over types.ts, so a failed
run no longer leaves a modified working tree behind — the previous version
would have, which is an unpleasant surprise for anyone running it locally.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: blink-dev <[email protected]>
Co-authored-by: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay deleted the fix/regenerate-stale-types branch September 17, 2026 16:43
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.

types.ts is stale: #703's moderation tables are missing, and regenerating locally deletes application_status

3 participants