Skip to content

Commit

Permalink
chore: removed code from projects migration (#1864)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncomerci committed Jun 24, 2024
1 parent 4502b0d commit 6b9e6d2
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 73 deletions.
10 changes: 0 additions & 10 deletions src/back/jobs/ProjectsMigration.ts

This file was deleted.

20 changes: 2 additions & 18 deletions src/back/models/Project.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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'

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'
Expand Down Expand Up @@ -74,21 +73,6 @@ export default class ProjectModel extends Model<ProjectAttributes> {
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<ProjectAttributes>(`create_multiple_projects`, query)
}

static async isAuthorOrCoauthor(user: string, projectId: string): Promise<boolean> {
if (!isUUID(projectId || '')) {
throw new Error(`Invalid project id: "${projectId}"`)
Expand Down
2 changes: 0 additions & 2 deletions src/back/routes/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> } = {
runQueuedAirdropJobs,
giveAndRevokeLandOwnerBadges,
giveTopVoterBadges,
migrateProjects,
}

export default routes((router) => {
Expand Down
14 changes: 0 additions & 14 deletions src/entities/Updates/model.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -26,15 +23,4 @@ export default class UpdateModel extends Model<UpdateAttributes> {
...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)
}
}
30 changes: 1 addition & 29 deletions src/services/ProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ProjectAttributes | null> {
try {
const creationDate = new Date()
Expand Down

0 comments on commit 6b9e6d2

Please sign in to comment.