Skip to content

feat(marquee): Phase 5 scale + live migration - #55

Merged
2bTwist merged 5 commits into
mainfrom
app/marquee-phase5
Jun 20, 2026
Merged

2bTwist merged 5 commits into
mainfrom
app/marquee-phase5

Conversation

@2bTwist

@2bTwist 2bTwist commented Jun 20, 2026 •

Copy link
Copy Markdown
Owner

Phase 5 of the Marquee dogfood: scale + live cross-backend migration, proven end to end. Stacked on #54 (base app/marquee-phase4).

What ships

  • Scale seed: seed.mts <kind> [count] (default 300, pass 5000 to stress).
  • Migrate config (src/lib/migrate.ts): wires @baas/migrate for Marquee. The collection list, the FK relation map (movieGenres / credits / reviews to their parents), stripFields for a Supabase source's id / created_at, and maxValueBytes for a Convex target. userId is carried verbatim, since the shared OIDC issuer makes a subject identical on both backends.
  • Admin Migrate panel: dry-run preview, real cutover, live per-collection progress, and a final report. Built on the same portable backends the app uses (it constructs both at once). Admin-gated via useAuth.canAdmin.
  • Headless drivers: scripts/migrate-run.mts (at-scale cutover) and scripts/clear.mts (wipe a backend after migration runs).

Direction-aware by design

Migrating user-owned data into Supabase is blocked by RLS for the browser's anon client (reviews and profiles require auth.uid() = userId on insert). So the panel is direction-aware: into Convex copies everything; into Supabase is catalog-only, with the reason stated in the UI.

Gates

  • test/migrate.test.ts (memory to memory, isolated): every collection copies, foreign keys remap to the ids the target mints (verified by content, since two memory backends mint colliding id spaces), userId is not remapped, idempotent. Full marquee suite 50/50.
  • Live browser smoke: a Supabase to Convex cutover with relations; a re-run fully idempotent; a migrated movie's cast resolves on Convex.
  • At-scale live run (forward): 5000 movies / 10000 movieGenres / 20000 credits copied plus about 61k FK relinks in 215s, ok=true, with the previously-migrated 106 movies idempotently skipped. About 450 rows/sec, no Convex per-mutation cap hit (single-row inserts).

Findings the dogfood surfaced

  • The migrate is single-row-per-mutation, so it never approaches Convex's per-mutation cap. Limit-safe, linear in row count.
  • The reverse Convex to Supabase cutover revealed a real capability conflict, now documented in the @baas/migrate module docstring (with a changeset). A strict Postgres target needs a nullable migratedFrom marker column on each table, and its FK columns must be permissive during the copy (the relink pass rewrites them afterward). But a FK constraint is exactly what PostgREST needs for a server-side embedded join (the serverSideJoins capability) and is what blocks the same table from being a migration target. A schema tuned for native joins is not automatically a clean migration target. The forward direction (into the schemaless backend) sidesteps both, which is why it is the supported path. The marquee schema is kept as designed (Phase 2 join intact); the conflict ships as a documented SDK finding rather than a forced fix.

2bTwist added 4 commits June 20, 2026 16:27
Scale: seed.mts takes an optional movie count (seed.mts <kind> 5000) to stress
~50-80k rows and exercise Convex per-mutation limits + pagination; default stays
the 300 dev catalog.

Migrate: lib/migrate.ts wires @baas/migrate for Marquee — the collection list,
the FK relation map (movieGenres/credits/reviews -> their parents), stripFields
for a Supabase source's id/created_at, and maxValueBytes for a Convex target.
userId is carried verbatim (shared issuer = consistent sub across backends);
poster handles copy as-is (file blobs are out of migration scope).

Gate: test/migrate.test.ts (memory->memory, isolated) proves every collection
copies, foreign keys remap to the ids the target mints (checked by content, not
id-equality, since two memory backends mint colliding id spaces), userId is not
remapped, and a re-run is idempotent. The live Supabase<->Convex cutover is the
admin-panel browser smoke.
An admin-gated panel that runs @baas/migrate between the two live backends with a
dry-run preview, a real cutover, and live per-collection progress, on top of the
same portable backends the app uses (it builds both at once). Renders the plan
(total/toCopy/toSkip) and the final report (copied/skipped/relinked + any error).

Direction-aware collections: into Convex copies everything (generic CRUD is
ungated); into Supabase is catalog-only, because reviews/profiles RLS rejects the
browser's anon client — migrating user data into an RLS backend needs service
credentials, stated in the panel rather than hidden. useAuth gains canAdmin; the
Migrate nav shows only for the admin role.
scripts/migrate-run.mts runs the same src/lib/migrate cutover the admin panel
runs, but headless, so a multi-thousand-movie copy completes in minutes with
stdout progress instead of a long browser session (the migrate only lists/inserts
— no subscribe — so it is safe under tsx). Proved Phase 5 at scale: a live
Supabase->Convex cutover of 5000 movies / 10000 movieGenres / 20000 credits
copied + ~61k FK relinks in 215s, ok=true, with the previously-migrated 106
movies idempotently skipped. No Convex per-mutation limit hit (single-row inserts).
…nsion

The Marquee dogfood's reverse Convex->Supabase cutover surfaced what a strict
relational target needs that a schemaless one does not, and a real conflict:

- A Postgres/Supabase target needs a nullable migratedFrom text column on every
  migrated table (the resume marker is stamped + read back; it is not in the
  source schema, so it is easy to miss). Convex accepts it for free.
- The two-pass copy inserts FK fields with the source id before the relink pass
  rewrites them, so a strict target's FK columns must be permissive during the
  copy (text, no FK constraint). A uuid-typed or FK-constrained column rejects the
  transient source id ("invalid input syntax for type uuid").
- The tension: a FK constraint is exactly what PostgREST needs to resolve a
  server-side embedded join (the serverSideJoins capability), yet it is what
  blocks the same table from being a migration target. A schema tuned for native
  joins is not automatically a clean migration target. The forward direction
  (into the schemaless backend) sidesteps both, which is why it is the supported
  path. Documented in the module docstring with a changeset.

Also adds scripts/clear.mts (wipe all marquee collections on a backend), used to
de-bloat a backend after migration runs.
@2bTwist
2bTwist changed the base branch from app/marquee-phase4 to main June 20, 2026 21:36
The dead-code CI check (knip) failed on the Phase 5 additions, which the lighter
pre-commit hook does not run. Fix both: broaden the marquee knip entry glob to
scripts/*.mts so the new headless drivers (migrate-run.mts, clear.mts) are seen as
entry points like seed.mts; and un-export CATALOG_COLLECTIONS / USER_COLLECTIONS /
MIGRATE_RELATIONS, which are internal building blocks of MIGRATE_COLLECTIONS /
collectionsFor / runMigration and have no external importer.
@2bTwist
2bTwist merged commit df88c11 into main Jun 20, 2026
11 checks passed
@2bTwist
2bTwist deleted the app/marquee-phase5 branch June 20, 2026 21:42
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