Skip to content

Upgrade Open Mercato to 0.6.4 (MikroORM 6 → 7)#72

Open
pat-lewczuk wants to merge 4 commits into
mainfrom
upgrade/open-mercato-0.6.4
Open

Upgrade Open Mercato to 0.6.4 (MikroORM 6 → 7)#72
pat-lewczuk wants to merge 4 commits into
mainfrom
upgrade/open-mercato-0.6.4

Conversation

@pat-lewczuk

Copy link
Copy Markdown
Member

Summary

Upgrades all @open-mercato/* packages 0.4.8 → 0.6.4 (latest stable). The new framework peer-depends on MikroORM 7, so this also bumps @mikro-orm/* from 6.x → ^7.1.x, adds the now-required @mikro-orm/decorators, and adds react-is (a required peer of @open-mercato/ui).

Breaking change fixed

MikroORM 7 moved decorators out of @mikro-orm/core, which broke yarn generate (does not provide an export named 'Entity'). Migrated decorator imports in all 9 app entity files to the framework's documented path:

-import { Entity, PrimaryKey, Property, Unique, Index } from '@mikro-orm/core'
+import { Entity, PrimaryKey, Property, Unique, Index } from '@mikro-orm/decorators/legacy'

Type-only imports (FilterQuery, EntityManager) and the Migration base class are unaffected.

Verification

  • yarn install — peers resolve (remaining warnings are transitive/optional, incl. disabled gateway-stripe)
  • yarn generate — clean, 404 OpenAPI paths, no MikroORM cache warning
  • yarn db:migrate — new 0.6.4 migrations applied (auth, customers, dictionaries, integrations, messages, query_index, staff, workflows)
  • ✅ Dev server boots; / & /login → 200, all /backend/* → 307 (auth redirect), no 500s / request errors

Known follow-ups (not addressed here)

  1. tsc / next build OOM — the framework ships .ts-only types (no .d.ts), so tsc deep-checks the full framework source; combined with MikroORM 7's heavy FilterQuery/EntityManager generics it OOMs even at a 20GB heap. next dev (turbopack/SWC) is unaffected and runs fine. Best raised upstream; an app-side stopgap would be typescript.ignoreBuildErrors for builds.
  2. Bounties poll-github queue error — pre-existing WIP-feature bug (scheduled poll enqueues a job with no matching worker, which the classify-pr worker then crashes on). Not upgrade-related.

🤖 Generated with Claude Code

pat-lewczuk and others added 4 commits June 9, 2026 08:56
Bump all @open-mercato/* packages 0.4.8 → 0.6.4. The new framework
peer-depends on MikroORM 7, so @mikro-orm/* go 6.x → ^7.1.x and
@mikro-orm/decorators is added (newly required). react-is added as a
required peer of @open-mercato/ui.

MikroORM 7 moved decorators out of @mikro-orm/core, which broke
`yarn generate` ("does not provide an export named 'Entity'"). Migrate
the decorator imports in all app entity files to the framework's
documented path:

  - import { Entity, PrimaryKey, ... } from '@mikro-orm/core'
  + import { Entity, PrimaryKey, ... } from '@mikro-orm/decorators/legacy'

Type-only imports (FilterQuery, EntityManager) and the Migration base
class are unaffected.

Verified: yarn generate (404 OpenAPI paths), db:migrate (all module
migrations applied), dev server boots and serves pages with no errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0.6.x introduced a generated `bootstrap-registrations.generated.ts` that
registers backend/frontend route manifests into the shared module registry
via `registerBackendRouteManifests()`. The admin sidebar nav API
(`/api/auth/admin/nav`) builds the menu from `getBackendRouteManifests()`,
which returns an empty array until those manifests are registered.

The app's `src/bootstrap.ts` predates this step and never called
`runBootstrapRegistrations()`, so the route manifest registry stayed empty
(verified: 0 routes) and the sidebar rendered with no groups. Calling it at
bootstrap module-eval populates the registry (verified: 205 backend routes
across all core and app modules). bootstrap.ts is imported by the root
layout and the `/api/[...slug]` catch-all (which serves the nav route), so
the registry is populated in every request context that needs it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Beyond the route-manifest registration (sidebar fix), align src/bootstrap.ts
with the canonical 0.6.4 app bootstrap, which had drifted since 0.4.x:

- Apply modules.ts inline overrides via applyModuleOverridesFromEnabledModules()
  and register the AI domain applier (import '@open-mercato/ai-assistant').
- Register code-based workflow definitions via registerCodeWorkflows() — without
  this, code workflows are silently never registered.
- Import modules from modules.app.generated (the app/widget-aware variant) rather
  than modules.generated.

File now matches apps/mercato/src/bootstrap.ts at tag v0.6.4 exactly. Verified:
app boots, /backend serves, no regressions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
MikroORM 7 removed knex entirely (em.getConnection().getKnex() no longer
exists), breaking 25 raw cross-module queries across teams, competitions,
judging, and the example module — they threw "getKnex is not a function"
at runtime (team browse, chat, stats, invitations, check-in, etc.).

knex cannot be reintroduced as a dependency: Turbopack statically traces
knex's dialect loader and fails to bundle the uninstalled mysql/oracle/…
drivers, which poisons the whole app bundle (no serverExternalPackages,
resolveAlias, or runtime-require indirection avoids it).

Migrate all usages to MikroORM 7's raw SQL via em.getConnection().execute():
- Add src/lib/db.ts helpers (rawAll/rawFirst/rawRun) used by API routes.
- Subscribers can't import app-local files (their generator bundler doesn't
  resolve @/ or relative paths), so they inline the same execute() call.
- Use `?` placeholders and `IN (?)` for array params (execute expands arrays
  knex-style; `= ANY(?)` would produce invalid SQL). All list call sites are
  guarded against empty arrays.
- Also fixes two pre-existing bounties files that used the broken `= ANY(?)`.

Verified: every affected route compiles and runs (401 when unauthenticated,
no 500/hang), and the rewritten SQL executes against the database.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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