콘텐츠로 이동

빠른 시작

--config에 MikroORM config 파일 경로를 지정하세요:

package.json
{
"scripts": {
"erd": "mikro-orm-markdown --config ./mikro-orm.config.ts --out ./ERD.md --title \"My Database\""
}
}
  • .ts config — tsx를 devDependency로 설치하세요 (npm install -D tsx). CLI가 자동으로 로드하며, preferTs를 명시하지 않았다면 MikroORM discovery가 entitiesTs를 우선 사용하도록 설정합니다.
  • .js config — 추가 패키지 불필요. 직접 작성한 파일이든, 빌드 결과물(예: ./dist/mikro-orm.config.js)이든 상관없습니다. .ts 엔티티 파일을 import한다면 설치의 tsx 안내를 확인하세요.
/** @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;
}

예시에서는 import 문을 생략했습니다. type:을 명시해 @mikro-orm/reflection 없이도 동작하는 예시입니다.

터미널 창
npm run erd

두 엔티티 모두 @namespace Blog 태그를 가지므로 하나의 ## Blog 섹션에 묶입니다. MikroORM의 기본 naming strategy를 기준으로 생성된 ERD.md에는 다음과 같은 ERD가 포함됩니다:

코드가 출력으로 어떻게 매핑되는가:

  • @namespace Blog → 두 엔티티가 ## Blog 섹션 아래로 묶임
  • @ManyToOne({ entity: () => Author }) → Post에서 Author로 향하는 관계선과 author_id FK 컬럼
  • Author.posts의 @atLeastOne → 컬렉션 쪽이 1개 이상으로 렌더링됨: Post }|--|| Author
  • email의 unique: true → email이 UK(unique key)로 표시됨
  • body의 @Property({ nullable: true }) → Nullable 칸이 Y로 표시됨
  • /** Post title */ → title의 Description 칸을 채움

각 엔티티는 컬럼 표로도 표현됩니다. 예를 들어 생성된 Post 섹션은 다음과 같습니다:

### 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) | | |

다음 단계: 모든 CLI 옵션과 JSDoc 태그를 확인하세요.