-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- FeedList View Entity의 수정부분 마이그레이션 파일 추가 - refactor(user.d): 사용하지 않는 import 모듈 제거
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class UpdateFeedListViewEntity1708621994632 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
WITH t1 AS (SELECT c.feedId AS feedId, COUNT(c.id) AS comment_cnt | ||
FROM comments c | ||
GROUP BY c.feedId), | ||
t2 AS (SELECT id, | ||
feedId, | ||
file_link AS img_url | ||
FROM upload_files | ||
WHERE (feedId, | ||
id) | ||
IN (SELECT feedId, | ||
MIN(id) | ||
FROM upload_files | ||
WHERE is_img = TRUE | ||
AND deleted_at IS NULL | ||
GROUP BY feedId)), | ||
t3 AS (SELECT feedId AS feedId, COUNT(id) AS files_cnt | ||
FROM upload_files | ||
WHERE is_img = FALSE | ||
AND deleted_at IS NULL | ||
GROUP BY feedId), | ||
t4 AS (SELECT feedId, COUNT(*) AS like_cnt FROM feed_symbol fs WHERE symbolId = 1 GROUP BY feedId), | ||
t5 AS (SELECT feedId AS feedId, COUNT(id) AS img_cnt | ||
FROM upload_files | ||
WHERE is_img = TRUE | ||
AND deleted_at IS NULL | ||
GROUP BY feedId) | ||
SELECT f.id, | ||
f.statusId, | ||
f.categoryId, | ||
c2.category, | ||
u2.id AS userId, | ||
u2.nickname AS userNickname, | ||
f.title, | ||
f.content, | ||
t2.img_url AS imgUrl, | ||
f.viewCnt, | ||
IFNULL(t1.comment_cnt, 0) AS commentCnt, | ||
IFNULL(t4.like_cnt, 0) AS likeCnt, | ||
IFNULL(t3.files_cnt, 0) AS filesCnt, | ||
IFNULL(t5.img_cnt, 0) AS imgCnt, | ||
f.created_at AS createdAt, | ||
f.updated_at AS updatedAt, | ||
f.posted_at AS postedAt, | ||
f.deleted_at AS deletedAt | ||
FROM feeds f | ||
LEFT JOIN estimation e ON f.estimationId = e.id | ||
LEFT JOIN t1 ON t1.feedId = f.id | ||
LEFT JOIN categories c2 ON f.categoryId = c2.id | ||
LEFT JOIN t2 ON t2.feedId = f.id | ||
LEFT JOIN t3 ON t3.feedId = f.id | ||
LEFT JOIN t4 ON t4.feedId = f.id | ||
LEFT JOIN t5 ON t5.feedId = f.id | ||
LEFT JOIN users u2 ON f.userId = u2.id | ||
`); | ||
} | ||
|
||
public async down(_queryRunner: QueryRunner): Promise<void> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters