Skip to content

Commit f2ce18a

Browse files
fix(timeline): add conversation user id and parent user id to view (#205)
1 parent 6a86abe commit f2ce18a

File tree

5 files changed

+480
-20
lines changed

5 files changed

+480
-20
lines changed
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
import { MigrationInterface, QueryRunner } from 'typeorm';
2+
3+
export class ConvAndParentUserId1765799789310 implements MigrationInterface {
4+
name = 'ConvAndParentUserId1765799789310';
5+
6+
public async up(query_runner: QueryRunner): Promise<void> {
7+
await query_runner.query(
8+
`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`,
9+
['VIEW', 'user_posts_view', 'public']
10+
);
11+
await query_runner.query(`DROP VIEW "user_posts_view"`);
12+
await query_runner.query(`CREATE VIEW "user_posts_view" AS
13+
SELECT
14+
t.tweet_id::text AS id,
15+
t.user_id AS profile_user_id,
16+
t.user_id AS tweet_author_id,
17+
t.tweet_id,
18+
NULL::uuid AS repost_id,
19+
t.type::text AS post_type,
20+
t.created_at AS post_date,
21+
t.type::text AS type,
22+
t.content,
23+
t.images,
24+
t.videos,
25+
t.num_likes,
26+
t.num_reposts,
27+
t.num_views,
28+
t.num_quotes,
29+
t.num_replies,
30+
t.num_bookmarks,
31+
t.mentions,
32+
t.created_at,
33+
t.updated_at,
34+
u.username,
35+
u.name,
36+
u.followers,
37+
u.following,
38+
u.avatar_url,
39+
u.cover_url,
40+
u.verified,
41+
u.bio,
42+
NULL::text AS reposted_by_name,
43+
NULL::text AS reposted_by_username,
44+
COALESCE(tq.original_tweet_id, trep.original_tweet_id) AS parent_id,
45+
trep.conversation_id AS conversation_id,
46+
conv_tweet.user_id AS conversation_user_id,
47+
COALESCE(orig_quote_tweet.user_id, orig_reply_tweet.user_id) AS parent_user_id
48+
FROM tweets t
49+
INNER JOIN "user" u ON t.user_id = u.id
50+
LEFT JOIN tweet_quotes tq ON t.tweet_id = tq.quote_tweet_id
51+
LEFT JOIN tweet_replies trep ON t.tweet_id = trep.reply_tweet_id
52+
LEFT JOIN tweets conv_tweet ON trep.conversation_id = conv_tweet.tweet_id
53+
LEFT JOIN tweets orig_quote_tweet ON tq.original_tweet_id = orig_quote_tweet.tweet_id
54+
LEFT JOIN tweets orig_reply_tweet ON trep.original_tweet_id = orig_reply_tweet.tweet_id
55+
56+
UNION ALL
57+
58+
SELECT
59+
(tr.tweet_id::text || '_' || tr.user_id::text) AS id,
60+
tr.user_id AS profile_user_id,
61+
t.user_id AS tweet_author_id,
62+
tr.tweet_id,
63+
tr.tweet_id AS repost_id,
64+
t.type::text AS post_type,
65+
tr.created_at AS post_date,
66+
'repost' AS type,
67+
t.content,
68+
t.images,
69+
t.videos,
70+
t.num_likes,
71+
t.num_reposts,
72+
t.num_views,
73+
t.num_quotes,
74+
t.num_replies,
75+
t.num_bookmarks,
76+
t.mentions,
77+
t.created_at,
78+
t.updated_at,
79+
u.username,
80+
u.name,
81+
u.followers,
82+
u.following,
83+
u.avatar_url,
84+
u.cover_url,
85+
u.verified,
86+
u.bio,
87+
reposter.name AS reposted_by_name,
88+
reposter.username AS reposted_by_username,
89+
COALESCE(tq.original_tweet_id, trep.original_tweet_id) AS parent_id,
90+
trep.conversation_id AS conversation_id,
91+
conv_tweet.user_id AS conversation_user_id,
92+
COALESCE(orig_quote_tweet.user_id, orig_reply_tweet.user_id) AS parent_user_id
93+
94+
FROM tweet_reposts tr
95+
INNER JOIN tweets t ON tr.tweet_id = t.tweet_id
96+
INNER JOIN "user" u ON t.user_id = u.id
97+
INNER JOIN "user" reposter ON tr.user_id = reposter.id
98+
LEFT JOIN tweet_quotes tq ON t.tweet_id = tq.quote_tweet_id
99+
LEFT JOIN tweet_replies trep ON t.tweet_id = trep.reply_tweet_id
100+
LEFT JOIN tweets conv_tweet ON trep.conversation_id = conv_tweet.tweet_id
101+
LEFT JOIN tweets orig_quote_tweet ON tq.original_tweet_id = orig_quote_tweet.tweet_id
102+
LEFT JOIN tweets orig_reply_tweet ON trep.original_tweet_id = orig_reply_tweet.tweet_id
103+
`);
104+
await query_runner.query(
105+
`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`,
106+
[
107+
'public',
108+
'VIEW',
109+
'user_posts_view',
110+
'SELECT \n t.tweet_id::text AS id,\n t.user_id AS profile_user_id,\n t.user_id AS tweet_author_id,\n t.tweet_id,\n NULL::uuid AS repost_id,\n t.type::text AS post_type,\n t.created_at AS post_date,\n t.type::text AS type,\n t.content,\n t.images,\n t.videos,\n t.num_likes,\n t.num_reposts,\n t.num_views,\n t.num_quotes,\n t.num_replies,\n t.num_bookmarks,\n t.mentions,\n t.created_at,\n t.updated_at,\n u.username,\n u.name,\n u.followers,\n u.following,\n u.avatar_url,\n u.cover_url,\n u.verified,\n u.bio,\n NULL::text AS reposted_by_name,\n NULL::text AS reposted_by_username,\n COALESCE(tq.original_tweet_id, trep.original_tweet_id) AS parent_id,\n trep.conversation_id AS conversation_id,\n conv_tweet.user_id AS conversation_user_id,\n COALESCE(orig_quote_tweet.user_id, orig_reply_tweet.user_id) AS parent_user_id\n FROM tweets t\n INNER JOIN "user" u ON t.user_id = u.id\n LEFT JOIN tweet_quotes tq ON t.tweet_id = tq.quote_tweet_id\n LEFT JOIN tweet_replies trep ON t.tweet_id = trep.reply_tweet_id\n LEFT JOIN tweets conv_tweet ON trep.conversation_id = conv_tweet.tweet_id\n LEFT JOIN tweets orig_quote_tweet ON tq.original_tweet_id = orig_quote_tweet.tweet_id\n LEFT JOIN tweets orig_reply_tweet ON trep.original_tweet_id = orig_reply_tweet.tweet_id\n \n UNION ALL\n \n SELECT \n (tr.tweet_id::text || \'_\' || tr.user_id::text) AS id,\n tr.user_id AS profile_user_id,\n t.user_id AS tweet_author_id,\n tr.tweet_id,\n tr.tweet_id AS repost_id,\n t.type::text AS post_type,\n tr.created_at AS post_date,\n \'repost\' AS type,\n t.content,\n t.images,\n t.videos,\n t.num_likes,\n t.num_reposts,\n t.num_views,\n t.num_quotes,\n t.num_replies,\n t.num_bookmarks,\n t.mentions,\n t.created_at,\n t.updated_at,\n u.username,\n u.name,\n u.followers,\n u.following,\n u.avatar_url,\n u.cover_url,\n u.verified,\n u.bio,\n reposter.name AS reposted_by_name,\n reposter.username AS reposted_by_username,\n COALESCE(tq.original_tweet_id, trep.original_tweet_id) AS parent_id,\n trep.conversation_id AS conversation_id,\n conv_tweet.user_id AS conversation_user_id,\n COALESCE(orig_quote_tweet.user_id, orig_reply_tweet.user_id) AS parent_user_id\n\n FROM tweet_reposts tr\n INNER JOIN tweets t ON tr.tweet_id = t.tweet_id\n INNER JOIN "user" u ON t.user_id = u.id\n INNER JOIN "user" reposter ON tr.user_id = reposter.id\n LEFT JOIN tweet_quotes tq ON t.tweet_id = tq.quote_tweet_id\n LEFT JOIN tweet_replies trep ON t.tweet_id = trep.reply_tweet_id\n LEFT JOIN tweets conv_tweet ON trep.conversation_id = conv_tweet.tweet_id\n LEFT JOIN tweets orig_quote_tweet ON tq.original_tweet_id = orig_quote_tweet.tweet_id\n LEFT JOIN tweets orig_reply_tweet ON trep.original_tweet_id = orig_reply_tweet.tweet_id',
111+
]
112+
);
113+
}
114+
115+
public async down(query_runner: QueryRunner): Promise<void> {
116+
await query_runner.query(
117+
`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`,
118+
['VIEW', 'user_posts_view', 'public']
119+
);
120+
await query_runner.query(`DROP VIEW "user_posts_view"`);
121+
await query_runner.query(`CREATE VIEW "user_posts_view" AS SELECT
122+
t.tweet_id::text AS id,
123+
t.user_id AS profile_user_id,
124+
t.user_id AS tweet_author_id,
125+
t.tweet_id,
126+
NULL::uuid AS repost_id,
127+
t.type::text AS post_type,
128+
t.created_at AS post_date,
129+
t.type::text AS type,
130+
t.content,
131+
t.images,
132+
t.videos,
133+
t.num_likes,
134+
t.num_reposts,
135+
t.num_views,
136+
t.num_quotes,
137+
t.num_replies,
138+
t.num_bookmarks,
139+
t.mentions,
140+
t.created_at,
141+
t.updated_at,
142+
u.username,
143+
u.name,
144+
u.followers,
145+
u.following,
146+
u.avatar_url,
147+
u.cover_url,
148+
u.verified,
149+
u.bio,
150+
NULL::text AS reposted_by_name,
151+
NULL::text AS reposted_by_username,
152+
COALESCE(tq.original_tweet_id, trep.original_tweet_id) AS parent_id,
153+
trep.conversation_id AS conversation_id
154+
FROM tweets t
155+
INNER JOIN "user" u ON t.user_id = u.id
156+
LEFT JOIN tweet_quotes tq ON t.tweet_id = tq.quote_tweet_id
157+
LEFT JOIN tweet_replies trep ON t.tweet_id = trep.reply_tweet_id
158+
159+
UNION ALL
160+
161+
SELECT
162+
(tr.tweet_id::text || '_' || tr.user_id::text) AS id,
163+
tr.user_id AS profile_user_id,
164+
t.user_id AS tweet_author_id,
165+
tr.tweet_id,
166+
tr.tweet_id AS repost_id,
167+
t.type::text AS post_type,
168+
tr.created_at AS post_date,
169+
'repost' AS type,
170+
t.content,
171+
t.images,
172+
t.videos,
173+
t.num_likes,
174+
t.num_reposts,
175+
t.num_views,
176+
t.num_quotes,
177+
t.num_replies,
178+
t.num_bookmarks,
179+
t.mentions,
180+
t.created_at,
181+
t.updated_at,
182+
u.username,
183+
u.name,
184+
u.followers,
185+
u.following,
186+
u.avatar_url,
187+
u.cover_url,
188+
u.verified,
189+
u.bio,
190+
reposter.name AS reposted_by_name,
191+
reposter.username AS reposted_by_username,
192+
COALESCE(tq.original_tweet_id, trep.original_tweet_id) AS parent_id,
193+
trep.conversation_id AS conversation_id
194+
195+
FROM tweet_reposts tr
196+
INNER JOIN tweets t ON tr.tweet_id = t.tweet_id
197+
INNER JOIN "user" u ON t.user_id = u.id
198+
INNER JOIN "user" reposter ON tr.user_id = reposter.id
199+
LEFT JOIN tweet_quotes tq ON t.tweet_id = tq.quote_tweet_id
200+
LEFT JOIN tweet_replies trep ON t.tweet_id = trep.reply_tweet_id`);
201+
await query_runner.query(
202+
`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`,
203+
[
204+
'public',
205+
'VIEW',
206+
'user_posts_view',
207+
'SELECT \n t.tweet_id::text AS id,\n t.user_id AS profile_user_id,\n t.user_id AS tweet_author_id,\n t.tweet_id,\n NULL::uuid AS repost_id,\n t.type::text AS post_type,\n t.created_at AS post_date,\n t.type::text AS type,\n t.content,\n t.images,\n t.videos,\n t.num_likes,\n t.num_reposts,\n t.num_views,\n t.num_quotes,\n t.num_replies,\n t.num_bookmarks,\n t.mentions,\n t.created_at,\n t.updated_at,\n u.username,\n u.name,\n u.followers,\n u.following,\n u.avatar_url,\n u.cover_url,\n u.verified,\n u.bio,\n NULL::text AS reposted_by_name,\n NULL::text AS reposted_by_username,\n COALESCE(tq.original_tweet_id, trep.original_tweet_id) AS parent_id,\n trep.conversation_id AS conversation_id\n FROM tweets t\n INNER JOIN "user" u ON t.user_id = u.id\n LEFT JOIN tweet_quotes tq ON t.tweet_id = tq.quote_tweet_id\n LEFT JOIN tweet_replies trep ON t.tweet_id = trep.reply_tweet_id\n \n UNION ALL\n \n SELECT \n (tr.tweet_id::text || \'_\' || tr.user_id::text) AS id,\n tr.user_id AS profile_user_id,\n t.user_id AS tweet_author_id,\n tr.tweet_id,\n tr.tweet_id AS repost_id,\n t.type::text AS post_type,\n tr.created_at AS post_date,\n \'repost\' AS type,\n t.content,\n t.images,\n t.videos,\n t.num_likes,\n t.num_reposts,\n t.num_views,\n t.num_quotes,\n t.num_replies,\n t.num_bookmarks,\n t.mentions,\n t.created_at,\n t.updated_at,\n u.username,\n u.name,\n u.followers,\n u.following,\n u.avatar_url,\n u.cover_url,\n u.verified,\n u.bio,\n reposter.name AS reposted_by_name,\n reposter.username AS reposted_by_username,\n COALESCE(tq.original_tweet_id, trep.original_tweet_id) AS parent_id,\n trep.conversation_id AS conversation_id\n\n FROM tweet_reposts tr\n INNER JOIN tweets t ON tr.tweet_id = t.tweet_id\n INNER JOIN "user" u ON t.user_id = u.id\n INNER JOIN "user" reposter ON tr.user_id = reposter.id\n LEFT JOIN tweet_quotes tq ON t.tweet_id = tq.quote_tweet_id\n LEFT JOIN tweet_replies trep ON t.tweet_id = trep.reply_tweet_id',
208+
]
209+
);
210+
}
211+
}

src/migrations/1765743134688-addHashtagCreatedAt.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)