Skip to content

Commit f65d6b7

Browse files
committed
Refactor migration to add REEL_VIDEO type and populate project social media entries
- Added REEL_VIDEO value to the project_social_media_type_enum. - Merged the functionality of populating project reel videos into the existing migration, removing the need for a separate migration file. - Implemented logic to insert and delete reel video entries based on project tickers during migration.
1 parent 3dfd720 commit f65d6b7

File tree

2 files changed

+94
-105
lines changed

2 files changed

+94
-105
lines changed

migration/1746613421849-addReelVideoToProjectSocialMediaType.ts

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,102 @@ export class AddReelVideoToProjectSocialMediaType1746613421849
1010
await queryRunner.query(
1111
`ALTER TYPE "public"."project_social_media_type_enum" ADD VALUE 'REEL_VIDEO'`,
1212
);
13+
14+
// Define the project ticker to Reel Video URL mapping
15+
const projectReelVideos = [
16+
{
17+
ticker: 'PACK',
18+
url: 'https://youtube.com/shorts/8Gk-Ly8Foac?feature=share',
19+
},
20+
{
21+
ticker: 'X23',
22+
url: 'https://youtube.com/shorts/AnKtMfnQrmU?feature=share',
23+
},
24+
{
25+
ticker: 'TDM',
26+
url: 'https://youtube.com/shorts/ZZX6NuXkJO8?feature=share',
27+
},
28+
{
29+
ticker: 'PRSM',
30+
url: 'https://youtube.com/shorts/k5qXJH-o2Z0?feature=share',
31+
},
32+
{
33+
ticker: 'CTZN',
34+
url: 'https://youtube.com/shorts/neF1zbCeImU?feature=share',
35+
},
36+
{
37+
ticker: 'H2DAO',
38+
url: 'https://youtube.com/shorts/Zgd30u7ta-A?feature=share',
39+
},
40+
{
41+
ticker: 'LOCK',
42+
url: 'https://youtube.com/shorts/WLeG91LzzVc?feature=share',
43+
},
44+
{
45+
ticker: 'ACHAD',
46+
url: 'https://youtube.com/shorts/G0-PXR7V-ro?feature=share',
47+
},
48+
{
49+
ticker: 'BEAST',
50+
url: 'https://youtube.com/shorts/Ouq2984E5F4?feature=share',
51+
},
52+
{
53+
ticker: 'MELS',
54+
url: 'https://youtube.com/shorts/KTXsNhANaDs?feature=share',
55+
},
56+
];
57+
58+
// Insert Reel Video social media entries for each project
59+
for (const { ticker, url } of projectReelVideos) {
60+
// First, get the project ID and admin user ID for the project with this ticker
61+
const projectResult = await queryRunner.query(
62+
`SELECT id, "adminUserId"
63+
FROM "project"
64+
WHERE "abc"->>'tokenTicker' = $1`,
65+
[ticker],
66+
);
67+
68+
if (projectResult.length > 0) {
69+
const projectId = projectResult[0].id;
70+
const adminUserId = projectResult[0].adminUserId;
71+
72+
// Insert the Reel Video social media entry
73+
await queryRunner.query(
74+
`INSERT INTO "project_social_media" ("type", "link", "projectId", "userId")
75+
VALUES ('REEL_VIDEO', $1, $2, $3)`,
76+
[url, projectId, adminUserId],
77+
);
78+
}
79+
}
1380
}
1481

15-
public async down(_queryRunner: QueryRunner): Promise<void> {
82+
public async down(queryRunner: QueryRunner): Promise<void> {
83+
// Define the project tickers that were updated
84+
const projectTickers = [
85+
'PACK',
86+
'X23',
87+
'TDM',
88+
'PRSM',
89+
'CTZN',
90+
'H2DAO',
91+
'LOCK',
92+
'ACHAD',
93+
'BEAST',
94+
'MELS',
95+
];
96+
97+
// Remove Reel Video social media entries for these projects
98+
for (const ticker of projectTickers) {
99+
await queryRunner.query(
100+
`DELETE FROM "project_social_media"
101+
WHERE "type" = 'REEL_VIDEO'
102+
AND "projectId" IN (
103+
SELECT id FROM "project" WHERE "abc"->>'tokenTicker' = $1
104+
)`,
105+
[ticker],
106+
);
107+
}
108+
16109
// Note: PostgreSQL doesn't support removing enum values directly
17110
// This would require recreating the enum type and updating all references
18111
// For safety, we'll leave the enum value in place during rollback

migration/1746613421850-populateProjectReelVideos.ts

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

0 commit comments

Comments
 (0)