|
| 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