From 0c297c1d5c9ec8a8771674e3a9a57e39827ace2a Mon Sep 17 00:00:00 2001 From: "toni.zamparetti" Date: Fri, 19 Jun 2026 10:45:24 -0300 Subject: [PATCH] fix in issue: delete an account belonging to a deleted project --- .../projects/dao/ProjectAccountDaoImpl.java | 1 - .../upgrade/dao/Upgrade42030to42040.java | 10 +++++++- .../META-INF/db/schema-42030to42040.sql | 24 +++++++++++++++++++ .../META-INF/db/schema-42210to42300.sql | 0 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 engine/schema/src/main/resources/META-INF/db/schema-42030to42040.sql create mode 100644 engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql diff --git a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java index b6eb6d44cea8..54d73e36d594 100644 --- a/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java +++ b/engine/schema/src/main/java/com/cloud/projects/dao/ProjectAccountDaoImpl.java @@ -52,7 +52,6 @@ protected ProjectAccountDaoImpl() { ProjectAccountSearch = createSearchBuilder(); ProjectAccountSearch.and("projectId", ProjectAccountSearch.entity().getProjectId(), SearchCriteria.Op.EQ); ProjectAccountSearch.and("accountId", ProjectAccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ); - ProjectAccountSearch.and("userId", ProjectAccountSearch.entity().getUserId(), Op.NULL); ProjectAccountSearch.done(); diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42030to42040.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42030to42040.java index 90f69a87cb03..4b03dfcfbb1b 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42030to42040.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42030to42040.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.upgrade.dao; +import com.cloud.utils.exception.CloudRuntimeException; + import java.io.InputStream; import java.sql.Connection; import java.util.ArrayList; @@ -40,7 +42,13 @@ public boolean supportsRollingUpgrade() { @Override public InputStream[] getPrepareScripts() { - return null; + final String scriptFile = "META-INF/db/schema-42030to42040.sql"; + final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile); + if (script == null) { + throw new CloudRuntimeException("Unable to find " + scriptFile); + } + + return new InputStream[] {script}; } @Override diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42030to42040.sql b/engine/schema/src/main/resources/META-INF/db/schema-42030to42040.sql new file mode 100644 index 000000000000..0358b3e79092 --- /dev/null +++ b/engine/schema/src/main/resources/META-INF/db/schema-42030to42040.sql @@ -0,0 +1,24 @@ +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. + +--; +-- Schema upgrade from 4.20.3.0 to 4.20.4.0 +--; + +-- Normalization of project accounts for deleted projects + +DELETE pa FROM project_account pa JOIN projects p ON pa.project_id = p.id WHERE p.removed IS NOT NULL AND pa.user_id IS NOT NULL; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql b/engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql new file mode 100644 index 000000000000..e69de29bb2d1