From f65d6b7e083b236a01151ae4cac00ca65b6aa184 Mon Sep 17 00:00:00 2001 From: ali Date: Tue, 26 Aug 2025 01:04:23 +0330 Subject: [PATCH] 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. --- ...49-addReelVideoToProjectSocialMediaType.ts | 95 +++++++++++++++- ...1746613421850-populateProjectReelVideos.ts | 104 ------------------ 2 files changed, 94 insertions(+), 105 deletions(-) delete mode 100644 migration/1746613421850-populateProjectReelVideos.ts diff --git a/migration/1746613421849-addReelVideoToProjectSocialMediaType.ts b/migration/1746613421849-addReelVideoToProjectSocialMediaType.ts index a284bd2c0..2474f9230 100644 --- a/migration/1746613421849-addReelVideoToProjectSocialMediaType.ts +++ b/migration/1746613421849-addReelVideoToProjectSocialMediaType.ts @@ -10,9 +10,102 @@ export class AddReelVideoToProjectSocialMediaType1746613421849 await queryRunner.query( `ALTER TYPE "public"."project_social_media_type_enum" ADD VALUE 'REEL_VIDEO'`, ); + + // Define the project ticker to Reel Video URL mapping + const projectReelVideos = [ + { + ticker: 'PACK', + url: 'https://youtube.com/shorts/8Gk-Ly8Foac?feature=share', + }, + { + ticker: 'X23', + url: 'https://youtube.com/shorts/AnKtMfnQrmU?feature=share', + }, + { + ticker: 'TDM', + url: 'https://youtube.com/shorts/ZZX6NuXkJO8?feature=share', + }, + { + ticker: 'PRSM', + url: 'https://youtube.com/shorts/k5qXJH-o2Z0?feature=share', + }, + { + ticker: 'CTZN', + url: 'https://youtube.com/shorts/neF1zbCeImU?feature=share', + }, + { + ticker: 'H2DAO', + url: 'https://youtube.com/shorts/Zgd30u7ta-A?feature=share', + }, + { + ticker: 'LOCK', + url: 'https://youtube.com/shorts/WLeG91LzzVc?feature=share', + }, + { + ticker: 'ACHAD', + url: 'https://youtube.com/shorts/G0-PXR7V-ro?feature=share', + }, + { + ticker: 'BEAST', + url: 'https://youtube.com/shorts/Ouq2984E5F4?feature=share', + }, + { + ticker: 'MELS', + url: 'https://youtube.com/shorts/KTXsNhANaDs?feature=share', + }, + ]; + + // Insert Reel Video social media entries for each project + for (const { ticker, url } of projectReelVideos) { + // First, get the project ID and admin user ID for the project with this ticker + const projectResult = await queryRunner.query( + `SELECT id, "adminUserId" + FROM "project" + WHERE "abc"->>'tokenTicker' = $1`, + [ticker], + ); + + if (projectResult.length > 0) { + const projectId = projectResult[0].id; + const adminUserId = projectResult[0].adminUserId; + + // Insert the Reel Video social media entry + await queryRunner.query( + `INSERT INTO "project_social_media" ("type", "link", "projectId", "userId") + VALUES ('REEL_VIDEO', $1, $2, $3)`, + [url, projectId, adminUserId], + ); + } + } } - public async down(_queryRunner: QueryRunner): Promise { + public async down(queryRunner: QueryRunner): Promise { + // Define the project tickers that were updated + const projectTickers = [ + 'PACK', + 'X23', + 'TDM', + 'PRSM', + 'CTZN', + 'H2DAO', + 'LOCK', + 'ACHAD', + 'BEAST', + 'MELS', + ]; + + // Remove Reel Video social media entries for these projects + for (const ticker of projectTickers) { + await queryRunner.query( + `DELETE FROM "project_social_media" + WHERE "type" = 'REEL_VIDEO' + AND "projectId" IN ( + SELECT id FROM "project" WHERE "abc"->>'tokenTicker' = $1 + )`, + [ticker], + ); + } + // Note: PostgreSQL doesn't support removing enum values directly // This would require recreating the enum type and updating all references // For safety, we'll leave the enum value in place during rollback diff --git a/migration/1746613421850-populateProjectReelVideos.ts b/migration/1746613421850-populateProjectReelVideos.ts deleted file mode 100644 index e71863df3..000000000 --- a/migration/1746613421850-populateProjectReelVideos.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { MigrationInterface, QueryRunner } from 'typeorm'; - -export class PopulateProjectReelVideos1746613421850 - implements MigrationInterface -{ - name = 'PopulateProjectReelVideos1746613421850'; - - public async up(queryRunner: QueryRunner): Promise { - // Define the project ticker to Reel Video URL mapping - const projectReelVideos = [ - { - ticker: 'PACK', - url: 'https://youtube.com/shorts/8Gk-Ly8Foac?feature=share', - }, - { - ticker: 'X23', - url: 'https://youtube.com/shorts/AnKtMfnQrmU?feature=share', - }, - { - ticker: 'TDM', - url: 'https://youtube.com/shorts/ZZX6NuXkJO8?feature=share', - }, - { - ticker: 'PRSM', - url: 'https://youtube.com/shorts/k5qXJH-o2Z0?feature=share', - }, - { - ticker: 'CTZN', - url: 'https://youtube.com/shorts/neF1zbCeImU?feature=share', - }, - { - ticker: 'H2DAO', - url: 'https://youtube.com/shorts/Zgd30u7ta-A?feature=share', - }, - { - ticker: 'LOCK', - url: 'https://youtube.com/shorts/WLeG91LzzVc?feature=share', - }, - { - ticker: 'ACHAD', - url: 'https://youtube.com/shorts/G0-PXR7V-ro?feature=share', - }, - { - ticker: 'BEAST', - url: 'https://youtube.com/shorts/Ouq2984E5F4?feature=share', - }, - { - ticker: 'MELS', - url: 'https://youtube.com/shorts/KTXsNhANaDs?feature=share', - }, - ]; - - // Insert Reel Video social media entries for each project - for (const { ticker, url } of projectReelVideos) { - // First, get the project ID and admin user ID for the project with this ticker - const projectResult = await queryRunner.query( - `SELECT id, "adminUserId" - FROM "project" - WHERE "abc"->>'tokenTicker' = $1`, - [ticker], - ); - - if (projectResult.length > 0) { - const projectId = projectResult[0].id; - const adminUserId = projectResult[0].adminUserId; - - // Insert the Reel Video social media entry - await queryRunner.query( - `INSERT INTO "project_social_media" ("type", "link", "projectId", "userId") - VALUES ('REEL_VIDEO', $1, $2, $3)`, - [url, projectId, adminUserId], - ); - } - } - } - - public async down(queryRunner: QueryRunner): Promise { - // Define the project tickers that were updated - const projectTickers = [ - 'PACK', - 'X23', - 'TDM', - 'PRSM', - 'CTZN', - 'H2DAO', - 'LOCK', - 'ACHAD', - 'BEAST', - 'MELS', - ]; - - // Remove Reel Video social media entries for these projects - for (const ticker of projectTickers) { - await queryRunner.query( - `DELETE FROM "project_social_media" - WHERE "type" = 'REEL_VIDEO' - AND "projectId" IN ( - SELECT id FROM "project" WHERE "abc"->>'tokenTicker' = $1 - )`, - [ticker], - ); - } - } -}