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