Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrations and remove links creation on migration/project create #1852

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import { MigrationBuilder } from "node-pg-migrate"
import Model from "../back/models/ProjectMilestoneUpdate"
import ProjectMilestoneModel from "../back/models/ProjectMilestone"
import UpdateModel from "../entities/Updates/model"

const LEGACY_TABLE_NAME = 'proposal_updates'

export async function up(pgm: MigrationBuilder): Promise<void> {
pgm.createTable(Model.tableName, {
Expand Down Expand Up @@ -36,7 +37,7 @@ export async function up(pgm: MigrationBuilder): Promise<void> {
})

pgm.createIndex(Model.tableName, 'update_id')
pgm.addConstraint(Model.tableName, 'update_id_fk', `FOREIGN KEY(update_id) REFERENCES ${UpdateModel.tableName}(id)`)
pgm.addConstraint(Model.tableName, 'update_id_fk', `FOREIGN KEY(update_id) REFERENCES ${LEGACY_TABLE_NAME}(id)`)
pgm.createIndex(Model.tableName, 'milestone_id')
pgm.addConstraint(Model.tableName, 'milestone_id_fk', `FOREIGN KEY(milestone_id) REFERENCES ${ProjectMilestoneModel.tableName}(id)`)
}
Expand Down
18 changes: 2 additions & 16 deletions src/services/ProjectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ import {
ProposalStatus,
ProposalType,
} from '../entities/Proposal/types'
import {
DEFAULT_CHOICES,
asNumber,
getProposalEndDate,
isProjectProposal,
proposalUrl,
} from '../entities/Proposal/utils'
import { DEFAULT_CHOICES, asNumber, getProposalEndDate, isProjectProposal } from '../entities/Proposal/utils'
import UpdateModel from '../entities/Updates/model'
import { IndexedUpdate, UpdateAttributes } from '../entities/Updates/types'
import { getPublicUpdates } from '../entities/Updates/utils'
Expand Down Expand Up @@ -186,8 +180,8 @@ export class ProjectService {
for (const project of migratedProjects) {
try {
const proposal = await ProposalService.getProposal(project.proposal_id)
await ProjectService.createMilestones(proposal, project, new Date(project.created_at))
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}`)
Expand Down Expand Up @@ -218,14 +212,6 @@ export class ProjectService {

await ProjectService.createPersonnel(proposal, newProject, creationDate)
await ProjectService.createMilestones(proposal, newProject, creationDate)
await ProjectService.addLink(
{
label: 'Proposal',
url: proposalUrl(proposal.id),
project_id: newProject.id,
},
proposal.user
)

return newProject
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function getFunding(proposal: ProposalAttributes, transparencyVesting?: Transpar
}

function getProjectStatus(proposal: ProposalAttributes, vesting?: TransparencyVesting) {
if (proposal.enacting_tx) {
const legacyCondition = !vesting && proposal.enacted_description
if (proposal.enacting_tx || legacyCondition) {
return ProjectStatus.Finished
}

Expand Down