From 44f7c048ed773b3a2f790e1dcd47fc8504df5f1d Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Wed, 26 Jun 2024 00:13:57 +0530 Subject: [PATCH] feat: rename app deploy status live to deployed (#877) (cherry picked from commit 47106cae92517f9060078f055d1eeec175910372) --- swiftwave_service/core/application.operations.go | 6 +++--- swiftwave_service/core/deployment.operations.go | 8 ++++---- swiftwave_service/core/types.go | 2 +- ...0624161343_rename_app_status_live_to_deployed.down.sql | 2 ++ ...250624161343_rename_app_status_live_to_deployed.up.sql | 2 ++ swiftwave_service/db/migrations/atlas.sum | 4 +++- swiftwave_service/graphql/application.resolvers.go | 2 +- swiftwave_service/graphql/model/models_gen.go | 6 +++--- swiftwave_service/graphql/schema/deployment.graphqls | 2 +- swiftwave_service/rest/webhook.go | 2 +- .../worker/process_application_deploy_request.go | 4 ++-- 11 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 swiftwave_service/db/migrations/20250624161343_rename_app_status_live_to_deployed.down.sql create mode 100644 swiftwave_service/db/migrations/20250624161343_rename_app_status_live_to_deployed.up.sql diff --git a/swiftwave_service/core/application.operations.go b/swiftwave_service/core/application.operations.go index 9b8728058f..1a5d1325bc 100644 --- a/swiftwave_service/core/application.operations.go +++ b/swiftwave_service/core/application.operations.go @@ -64,7 +64,7 @@ type ApplicationDeploymentInfo struct { func FindApplicationsForForceUpdate(_ context.Context, db gorm.DB) ([]*ApplicationDeploymentInfo, error) { var deployments []*Deployment - err := db.Model(&Deployment{}).Where("status = ?", DeploymentStatusLive).Scan(&deployments).Error + err := db.Model(&Deployment{}).Where("status = ?", DeploymentStatusDeployed).Scan(&deployments).Error if err != nil { return nil, err } @@ -617,7 +617,7 @@ func (application *Application) Update(ctx context.Context, db gorm.DB, _ contai isReloadRequired = true } // update deployment -- if required - currentDeploymentID, err := FindCurrentLiveDeploymentIDByApplicationId(ctx, db, application.ID) + currentDeploymentID, err := FindCurrentDeployedDeploymentIDByApplicationId(ctx, db, application.ID) if err != nil { currentDeploymentID, err = FindLatestDeploymentIDByApplicationId(ctx, db, application.ID) } @@ -694,7 +694,7 @@ func (application *Application) RebuildApplication(ctx context.Context, db gorm. return "", err } // create a new deployment from latest deployment - latestDeployment, err := FindCurrentLiveDeploymentByApplicationId(ctx, db, application.ID) + latestDeployment, err := FindCurrentDeployedDeploymentByApplicationId(ctx, db, application.ID) if err != nil { latestDeployment, err = FindLatestDeploymentByApplicationId(ctx, db, application.ID) if err != nil { diff --git a/swiftwave_service/core/deployment.operations.go b/swiftwave_service/core/deployment.operations.go index a2dc3c064f..ddf5fc8197 100644 --- a/swiftwave_service/core/deployment.operations.go +++ b/swiftwave_service/core/deployment.operations.go @@ -24,9 +24,9 @@ func FindLatestDeploymentByApplicationId(ctx context.Context, db gorm.DB, id str return deployment, nil } -func FindCurrentLiveDeploymentByApplicationId(ctx context.Context, db gorm.DB, id string) (*Deployment, error) { +func FindCurrentDeployedDeploymentByApplicationId(ctx context.Context, db gorm.DB, id string) (*Deployment, error) { var deployment = &Deployment{} - tx := db.Where("application_id = ? AND status = ?", id, DeploymentStatusLive).Order("created_at desc").First(&deployment) + tx := db.Where("application_id = ? AND status = ?", id, DeploymentStatusDeployed).Order("created_at desc").First(&deployment) if tx.Error != nil { return nil, tx.Error } @@ -42,9 +42,9 @@ func FindLatestDeploymentIDByApplicationId(ctx context.Context, db gorm.DB, id s return deployment.ID, nil } -func FindCurrentLiveDeploymentIDByApplicationId(ctx context.Context, db gorm.DB, id string) (string, error) { +func FindCurrentDeployedDeploymentIDByApplicationId(ctx context.Context, db gorm.DB, id string) (string, error) { var deployment = &Deployment{} - tx := db.Select("id").Where("application_id = ? AND status = ?", id, DeploymentStatusLive).Order("created_at desc").First(&deployment) + tx := db.Select("id").Where("application_id = ? AND status = ?", id, DeploymentStatusDeployed).Order("created_at desc").First(&deployment) if tx.Error != nil { return "", tx.Error } diff --git a/swiftwave_service/core/types.go b/swiftwave_service/core/types.go index 74297d7944..7bd63513e3 100644 --- a/swiftwave_service/core/types.go +++ b/swiftwave_service/core/types.go @@ -82,7 +82,7 @@ type DeploymentStatus string const ( DeploymentStatusPending DeploymentStatus = "pending" DeploymentStatusDeployPending DeploymentStatus = "deployPending" - DeploymentStatusLive DeploymentStatus = "live" + DeploymentStatusDeployed DeploymentStatus = "deployed" DeploymentStatusStopped DeploymentStatus = "stopped" DeploymentStatusFailed DeploymentStatus = "failed" DeploymentStalled DeploymentStatus = "stalled" diff --git a/swiftwave_service/db/migrations/20250624161343_rename_app_status_live_to_deployed.down.sql b/swiftwave_service/db/migrations/20250624161343_rename_app_status_live_to_deployed.down.sql new file mode 100644 index 0000000000..b3bc4a0d89 --- /dev/null +++ b/swiftwave_service/db/migrations/20250624161343_rename_app_status_live_to_deployed.down.sql @@ -0,0 +1,2 @@ +-- reverse: modify "deployments" table +UPDATE "public"."deployments" SET status = 'live' WHERE status = 'deployed'; diff --git a/swiftwave_service/db/migrations/20250624161343_rename_app_status_live_to_deployed.up.sql b/swiftwave_service/db/migrations/20250624161343_rename_app_status_live_to_deployed.up.sql new file mode 100644 index 0000000000..d3b2081611 --- /dev/null +++ b/swiftwave_service/db/migrations/20250624161343_rename_app_status_live_to_deployed.up.sql @@ -0,0 +1,2 @@ +-- modify "deployments" table +UPDATE "public"."deployments" SET status = 'deployed' WHERE status = 'live'; diff --git a/swiftwave_service/db/migrations/atlas.sum b/swiftwave_service/db/migrations/atlas.sum index 3e2d27d852..26089ee5cf 100644 --- a/swiftwave_service/db/migrations/atlas.sum +++ b/swiftwave_service/db/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:MBKMEy89E8d/dJ6qPEDgVvyviAQkEIIZ2wIVMUmbgqg= +h1:b432hkpq37nDG1czxt21T1S/temPuIUoQ3fyuehkN+M= 20240413191732_init.down.sql h1:HoitObGwuKF/akF4qg3dol2FfNTLCEuf6wHYDuCez8I= 20240413191732_init.up.sql h1:USKdQx/yTz1KJ0+mDwYGhKm3WzX7k+I9+6B6SxImwaE= 20240414051823_server_custom_ssh_port_added.down.sql h1:IC1DFQBQceTPTRdZOo5/WqytH+ZbgcKrQuMCkhArF/0= @@ -39,3 +39,5 @@ h1:MBKMEy89E8d/dJ6qPEDgVvyviAQkEIIZ2wIVMUmbgqg= 20240620100729_add_app_custom_healthcheck.up.sql h1:kgZY1IBSRF3OXwoAdleIKVtcnbj+AT/f6K8AR1s/7yg= 20240624161343_add_commit_msg_to_deployment.down.sql h1:tSOS19XmAJvwaAwpbIppYfi5PvRQ2HWz1Go2JGlWNP8= 20240624161343_add_commit_msg_to_deployment.up.sql h1:JrOb5F2VQkKNAQygCCvy2WEK4u80xsbWWty+bVlNM2w= +20250624161343_rename_app_status_live_to_deployed.down.sql h1:eBRrKO112ul0fqIibuE71ASQFoFQZixRN8qGp9V/RsI= +20250624161343_rename_app_status_live_to_deployed.up.sql h1:4/ngjaqebN9HiQSGmKyy0B5vYtLeyRkdYS0Yu2QUSRM= diff --git a/swiftwave_service/graphql/application.resolvers.go b/swiftwave_service/graphql/application.resolvers.go index 3e96fa8584..9cae82d6cc 100644 --- a/swiftwave_service/graphql/application.resolvers.go +++ b/swiftwave_service/graphql/application.resolvers.go @@ -95,7 +95,7 @@ func (r *applicationResolver) RealtimeInfo(ctx context.Context, obj *model.Appli // LatestDeployment is the resolver for the latestDeployment field. func (r *applicationResolver) LatestDeployment(ctx context.Context, obj *model.Application) (*model.Deployment, error) { // fetch running instance - record, err := core.FindCurrentLiveDeploymentByApplicationId(ctx, r.ServiceManager.DbClient, obj.ID) + record, err := core.FindCurrentDeployedDeploymentByApplicationId(ctx, r.ServiceManager.DbClient, obj.ID) if err != nil { record, err = core.FindLatestDeploymentByApplicationId(ctx, r.ServiceManager.DbClient, obj.ID) if err != nil { diff --git a/swiftwave_service/graphql/model/models_gen.go b/swiftwave_service/graphql/model/models_gen.go index de7fed7a8a..a1475e3cdd 100644 --- a/swiftwave_service/graphql/model/models_gen.go +++ b/swiftwave_service/graphql/model/models_gen.go @@ -742,7 +742,7 @@ const ( DeploymentStatusPending DeploymentStatus = "pending" DeploymentStatusDeployPending DeploymentStatus = "deployPending" DeploymentStatusDeploying DeploymentStatus = "deploying" - DeploymentStatusLive DeploymentStatus = "live" + DeploymentStatusDeployed DeploymentStatus = "deployed" DeploymentStatusStopped DeploymentStatus = "stopped" DeploymentStatusFailed DeploymentStatus = "failed" DeploymentStatusStalled DeploymentStatus = "stalled" @@ -752,7 +752,7 @@ var AllDeploymentStatus = []DeploymentStatus{ DeploymentStatusPending, DeploymentStatusDeployPending, DeploymentStatusDeploying, - DeploymentStatusLive, + DeploymentStatusDeployed, DeploymentStatusStopped, DeploymentStatusFailed, DeploymentStatusStalled, @@ -760,7 +760,7 @@ var AllDeploymentStatus = []DeploymentStatus{ func (e DeploymentStatus) IsValid() bool { switch e { - case DeploymentStatusPending, DeploymentStatusDeployPending, DeploymentStatusDeploying, DeploymentStatusLive, DeploymentStatusStopped, DeploymentStatusFailed, DeploymentStatusStalled: + case DeploymentStatusPending, DeploymentStatusDeployPending, DeploymentStatusDeploying, DeploymentStatusDeployed, DeploymentStatusStopped, DeploymentStatusFailed, DeploymentStatusStalled: return true } return false diff --git a/swiftwave_service/graphql/schema/deployment.graphqls b/swiftwave_service/graphql/schema/deployment.graphqls index b8d08ccb21..c010c8a096 100644 --- a/swiftwave_service/graphql/schema/deployment.graphqls +++ b/swiftwave_service/graphql/schema/deployment.graphqls @@ -8,7 +8,7 @@ enum DeploymentStatus { pending deployPending deploying - live + deployed stopped failed stalled diff --git a/swiftwave_service/rest/webhook.go b/swiftwave_service/rest/webhook.go index 66a09721a8..807931dfb3 100644 --- a/swiftwave_service/rest/webhook.go +++ b/swiftwave_service/rest/webhook.go @@ -36,7 +36,7 @@ func (server *Server) redeployApp(c echo.Context) error { return c.String(401, "Unauthorized") } // Fetch latest deployment - deployment, err := core.FindCurrentLiveDeploymentByApplicationId(ctx, server.ServiceManager.DbClient, application.ID) + deployment, err := core.FindCurrentDeployedDeploymentByApplicationId(ctx, server.ServiceManager.DbClient, application.ID) if err != nil { _, err = core.FindLatestDeploymentByApplicationId(ctx, server.ServiceManager.DbClient, application.ID) if errors.Is(err, gorm.ErrRecordNotFound) { diff --git a/swiftwave_service/worker/process_application_deploy_request.go b/swiftwave_service/worker/process_application_deploy_request.go index a4e19fb429..26f829e211 100644 --- a/swiftwave_service/worker/process_application_deploy_request.go +++ b/swiftwave_service/worker/process_application_deploy_request.go @@ -251,7 +251,7 @@ func (m Manager) deployApplicationHelper(request DeployApplicationRequest, docke }, } // find current deployment and mark it as stalled - currentDeployment, err := core.FindCurrentLiveDeploymentByApplicationId(ctx, *db, request.AppId) + currentDeployment, err := core.FindCurrentDeployedDeploymentByApplicationId(ctx, *db, request.AppId) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { return err @@ -264,7 +264,7 @@ func (m Manager) deployApplicationHelper(request DeployApplicationRequest, docke } } // update deployment status - err = deployment.UpdateStatus(ctx, *db, core.DeploymentStatusLive) + err = deployment.UpdateStatus(ctx, *db, core.DeploymentStatusDeployed) if err != nil { return err }