Add GQL mutation for redeploying deployment to production (#42)

* Add graphql mutation to redeploy deployment to production

* Implement frontend to redeploy deployment to production

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
2024-02-01 11:37:57 +05:30
committed by Ashwin Phatak
co-authored by neeraj
parent 5310d7c7d0
commit 0feeb9408d
11 changed files with 99 additions and 22 deletions
+2 -1
View File
@@ -24,6 +24,7 @@
{
"allowArgumentsExplicitlyTypedAsAny": true
}
]
],
"@typescript-eslint/no-unused-vars": ["error", { "ignoreRestSiblings": true }]
}
}
+33 -1
View File
@@ -8,7 +8,7 @@ import { User } from './entity/User';
import { Organization } from './entity/Organization';
import { UserOrganization } from './entity/UserOrganization';
import { Project } from './entity/Project';
import { Deployment } from './entity/Deployment';
import { Deployment, Environment } from './entity/Deployment';
import { ProjectMember } from './entity/ProjectMember';
import { EnvironmentVariable } from './entity/EnvironmentVariable';
@@ -243,4 +243,36 @@ export class Database {
return false;
}
}
async redeployToProdById (deploymentId: string): Promise<boolean> {
const deploymentRepository = this.dataSource.getRepository(Deployment);
const deployment = await deploymentRepository.findOne({
relations: {
project: true,
domain: true
},
where: {
id: Number(deploymentId)
}
});
if (deployment === null) {
throw new Error('Deployment not found');
}
const { id, createdAt, updatedAt, ...updatedDeployment } = deployment;
if (updatedDeployment.environment === Environment.Production) {
// TODO: Put isCurrent field in project
updatedDeployment.isCurrent = true;
}
await deploymentRepository.update({ id: Number(deploymentId) }, { domain: null, isCurrent: false });
const savedUpdatedDeployment = await deploymentRepository.save(updatedDeployment);
if (savedUpdatedDeployment) {
return true;
} else {
return false;
}
}
}
+1 -1
View File
@@ -35,7 +35,7 @@ export class Deployment {
@OneToOne(() => Domain)
@JoinColumn({ name: 'domainId' })
domain!: Domain;
domain!: Domain | null;
@Column('varchar')
branch!: string;
+9
View File
@@ -146,6 +146,15 @@ export const createResolvers = async (db: Database): Promise<any> => {
log(err);
return false;
}
},
redeployToProd: async (_: any, { deploymentId }: {deploymentId: string }) => {
try {
return db.redeployToProdById(deploymentId);
} catch (err) {
log(err);
return false;
}
}
}
};
+1
View File
@@ -127,6 +127,7 @@ type Mutation {
addEnvironmentVariables(projectId: String!, environmentVariables: [AddEnvironmentVariableInput!]): Boolean!
updateDeploymentToProd(deploymentId: String!): Boolean!
updateProject(projectId: String!, updateProject: UpdateProjectInput): Boolean!
redeployToProd(deploymentId: String!): Boolean!
}
input AddEnvironmentVariableInput {
+6 -6
View File
@@ -5,7 +5,7 @@
"title": "nextjs-boilerplate-1",
"status": "Building",
"environment": "Production",
"isCurrent": false,
"isCurrent": true,
"branch": "prod",
"commitHash": "testXyz"
},
@@ -15,7 +15,7 @@
"title": "nextjs-boilerplate-2",
"status": "Ready",
"environment": "Preview",
"isCurrent": true,
"isCurrent": false,
"branch": "prod",
"commitHash": "testXyz"
},
@@ -35,7 +35,7 @@
"title": "nextjs-boilerplate-1",
"status": "Building",
"environment": "Production",
"isCurrent": false,
"isCurrent": true,
"branch": "prod",
"commitHash": "testXyz"
},
@@ -45,7 +45,7 @@
"title": "nextjs-boilerplate-2",
"status": "Ready",
"environment": "Preview",
"isCurrent": true,
"isCurrent": false,
"branch": "prod",
"commitHash": "testXyz"
},
@@ -65,7 +65,7 @@
"title": "nextjs-boilerplate-1",
"status": "Building",
"environment": "Production",
"isCurrent": false,
"isCurrent": true,
"branch": "prod",
"commitHash": "testXyz"
},
@@ -75,7 +75,7 @@
"title": "nextjs-boilerplate-2",
"status": "Ready",
"environment": "Preview",
"isCurrent": true,
"isCurrent": false,
"branch": "prod",
"commitHash": "testXyz"
},
+5 -7
View File
@@ -117,14 +117,12 @@ const main = async () => {
await dataSource.initialize();
await generateTestData(dataSource);
log('Data loaded successfully');
} else {
throw new Error('Database already exists');
log('WARNING: Database already exists');
}
};
main().then(() => {
log('Data loaded successfully');
})
.catch((err) => {
log(err);
});
main().catch((err) => {
log(err);
});