feat(marquee): Phase 5 scale + live migration - #55
Merged
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 5 of the Marquee dogfood: scale + live cross-backend migration, proven end to end. Stacked on #54 (base
app/marquee-phase4).What ships
seed.mts <kind> [count](default 300, pass 5000 to stress).src/lib/migrate.ts): wires@baas/migratefor Marquee. The collection list, the FK relation map (movieGenres / credits / reviews to their parents),stripFieldsfor a Supabase source'sid/created_at, andmaxValueBytesfor a Convex target.userIdis carried verbatim, since the shared OIDC issuer makes a subject identical on both backends.useAuth.canAdmin.scripts/migrate-run.mts(at-scale cutover) andscripts/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() = userIdon 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),userIdis not remapped, idempotent. Full marquee suite 50/50.Findings the dogfood surfaced
@baas/migratemodule docstring (with a changeset). A strict Postgres target needs a nullablemigratedFrommarker 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 (theserverSideJoinscapability) 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.