From 10cbdf73a39b0f5d9e6dc5f0b1a30d0f1f043521 Mon Sep 17 00:00:00 2001 From: Shreerang Kale Date: Mon, 3 Feb 2025 23:33:35 +0530 Subject: [PATCH] Fix unique constraint error in rollback deployment --- packages/backend/src/service.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/service.ts b/packages/backend/src/service.ts index de402918..efa10a38 100644 --- a/packages/backend/src/service.ts +++ b/packages/backend/src/service.ts @@ -709,6 +709,8 @@ export class Service { deployer = data.deployer; } + console.log("DATA>DOMAIN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",data.domain) + const deployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, false); const dnsDeployment = await this.createDeploymentFromData(userId, data, deployer!.deployerLrn!, applicationRecordId, applicationRecordData, true); @@ -1246,7 +1248,7 @@ export class Service { const newCurrentDeploymentUpdate = await this.db.updateDeploymentById( deploymentId, - { isCurrent: true, domain: oldCurrentDeployment.domain }, + { isCurrent: true, domain: null }, ); const newCurrentDeployment = await this.db.getDeployment({ where: { id: deploymentId }, relations: { project: true, deployer: true } }); @@ -1255,6 +1257,25 @@ export class Service { throw new Error(`Deployment with Id ${deploymentId} not found`); } + const applicationDeploymentRequestData = newCurrentDeployment.applicationDeploymentRequestData; + + const customDomain = await this.db.getOldestDomainByProjectId(projectId); + + if (customDomain) { + await this.db.updateDeployment( + { + domainId: customDomain.id, + }, + { + domain: null, + }, + ); + } + + if(customDomain && applicationDeploymentRequestData) { + newCurrentDeployment.domain = customDomain + } + // Create a DNS deployment for the new current deployment const dnsDeployment = await this.createDeploymentFromData( newCurrentDeployment.project.ownerId, @@ -1265,9 +1286,6 @@ export class Service { true, ); - const applicationDeploymentRequestData = newCurrentDeployment.applicationDeploymentRequestData; - - applicationDeploymentRequestData!.version = (Number(applicationDeploymentRequestData?.version) + 1).toString(); applicationDeploymentRequestData!.meta = JSON.stringify({ ...JSON.parse(applicationDeploymentRequestData!.meta), note: `Updated by Snowball @ ${DateTime.utc().toFormat(