Fix deployments visit URL and date filter (#78)

* Add method to update multiple deployments in single query

* Fix deployments URL visit and date filter

* Clean fixtures data

* Update fixtures data

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
2024-02-20 10:53:42 +05:30
committed by GitHub
co-authored by neeraj
parent c3d1b4f3eb
commit a45fb4c617
14 changed files with 45 additions and 247 deletions
+13
View File
@@ -316,6 +316,19 @@ export class Database {
return Boolean(updateResult.affected);
}
async updateDeploymentsByProjectIds (projectIds: string[], data: DeepPartial<Deployment>): Promise<boolean> {
const deploymentRepository = this.dataSource.getRepository(Deployment);
const updateResult = await deploymentRepository
.createQueryBuilder()
.update(Deployment)
.set(data)
.where('projectId IN (:...projectIds)', { projectIds })
.execute();
return Boolean(updateResult.affected);
}
async addProject (userId: string, organizationId: string, data: DeepPartial<Project>): Promise<Project> {
const projectRepository = this.dataSource.getRepository(Project);
+5 -11
View File
@@ -78,7 +78,9 @@ export class Service {
log(`Found ${records.length} ApplicationDeploymentRecords`);
// Update deployments for which ApplicationDeploymentRecords were returned
await this.updateDeploymentsWithRecordData(records);
if (records.length) {
await this.updateDeploymentsWithRecordData(records);
}
}
this.deployRecordCheckTimeout = setTimeout(() => {
@@ -110,10 +112,7 @@ export class Service {
}, new Set<string>());
// Set old deployments isCurrent to false
await Promise.all(Array.from(productionDeploymentProjectIds).map(
// TODO: Add DB method to update multiple deployments in single query
async (projectId) => this.db.updateDeployment({ projectId }, { isCurrent: false })
));
await this.db.updateDeploymentsByProjectIds(Array.from(productionDeploymentProjectIds), { isCurrent: false });
const recordToDeploymentsMap = deployments.reduce((acc: {[key: string]: Deployment}, deployment) => {
acc[deployment.applicationRecordId] = deployment;
@@ -135,7 +134,7 @@ export class Service {
}
);
log(`Updated deployment deployment ${deployment.id} with URL ${record.attributes.url}`);
log(`Updated deployment ${deployment.id} with URL ${record.attributes.url}`);
});
await Promise.all(deploymentUpdatePromises);
@@ -295,7 +294,6 @@ export class Service {
octokit,
{
project: oldDeployment.project,
isCurrent: true,
branch: oldDeployment.branch,
environment: Environment.Production,
domain: prodBranchDomains[0],
@@ -357,7 +355,6 @@ export class Service {
commitHash: data.commitHash,
commitMessage: data.commitMessage,
environment: data.environment,
isCurrent: data.isCurrent,
status: DeploymentStatus.Building,
applicationRecordId,
applicationRecordData,
@@ -400,7 +397,6 @@ export class Service {
octokit,
{
project,
isCurrent: true,
branch: project.prodBranch,
environment: Environment.Production,
domain: null,
@@ -486,7 +482,6 @@ export class Service {
octokit,
{
project,
isCurrent: project.prodBranch === branch,
branch,
environment: project.prodBranch === branch ? Environment.Production : Environment.Preview,
domain,
@@ -543,7 +538,6 @@ export class Service {
project: oldDeployment.project,
// TODO: Put isCurrent field in project
branch: oldDeployment.branch,
isCurrent: true,
environment: Environment.Production,
domain: oldDeployment.domain,
commitHash: oldDeployment.commitHash,
+2 -2
View File
@@ -6,7 +6,7 @@
},
{
"id": "7eb9b3eb-eb74-4b53-b59a-69884c82a7fb",
"name": "AirFoil",
"slug": "airfoil-2"
"name": "Laconic",
"slug": "laconic-2"
}
]
+6 -6
View File
@@ -1,37 +1,37 @@
[
{
"projectIndex": 0,
"name": "randomurl.snowballtools.xyz",
"name": "example.snowballtools.xyz",
"status": "Live",
"branch": "main"
},
{
"projectIndex": 0,
"name": "saugatt.com",
"name": "example.org",
"status": "Pending",
"branch": "test"
},
{
"projectIndex": 1,
"name": "randomurl.snowballtools.xyz",
"name": "example.snowballtools.xyz",
"status": "Live",
"branch": "main"
},
{
"projectIndex": 1,
"name": "saugatt.com",
"name": "example.org",
"status": "Pending",
"branch": "test"
},
{
"projectIndex": 2,
"name": "randomurl.snowballtools.xyz",
"name": "example.snowballtools.xyz",
"status": "Live",
"branch": "main"
},
{
"projectIndex": 2,
"name": "saugatt.com",
"name": "example.org",
"status": "Pending",
"branch": "test"
},
+3 -3
View File
@@ -1,21 +1,21 @@
[
{
"projectIndex": 0,
"name": "www.saugatt.com",
"name": "www.example.org",
"status": "Pending",
"redirectToIndex": 1,
"branch": "test"
},
{
"projectIndex": 1,
"name": "www.saugatt.com",
"name": "www.example.org",
"status": "Pending",
"redirectToIndex": 3,
"branch": "test"
},
{
"projectIndex": 2,
"name": "www.saugatt.com",
"name": "www.example.org",
"status": "Pending",
"redirectToIndex": 5,
"branch": "test"
+6 -6
View File
@@ -1,20 +1,20 @@
[
{
"id": "59f4355d-9549-4aac-9b54-eeefceeabef0",
"name": "Saugat Yadav",
"email": "saugaty@airfoil.studio",
"name": "Snowball",
"email": "snowball@snowballtools.xyz",
"isVerified": true
},
{
"id": "e505b212-8da6-48b2-9614-098225dab34b",
"name": "Gideon Low",
"email": "gideonl@airfoil.studio",
"name": "Alice Anderson",
"email": "alice@snowballtools.xyz",
"isVerified": true
},
{
"id": "cd892fad-9138-4aa2-a62c-414a32776ea7",
"name": "Sushan Yadav",
"email": "sushany@airfoil.studio",
"name": "Bob Banner",
"email": "bob@snowballtools.xyz",
"isVerified": true
}
]
+1 -1
View File
@@ -20,7 +20,7 @@ const log = debug('snowball:initialize-database');
const USER_DATA_PATH = './fixtures/users.json';
const PROJECT_DATA_PATH = './fixtures/projects.json';
const ORGANIZATION_DATA_PATH = './fixtures/organizations.json';
const USER_ORGANIZATION_DATA_PATH = './fixtures/user-orgnizations.json';
const USER_ORGANIZATION_DATA_PATH = './fixtures/user-organizations.json';
const PROJECT_MEMBER_DATA_PATH = './fixtures/project-members.json';
const PRIMARY_DOMAIN_DATA_PATH = './fixtures/primary-domains.json';
const DEPLOYMENT_DATA_PATH = './fixtures/deployments.json';