codestates / codestates/quokkaBoard-server

[ ๐Ÿ“Œ Error Handling] typeorm-seeding config error

Open
#108 0 comments 0 reactions 1 assignee Claimed by @skyupguf View on GitHub
Complete err_handling
Dominant language
TypeScript
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

### ์–ด๋–ค ์—๋Ÿฌ์ธ๊ฐ€์š”?
- ConnectionOption ์ด typeorm-seeding ๋ชจ๋“ˆ์˜ seeds, factories ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ฝ์ง€ ๋ชปํ•˜๋Š” ๋ฌธ์ œ

### ์—๋Ÿฌ ๋ฉ”์‹œ์ง€
```
$ Error "No connection options were found in any orm configuration files" on production.
```

### ์—๋Ÿฌ ํ•ธ๋“ค๋ง ๋ฐฉ๋ฒ•
- typeorm์˜ connectionOption๋“ค์€ typeorm-seeding์˜ seed, factory ์†์„ฑ๋“ค์„ ์ฝ์ง€ ๋ชปํ•œ๋‹ค.
- ์ •์˜๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋‹ˆ ๋‹น์—ฐํ•œ ๊ฒƒ, ๋‹ค์Œ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ• ๋ชจ๋‘ ์—๋Ÿฌ ํ•ธ๋“ค๋ง์ด ๊ฐ€๋Šฅํ–ˆ๋‹ค.

1. ConnectionOptions๋Š” ์ƒ์†์ด ๋˜์ง€ ์•Š์•˜์œผ๋‚˜ MysqlConnectionOptions ์—์„œ ์ƒ์†์„ ํ†ตํ•œ ์†์„ฑ์ถ”๊ฐ€, ํƒ€์ž…์ •์˜
```
import { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions';

interface newConnectionOptions extends MysqlConnectionOptions {
readonly seeds?: (Function | string)[];
readonly factories?: (Function | string)[];
}

const ormconfig: newConnectionOptions = {
....
"seeds": [ "src/db/seed/**/*.seed.ts" ],
"factories": [ "src/db/factory/**/*.factory.ts" ],
};
//์ •์ƒ์ ์œผ๋กœ ์ถ”๊ฐ€๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
```

2. typeorm-seeding ์˜ ConnectioOption
- ์—ฐ๊ฒฐ๋ชจ๋“ˆ์„ ์ƒ์†ํ•ด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, typeorm-seeding ๋ชจ๋“ˆ์—์„œ ๊ด€๋ จ ๋ชจ๋“ˆ์— ๋Œ€ํ•œ ์ •์˜๊ฐ€ ๋‹น์—ฐํžˆ ์žˆ์ง€ ์•Š์„๊นŒ ์ƒ๊ฐ
- ๋ชจ๋“ˆ ๊ฒฝ๋กœ ํŒŒ์ผ์— ์—ฐ๊ฒฐ๊ด€๋ จ ์˜ต์…˜์— ๋Œ€ํ•œ ์ •์˜๊ฐ€ ์ž˜ ๋˜์–ด ์žˆ๋‹ค.
```
./node_modules/typeorm-seeding/dist/connection.d.ts

import { Connection as TypeORMConnection, ConnectionOptions as TypeORMConnectionOptions } from 'typeorm';

interface SeedingOptions {
factories: string[];
seeds: string[];
}

export declare type ConnectionOptions = TypeORMConnectionOptions & SeedingOptions;
```

- ์ฆ‰ typeorm-seeding์˜ ์—ฐ๊ฒฐ์˜ต์…˜์—์„œ typeorm ์—ฐ๊ฒฐ์˜ต์…˜๊นŒ์ง€ ์ „๋ถ€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํƒ€์ž…์ •์˜๊ฐ€ ๋˜์–ด ์žˆ๋‹ค.
- ์•„๋ž˜์™€ ๊ฐ™์ด ์‚ฌ์šฉํ•˜๋ฉด CLI๋กœ seed ์ž‘์—…, ์„œ๋ฒ„์‹œ์ž‘์œผ๋กœ DB์—ฐ๊ฒฐ ๋ชจ๋‘ ๊ฐ€๋Šฅํ•˜๋‹ค.
```
import { ConnectionOptions } from "typeorm-seeding"

const ormconfig: newConnectionOptions = {
....
"seeds": [ "src/db/seed/**/*.seed.ts" ],
"factories": [ "src/db/factory/**/*.factory.ts" ],
};
//๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ •์ƒ์ ์œผ๋กœ ์ถ”๊ฐ€๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.
```
### ์—๋Ÿฌ ํ•ธ๋“ค๋ง์„ ์œ„ํ•ด ์ฐธ๊ณ ํ•œ ๋ ˆํผ๋Ÿฐ์Šค ๋งํฌ
[๋งํฌ](https://github.com/typeorm/typeorm/issues/5103)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.