From 2582c19e59686e6361c603076ebcf21eb164b8a2 Mon Sep 17 00:00:00 2001 From: gsmithun4 Date: Fri, 11 Jul 2025 10:53:52 +0530 Subject: [PATCH] migration fix --- .../1742905945987-UpdateGlobalDataSources.ts | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/server/data-migrations/1742905945987-UpdateGlobalDataSources.ts b/server/data-migrations/1742905945987-UpdateGlobalDataSources.ts index 9f355d9d41..3a44b7666c 100644 --- a/server/data-migrations/1742905945987-UpdateGlobalDataSources.ts +++ b/server/data-migrations/1742905945987-UpdateGlobalDataSources.ts @@ -2,6 +2,18 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; export class UpdateGlobalDataSources1742905945987 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { + const constraintExists = await queryRunner.query(` + SELECT 1 + FROM information_schema.table_constraints + WHERE constraint_name = 'chk_global_data_source_app_version_id' + AND table_name = 'data_sources' + `); + + if (constraintExists && constraintExists.length > 0) { + console.log('Constraint chk_global_data_source_app_version_id already exists. Skipping migration.'); + return; + } + // Step 1: Set app_version_id to NULL for existing global data sources await queryRunner.query(` UPDATE data_sources @@ -17,5 +29,20 @@ export class UpdateGlobalDataSources1742905945987 implements MigrationInterface `); } - public async down(queryRunner: QueryRunner): Promise {} + public async down(queryRunner: QueryRunner): Promise { + // Drop the constraint if it exists + const constraintExists = await queryRunner.query(` + SELECT 1 + FROM information_schema.table_constraints + WHERE constraint_name = 'chk_global_data_source_app_version_id' + AND table_name = 'data_sources' + `); + + if (constraintExists && constraintExists.length > 0) { + await queryRunner.query(` + ALTER TABLE data_sources + DROP CONSTRAINT chk_global_data_source_app_version_id + `); + } + } }