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(cd-service): sync all_app_locks with app_locks #2153

Merged
merged 2 commits into from
Dec 2, 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
@@ -0,0 +1,40 @@
WITH combinations AS (
SELECT
DISTINCT environment,
appname
FROM
all_app_locks ),
latest_app_locks_versions AS (
SELECT MAX(eslversion) AS latest,
envname,
appname,
lockID FROM app_locks GROUP BY envname, appname, lockId
),
new_data AS (
SELECT
c.environment,
c.appname,
JSON_BUILD_OBJECT('appLocks', COALESCE(JSON_AGG(t.lockID) FILTER (WHERE t.lockID IS NOT NULL), '[]'::json)) AS json
FROM
combinations c
LEFT JOIN (SELECT al.eslversion, al.envname, al.appname, al.lockId FROM latest_app_locks_versions la
JOIN app_locks al ON al.eslversion=la.latest AND al.envname=la.envname AND al.appname=la.appname AND al.lockId=la.lockId WHERE deleted=false) AS t
ON
c.environment = t.envname
AND c.appname = t.appname
GROUP BY
c.environment,
c.appname ),
latest_versions AS (
SELECT
environment,
appname,
COALESCE(MAX(version), 0) AS max_version
FROM
all_app_locks
GROUP BY
environment,
appname )
INSERT INTO all_app_locks (version, created, environment, appname, json)
SELECT max_version + 1, now(), lv.environment, lv.appname, t.json FROM new_data t LEFT JOIN latest_versions lv ON t.environment = lv.environment AND t.appname = lv.appname;
INSERT INTO overview_cache (timestamp, json) VALUES (now(), '{}');
1 change: 1 addition & 0 deletions services/cd-service/pkg/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ func RunServer() {
reposerver.Register(srv, repo, cfg)
if dbHandler != nil {
api.RegisterCommitDeploymentServiceServer(srv, &service.CommitDeploymentServer{DBHandler: dbHandler})
_, _ = overviewSrv.GetOverview(ctx, &api.GetOverviewRequest{GitRevision: ""})
}
},
},
Expand Down
4 changes: 4 additions & 0 deletions services/cd-service/pkg/repository/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,10 @@ func (u *UndeployApplication) Transform(
return "", err
}
}
err = state.DBHandler.DBWriteAllAppLocks(ctx, transaction, locks.Version, env, u.Application, []string{})
if err != nil {
return "", err
}
continue
}
return "", fmt.Errorf("UndeployApplication(db): error cannot un-deploy application '%v' the release '%v' is not un-deployed", u.Application, env)
Expand Down
Loading