Skip to content

Commit 657c786

Browse files
authored
Merge pull request #452 from boostcampwm-2024/fix/view-update-comment-count
🐛 fix: feedview 마이그레이션 파일 작성 - comment_count 추가
2 parents cb247e0 + f855b8f commit 657c786

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class UpdateFeedViewWithCommentCount1754028000000
4+
implements MigrationInterface
5+
{
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(
8+
`CREATE OR REPLACE VIEW feed_view AS
9+
SELECT
10+
ROW_NUMBER() OVER (ORDER BY f.created_at) AS order_id,
11+
f.id AS id,
12+
f.title AS title,
13+
f.path AS path,
14+
f.created_at AS created_at,
15+
f.thumbnail AS thumbnail,
16+
f.view_count AS view_count,
17+
f.summary AS summary,
18+
f.like_count AS like_count,
19+
f.comment_count AS comment_count,
20+
r.name AS blog_name,
21+
r.blog_platform AS blog_platform,
22+
(
23+
SELECT JSON_ARRAYAGG(t.name)
24+
FROM tag_map tm
25+
INNER JOIN tag t ON t.id = tm.tag_id
26+
WHERE tm.feed_id = f.id
27+
) AS tag
28+
FROM feed f
29+
INNER JOIN rss_accept r ON r.id = f.blog_id
30+
GROUP BY f.id;`,
31+
);
32+
}
33+
34+
public async down(queryRunner: QueryRunner): Promise<void> {
35+
await queryRunner.query(
36+
`CREATE OR REPLACE VIEW feed_view AS
37+
SELECT
38+
ROW_NUMBER() OVER (ORDER BY f.created_at) AS order_id,
39+
f.id AS id,
40+
f.title AS title,
41+
f.path AS path,
42+
f.created_at AS created_at,
43+
f.thumbnail AS thumbnail,
44+
f.view_count AS view_count,
45+
f.summary AS summary,
46+
f.like_count AS like_count,
47+
r.name AS blog_name,
48+
r.blog_platform AS blog_platform,
49+
(
50+
SELECT JSON_ARRAYAGG(t.name)
51+
FROM tag_map tm
52+
INNER JOIN tag t ON t.id = tm.tag_id
53+
WHERE tm.feed_id = f.id
54+
) AS tag
55+
FROM feed f
56+
INNER JOIN rss_accept r ON r.id = f.blog_id
57+
GROUP BY f.id;`,
58+
);
59+
}
60+
}

0 commit comments

Comments
 (0)