om-migrate-mikro-orm

Migrates custom module code from MikroORM v6 to v7 including Kysely query conversion.

1.7k|382|Updated Sep 10, 2025
One-click install
npx skills add https://github.com/open-mercato/open-mercato --skill om-migrate-mikro-orm
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: om-migrate-mikro-orm
Source: https://github.com/open-mercato/open-mercato/tree/main/.ai/skills/om-migrate-mikro-orm
Command: npx skills add https://github.com/open-mercato/open-mercato --skill om-migrate-mikro-orm

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Upgrading MikroORM from v6 to v7 breaks existing module code through removed APIs like persistAndFlush, relocated decorator imports, and the replacement of Knex with Kysely, producing type errors and runtime failures that are tedious to fix manually.

Core Features & Use Cases

  • API Migration: Replaces persistAndFlush/removeAndFlush with the chained persist().flush() pattern and updates test mocks accordingly.
  • Knex to Kysely Conversion: Rewrites raw SQL queries, inserts, updates, deletes, and JSONB casts using the Kysely query builder with sql template literals.
  • Type and Config Fixes: Resolves FilterQuery and RequiredEntityData generic errors, moves decorator imports to @mikro-orm/decorators/legacy, and configures ReflectMetadataProvider.
  • Use Case: A developer upgrades their Open Mercato module to MikroORM v7 and needs to convert all entity decorators, raw Knex queries, and Jest mocks while keeping migrations and snapshots consistent.

Quick Start

Migrate my module in apps/mercato/src/modules to MikroORM v7 and fix all resulting type errors.

Frequently Asked Questions about om-migrate-mikro-orm

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate from MikroORM v6 to v7?

Move decorator imports to @mikro-orm/decorators/legacy, replace persistAndFlush with persist().flush(), convert Knex queries to Kysely via em.getKysely(), and set metadataProvider to ReflectMetadataProvider in your ORM config. Then run type checks and tests to verify.

How to replace persistAndFlush in MikroORM v7?

Replace await em.persistAndFlush(entity) with await em.persist(entity).flush(), and removeAndFlush with em.remove(entity).flush(). Update test mocks to cover persist, remove, and flush as separate mock functions.

How do I convert Knex raw queries to Kysely?

Get the query builder with em.getKysely() and rewrite queries using selectFrom, insertInto, updateTable, or deleteFrom, always ending with .execute(). For raw SQL, use the sql template literal tag with parameter interpolation instead of knex.raw bindings.

Why does MikroORM v7 fail with FilterQuery type errors?

v7 tightened generic constraints on FilterQuery and RequiredEntityData, so filters with null comparisons or mixed naming conventions no longer infer correctly. Add an explicit cast like { tenantId, deletedAt: null } as FilterQuery<MyEntity> to resolve the errors.

Why does MikroORM v7 entity metadata inference fail silently?

v7 removed the default ReflectMetadataProvider, so entity metadata inference fails without explicit configuration. Set metadataProvider: ReflectMetadataProvider from @mikro-orm/decorators/legacy in your MikroORM.init options.

Does MikroORM v7 work with Jest?

v7 is ESM-only and uses import.meta internally, which breaks standard Jest. Use a custom transformer that replaces import.meta with CJS equivalents and set transformIgnorePatterns to node_modules/(?!(@mikro-orm)/) so the packages get transformed.