From 6b9e6d220a41bf294c7a3f0d133253dd59651af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Comerci?= <45410089+ncomerci@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:44:36 -0300 Subject: [PATCH] chore: removed code from projects migration (#1864) --- src/back/jobs/ProjectsMigration.ts | 10 ---------- src/back/models/Project.ts | 20 ++------------------ src/back/routes/debug.ts | 2 -- src/entities/Updates/model.ts | 14 -------------- src/services/ProjectService.ts | 30 +----------------------------- 5 files changed, 3 insertions(+), 73 deletions(-) delete mode 100644 src/back/jobs/ProjectsMigration.ts diff --git a/src/back/jobs/ProjectsMigration.ts b/src/back/jobs/ProjectsMigration.ts deleted file mode 100644 index 58f5f353a..000000000 --- a/src/back/jobs/ProjectsMigration.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ProjectService } from '../../services/ProjectService' - -export async function migrateProjects() { - const result = await ProjectService.migrateProjects() - if (result.error || result.migrationErrors.length > 0) { - throw JSON.stringify(result) - } - - return result -} diff --git a/src/back/models/Project.ts b/src/back/models/Project.ts index 7de5bea63..40c98eece 100644 --- a/src/back/models/Project.ts +++ b/src/back/models/Project.ts @@ -1,6 +1,5 @@ -import crypto from 'crypto' import { Model } from 'decentraland-gatsby/dist/entities/Database/model' -import { SQL, join, table } from 'decentraland-gatsby/dist/entities/Database/utils' +import { SQL, table } from 'decentraland-gatsby/dist/entities/Database/utils' import isEthereumAddress from 'validator/lib/isEthereumAddress' import isUUID from 'validator/lib/isUUID' @@ -8,7 +7,7 @@ import CoauthorModel from '../../entities/Coauthor/model' import { CoauthorStatus } from '../../entities/Coauthor/types' import { ProjectStatus } from '../../entities/Grant/types' import ProposalModel from '../../entities/Proposal/model' -import { ProjectFunding, ProposalProject } from '../../entities/Proposal/types' +import { ProjectFunding } from '../../entities/Proposal/types' import PersonnelModel, { PersonnelAttributes } from './Personnel' import ProjectLinkModel, { ProjectLink } from './ProjectLink' @@ -74,21 +73,6 @@ export default class ProjectModel extends Model { return result[0] } - static async migrate(proposals: ProposalProject[]) { - const values = proposals.map( - ({ id, title, about, status, updated_at }) => - SQL`(${crypto.randomUUID()}, ${id}, ${title}, ${about}, ${status}, ${new Date(updated_at)})` - ) - - const query = SQL` - INSERT INTO ${table(ProjectModel)} (id, proposal_id, title, about, status, created_at) - VALUES ${join(values, SQL`, `)} - RETURNING *; - ` - - return this.namedQuery(`create_multiple_projects`, query) - } - static async isAuthorOrCoauthor(user: string, projectId: string): Promise { if (!isUUID(projectId || '')) { throw new Error(`Invalid project id: "${projectId}"`) diff --git a/src/back/routes/debug.ts b/src/back/routes/debug.ts index 45bcc8b67..a4f3e3ea1 100644 --- a/src/back/routes/debug.ts +++ b/src/back/routes/debug.ts @@ -6,14 +6,12 @@ import { DEBUG_ADDRESSES } from '../../constants' import CacheService from '../../services/CacheService' import { ErrorService } from '../../services/ErrorService' import { giveAndRevokeLandOwnerBadges, giveTopVoterBadges, runQueuedAirdropJobs } from '../jobs/BadgeAirdrop' -import { migrateProjects } from '../jobs/ProjectsMigration' import { validateDebugAddress } from '../utils/validations' const FUNCTIONS_MAP: { [key: string]: () => Promise } = { runQueuedAirdropJobs, giveAndRevokeLandOwnerBadges, giveTopVoterBadges, - migrateProjects, } export default routes((router) => { diff --git a/src/entities/Updates/model.ts b/src/entities/Updates/model.ts index b09d5203c..8dda1ba9a 100644 --- a/src/entities/Updates/model.ts +++ b/src/entities/Updates/model.ts @@ -1,8 +1,5 @@ import crypto from 'crypto' import { Model } from 'decentraland-gatsby/dist/entities/Database/model' -import { SQL, table } from 'decentraland-gatsby/dist/entities/Database/utils' - -import ProjectModel from '../../back/models/Project' import { UpdateAttributes, UpdateStatus } from './types' @@ -26,15 +23,4 @@ export default class UpdateModel extends Model { ...update, }) } - - static async setProjectIds() { - const query = SQL` - UPDATE ${table(this)} pu - SET project_id = p.id - FROM ${table(ProjectModel)} p - WHERE pu.proposal_id = p.proposal_id - ` - - return await this.namedQuery('set_project_ids', query) - } } diff --git a/src/services/ProjectService.ts b/src/services/ProjectService.ts index 5ab0671c3..fa3bc4ed8 100644 --- a/src/services/ProjectService.ts +++ b/src/services/ProjectService.ts @@ -34,7 +34,7 @@ import { createProposalProject, toGovernanceProjectStatus } from '../utils/proje import { BudgetService } from './BudgetService' import { ErrorService } from './ErrorService' -import { ProposalInCreation, ProposalService } from './ProposalService' +import { ProposalInCreation } from './ProposalService' import { VestingService } from './VestingService' function newestVestingFirst(a: TransparencyVesting, b: TransparencyVesting): number { @@ -170,34 +170,6 @@ export class ProjectService { }) } - static async migrateProjects() { - const migrationResult = { migratedProjects: 0, migrationsFinished: 0, migrationErrors: [] as string[], error: '' } - try { - const { data: projects } = await this.getProposalProjects() - const migratedProjects = await ProjectModel.migrate(projects) - migrationResult.migratedProjects = migratedProjects.length - - for (const project of migratedProjects) { - try { - const proposal = await ProposalService.getProposal(project.proposal_id) - await ProjectService.createPersonnel(proposal, project, new Date(project.created_at)) - await ProjectService.createMilestones(proposal, project, new Date(project.created_at)) - migrationResult.migrationsFinished++ - } catch (e) { - migrationResult.migrationErrors.push(`Project ${project.id} failed with: ${e}`) - } - } - - await UpdateModel.setProjectIds() - return migrationResult - } catch (e) { - const message = `Migration failed: ${e}` - console.error(message) - migrationResult.error = message - return migrationResult - } - } - private static async createProject(proposal: ProposalWithOutcome): Promise { try { const creationDate = new Date()