Skip to content

Commit

Permalink
Merge pull request #1892 from Giveth/feat/check_periodically_endaoment
Browse files Browse the repository at this point in the history
Feat/Endaoment project update feature
  • Loading branch information
kkatusic authored Jan 10, 2025
2 parents b224a32 + baa7450 commit 448da9e
Show file tree
Hide file tree
Showing 4 changed files with 45,521 additions and 0 deletions.
56 changes: 56 additions & 0 deletions migration/1735909243926-insertEndaomentProjectsIds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* This migration script is used to insert the endaomentId values for the projects in the endaomentProjects array.
* The endaomentId values are used to link the projects in the database with the projects in the Endaoment platform.
*
* The script will add a new column to the project table called "endaomentId".
*/

import { MigrationInterface, QueryRunner } from 'typeorm';
import { endaomentProjects } from './data/updatedEndaomentProjects';

export class InsertEndaomentProjectsIds1735909243926
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
// Add endaomentId column to the project table
queryRunner.query(`
ALTER TABLE "project"
ADD COLUMN IF NOT EXISTS "endaomentId" UUID;
`);

// Get the organization ID for Endaoment
const endaomentOrgIdResult = await queryRunner.query(`
SELECT "id" FROM "organization" WHERE "label" = 'endaoment';
`);
const endaomentOrgId = endaomentOrgIdResult[0].id;

// Go through each project in the endaomentProjects array and update the endaomentId value in the database
for (const project of endaomentProjects) {
const singleProject = await queryRunner.query(
`SELECT "id" FROM "project" WHERE "title" = $1 AND "organizationId" = $2`,
[project.name, endaomentOrgId],
);

// Update project endaomentId value
if (
singleProject &&
singleProject.length > 0 &&
singleProject[0].id > 0
) {
await queryRunner.query(
`UPDATE "project"
SET "endaomentId" = $1
WHERE "id" = $2;`,
[project.endaomentID, singleProject[0].id],
);
}
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
queryRunner.query(`
ALTER TABLE "project"
DROP COLUMN IF EXISTS "endaomentId";
`);
}
}
Loading

0 comments on commit 448da9e

Please sign in to comment.