TypeORM to MikroORM Migration
Guide for migrating custom entities from TypeORM-only to dual MultiORM support.
Overviewโ
Ever Gauzy supports both TypeORM and MikroORM simultaneously via Multi-ORM decorators. When creating or modifying entities, use the @MultiORM* decorators to ensure compatibility with both ORMs.
Decorator Mappingโ
| TypeORM Decorator | MultiORM Equivalent |
|---|---|
@Entity() | @MultiORMEntity() |
@Column() | @MultiORMColumn() |
@ManyToOne() | @MultiORMManyToOne() |
@OneToMany() | @MultiORMOneToMany() |
@ManyToMany() | @MultiORMManyToMany() |
@JoinTable() | @MultiORMJoinTable() |
@Index() | @MultiORMIndex() |
Example Migrationโ
Before (TypeORM only)โ
import { Entity, Column, ManyToOne } from "typeorm";
@Entity("my_entity")
export class MyEntity extends TenantOrganizationBaseEntity {
@Column()
name: string;
@ManyToOne(() => User, { nullable: true })
user?: User;
}
After (MultiORM)โ
import { MultiORMEntity, MultiORMColumn, MultiORMManyToOne } from "@gauzy/core";
@MultiORMEntity("my_entity")
export class MyEntity extends TenantOrganizationBaseEntity {
@MultiORMColumn()
name: string;
@MultiORMManyToOne(() => User, { nullable: true })
user?: User;
}
Repository Migrationโ
Beforeโ
import { Repository } from "typeorm";
@Injectable()
export class MyService {
constructor(
@InjectRepository(MyEntity)
private repository: Repository<MyEntity>,
) {}
}
Afterโ
import { TypeOrmMyEntityRepository } from "./repository/type-orm-my-entity.repository";
import { MikroOrmMyEntityRepository } from "./repository/mikro-orm-my-entity.repository";
@Injectable()
export class MyService extends TenantAwareCrudService<MyEntity> {
constructor(
typeOrmRepo: TypeOrmMyEntityRepository,
mikroOrmRepo: MikroOrmMyEntityRepository,
) {
super(typeOrmRepo, mikroOrmRepo);
}
}
Common Pitfallsโ
- MikroORM stricter validation โ MikroORM 6.x validates metadata more strictly
- Relation decorators โ use conditional decorators for ORM-specific relations
- Entity discovery โ ensure entities are registered in both ORMs
Related Pagesโ
- Multi-ORM Deep Dive โ ORM architecture
- Entity Inheritance โ base entities
- Custom Entity Fields โ custom fields