codestates / codestates/Bobpago
[๐จErr Handling] ๋ ์ํผ๋ฅผ ํ ์ด๋ธ์์ ๋จ๋ ์ ์ผ๋ก ์ญ์ ํ ๋ ๋ฐ์ํ๋ ์๋ฌ
- Dominant language
- TypeScript
- Stars
- 5
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
> ํด๊ฒฐ๋ ์๋ฌ๋ผ๋ฉด ๋ผ๋ฒจ์ 'Complete' ๋ฅผ ๋ฌ์์ฃผ์ธ์.
> ๋ฏธํด๊ฒฐ๋ ์๋ฌ๋ผ๋ฉด ๋ผ๋ฒจ์ 'In progress' ๋ก ๋ณ๊ฒฝํด์ฃผ์ธ์.
### ์ด๋ค ์๋ฌ์ธ๊ฐ์?
- ๋ ์ํผ๋ฅผ recipeํ
์ด๋ธ์์๋ง ๋จ๋
์ ์ผ๋ก ์ญ์ ํ ๋ ๋ฐ์ํ๋ ์๋ฌ
### ์๋ฌ ๋ฉ์์ง
```bash
$ error FK cannot add foreign key constraint ...
```
### ์๋ฌ ํธ๋ค๋ง ๋ฐฉ๋ฒ
- - ๋ ์ํผ๋ฅผ ๋จผ์ ํ
์ด๋ธ์์ ์ญ์ ํ๊ฒ๋๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํ๋๋ฐ, ์ด๋ ๋ ์ํผ id๋ฅผ ์ธ๋ํค๋ก ๊ฐ์ง๊ณ ์๋ ํ
์ด๋ธ์ ๋ฌด๊ฒฐ์ฑ์ ์๋ฐฐ๋๊ธฐ ๋๋ฌธ์์ ๊นจ๋ณ์
- ๋ฐ๋ผ์ ์ธ๋ํค๋ฅผ ์ฐธ์กฐํ๊ณ ์๋ํ
์ด๋ธ๋ค์ ๋จผ์ ์ง์์ผ๊ฒ ๋ค ์๊ฐํ๊ณ ๊ฐ์ข
ํ
์ด๋ธ์ ๋จผ์ ์ญ์ ํด์ฃผ์๋ค.
- ๊ทผ๋ฐ comment ํ
์ด๋ธ์ id ๊ฒฝ์ฐ comment_reaction ํ
์ด๋ธ์ ์ธ๋ํค๋ก ์ฐธ์กฐํ๊ณ ์๊ธฐ๋๋ฌธ์ comment_reaction ํ
์ด๋ธ์ ๋จผ์ ์ง์์ผ๋๋ค๋ผ๊ณ ์๊ฐํ๊ฒ๋ฌ๋ค.
- ๊ทธ๋ฌ๋ ์ด๋ฐ๋ฐฉ๋ฒ์ด ๊ต์ฅํ ๋นํจ์จ์ ์ด๋ผ๋ ์๊ฐ์ด ๋ค์๊ณ ์ด์ ๊ด๋ จํด์ ์กฐ๊ธ ์ฐพ์๋ณด๋ ManyToOne๊ด๊ณ์ `onDelete: 'CASCADE'` ์ต์
์ ์ฃผ๋ฉด ์๋์ผ๋ก ์ธ๋ํค๋ฅผ ์ฐธ์กฐํ๊ณ ์๋ ํ
์ด๋ธ์ด ๊ฐ์ด ์ญ์ ๊ฐ ๋๋๊ฑธ ๊นจ๋ณ์๋ค!
```ts
// recipes.service.ts
// Before
// 1. AWS S3์์ ์ด๋ฏธ์ง ๊ฐ์ฒด ์ญ์
await this.imageService.deleteById(recipeId, 'recipe');
// 2. ๋ ์ํผ_์ฌ๋ฃ ํ
์ด๋ธ์์ ๋ ์ํผ ์์ด๋ ๊ธฐ์ค์ผ๋ก ์ญ์
await this.recipeIngredientRepository.delete({ recipeId });
// 3. ๋ ์ํผ_์ด๋ฏธ์ง ํ
์ด๋ธ์์ ๋ ์ํผ ์์ด๋ ๊ธฐ์ค์ผ๋ก ์ญ์
await this.recipeImageRepository.delete({ recipeId });
// 4. ๋๊ธ_๋ฆฌ์ก์
ํ
์ด๋ธ์์ ๋ ์ํผ ์์ด๋ ๊ธฐ์ค์ผ๋ก ์ญ์
await this.commentReactionRepository.delete({ recipeId });
// 5. ๋๊ธ ํ
์ด๋ธ์์ ๋ ์ํผ ์์ด๋ ๊ธฐ์ค์ผ๋ก ์ญ์
await this.commentRepository.delete({ recipeId });
// 6. ๋ ์ํผ ํ
์ด๋ธ์์ ์ญ์
await this.recipeRepository.delete({ id: recipeId });
```
```ts
// After
// 1. AWS S3์์ ์ด๋ฏธ์ง ๊ฐ์ฒด ์ญ์
await this.imageService.deleteById(recipeId, 'recipe');
// 2. ๋๊ธ S3 ์ด๋ฏธ์ง ์ญ์
await this.imageService.deleteComments(recipeId);
// 3. ๋ ์ํผ ํ
์ด๋ธ์์ ์ญ์
await this.recipeRepository.delete({ id: recipeId });
```
### ์๋ฌ ํธ๋ค๋ง์ ์ํด ์ฐธ๊ณ ํ ๋ ํผ๋ฐ์ค ๋งํฌ
[https://github.com/typeorm/typeorm/issues/1460](https://github.com/typeorm/typeorm/issues/1460)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.