Quick Start
1. Add a script
Section titled “1. Add a script”Point --config at your MikroORM config file:
{ "scripts": { "erd": "mikro-orm-markdown --config ./mikro-orm.config.ts --out ./ERD.md --title \"My Database\"" }}.tsconfig — installtsxas a dev dependency (npm install -D tsx). The CLI loads it automatically and defaults MikroORM discovery toentitiesTsunless you explicitly setpreferTs..jsconfig — no extra packages needed. It can be hand-written, or your own build output (e.g../dist/mikro-orm.config.js). If it imports.tsentity files, see thetsxnote in Installation.
2. Describe your entities with JSDoc
Section titled “2. Describe your entities with JSDoc”/** @namespace Blog */@Entity()export class Author { @PrimaryKey({ type: 'integer' }) id!: number;
@Property({ type: 'string' }) name!: string;
@Property({ type: 'string', unique: true }) email!: string;
/** @atLeastOne */ @OneToMany({ entity: () => Post, mappedBy: 'author' }) posts = new Collection<Post>(this);}
/** * Blog post authored by a registered user. * @namespace Blog */@Entity()export class Post { @PrimaryKey({ type: 'integer' }) id!: number;
/** Post title */ @Property({ type: 'string' }) title!: string;
@Property({ type: 'text', nullable: true }) body?: string;
@ManyToOne({ entity: () => Author }) author!: Author;}Imports are omitted. Explicit type: options keep the example working without @mikro-orm/reflection.
3. Run it
Section titled “3. Run it”npm run erdWhat you get
Section titled “What you get”Both entities share the @namespace Blog tag, so they land in one ## Blog section. With MikroORM’s default naming strategy, the generated ERD.md contains an ERD like this:
How the code maps to the output:
@namespace Blog→ both entities are grouped under the## Blogsection@ManyToOne({ entity: () => Author })→ thePosttoAuthorrelation line and theauthor_id FKcolumn@atLeastOneonAuthor.posts→ the collection side is rendered as one-or-more:Post }|--|| Authorunique: trueonemail→emailis markedUK(unique key)@Property({ nullable: true })onbody→ theNullablecell is markedY/** Post title */→ fills the Description cell fortitle
Each entity also gets a column table. For example, the generated Post section looks like this:
### Post
*Table: `post`*
> Blog post authored by a registered user.
| Column | Type | Key | Nullable | Description || --------- | ------- | ----------- | -------- | ----------- || id | integer | PK | | || title | string | | | Post title || body | text | | Y | || author_id | integer | FK (author) | | |Next: see every CLI option and JSDoc tag.