|
| 1 | +import { MigrationInterface, QueryRunner } from 'typeorm'; |
| 2 | + |
| 3 | +export class AddMissingReelVideoSocialMedia1747000000000 |
| 4 | + implements MigrationInterface |
| 5 | +{ |
| 6 | + name = 'AddMissingReelVideoSocialMedia1747000000000'; |
| 7 | + |
| 8 | + public async up(queryRunner: QueryRunner): Promise<void> { |
| 9 | + // Define the project ticker to Reel Video URL mapping |
| 10 | + const projectReelVideos = [ |
| 11 | + { |
| 12 | + ticker: 'PACK', |
| 13 | + url: 'https://youtube.com/shorts/8Gk-Ly8Foac?feature=share', |
| 14 | + }, |
| 15 | + { |
| 16 | + ticker: 'X23', |
| 17 | + url: 'https://youtube.com/shorts/AnKtMfnQrmU?feature=share', |
| 18 | + }, |
| 19 | + { |
| 20 | + ticker: 'TDM', |
| 21 | + url: 'https://youtube.com/shorts/ZZX6NuXkJO8?feature=share', |
| 22 | + }, |
| 23 | + { |
| 24 | + ticker: 'PRSM', |
| 25 | + url: 'https://youtube.com/shorts/k5qXJH-o2Z0?feature=share', |
| 26 | + }, |
| 27 | + { |
| 28 | + ticker: 'CTZN', |
| 29 | + url: 'https://youtube.com/shorts/neF1zbCeImU?feature=share', |
| 30 | + }, |
| 31 | + { |
| 32 | + ticker: 'H2DAO', |
| 33 | + url: 'https://youtube.com/shorts/Zgd30u7ta-A?feature=share', |
| 34 | + }, |
| 35 | + { |
| 36 | + ticker: 'LOCK', |
| 37 | + url: 'https://youtube.com/shorts/WLeG91LzzVc?feature=share', |
| 38 | + }, |
| 39 | + { |
| 40 | + ticker: 'ACHAD', |
| 41 | + url: 'https://youtube.com/shorts/G0-PXR7V-ro?feature=share', |
| 42 | + }, |
| 43 | + { |
| 44 | + ticker: 'BEAST', |
| 45 | + url: 'https://youtube.com/shorts/Ouq2984E5F4?feature=share', |
| 46 | + }, |
| 47 | + { |
| 48 | + ticker: 'MELS', |
| 49 | + url: 'https://youtube.com/shorts/KTXsNhANaDs?feature=share', |
| 50 | + }, |
| 51 | + ]; |
| 52 | + |
| 53 | + // Insert Reel Video social media entries for each project only if they don't exist |
| 54 | + for (const { ticker, url } of projectReelVideos) { |
| 55 | + // First, get the project ID and admin user ID for the project with this ticker |
| 56 | + const projectResult = await queryRunner.query( |
| 57 | + `SELECT id, "adminUserId" |
| 58 | + FROM "project" |
| 59 | + WHERE "abc"->>'tokenTicker' = $1`, |
| 60 | + [ticker], |
| 61 | + ); |
| 62 | + |
| 63 | + if (projectResult.length > 0) { |
| 64 | + const projectId = projectResult[0].id; |
| 65 | + const adminUserId = projectResult[0].adminUserId; |
| 66 | + |
| 67 | + // Check if the REEL_VIDEO record already exists for this project |
| 68 | + const existingRecord = await queryRunner.query( |
| 69 | + `SELECT id FROM "project_social_media" |
| 70 | + WHERE "type" = 'REEL_VIDEO' AND "projectId" = $1`, |
| 71 | + [projectId], |
| 72 | + ); |
| 73 | + |
| 74 | + // Only insert if the record doesn't exist |
| 75 | + if (existingRecord.length === 0) { |
| 76 | + await queryRunner.query( |
| 77 | + `INSERT INTO "project_social_media" ("type", "link", "projectId", "userId") |
| 78 | + VALUES ('REEL_VIDEO', $1, $2, $3)`, |
| 79 | + [url, projectId, adminUserId], |
| 80 | + ); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + public async down(queryRunner: QueryRunner): Promise<void> { |
| 87 | + // Define the project tickers that were updated |
| 88 | + const projectTickers = [ |
| 89 | + 'PACK', |
| 90 | + 'X23', |
| 91 | + 'TDM', |
| 92 | + 'PRSM', |
| 93 | + 'CTZN', |
| 94 | + 'H2DAO', |
| 95 | + 'LOCK', |
| 96 | + 'ACHAD', |
| 97 | + 'BEAST', |
| 98 | + 'MELS', |
| 99 | + ]; |
| 100 | + |
| 101 | + // Remove Reel Video social media entries for these projects |
| 102 | + for (const ticker of projectTickers) { |
| 103 | + await queryRunner.query( |
| 104 | + `DELETE FROM "project_social_media" |
| 105 | + WHERE "type" = 'REEL_VIDEO' |
| 106 | + AND "projectId" IN ( |
| 107 | + SELECT id FROM "project" WHERE "abc"->>'tokenTicker' = $1 |
| 108 | + )`, |
| 109 | + [ticker], |
| 110 | + ); |
| 111 | + } |
| 112 | + } |
| 113 | +} |
0 commit comments