codestates / codestates/quokkaBoard-server
[ ๐ Error Handling] typeorm-seeding config error
- 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.