-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1892 from Giveth/feat/check_periodically_endaoment
Feat/Endaoment project update feature
- Loading branch information
Showing
4 changed files
with
45,521 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
`); | ||
} | ||
} |
Oops, something went wrong.