fix: re-install graphql plugin in workspaces (#16764)
* re-install graphql plugin in workspaces
This commit is contained in:
parent
4fd6e61b42
commit
ecec0e1975
|
|
@ -54,6 +54,7 @@ import com.appsmith.server.domains.QNotification;
|
|||
import com.appsmith.server.domains.QOrganization;
|
||||
import com.appsmith.server.domains.QPlugin;
|
||||
import com.appsmith.server.domains.QUserData;
|
||||
import com.appsmith.server.domains.QWorkspace;
|
||||
import com.appsmith.server.domains.Role;
|
||||
import com.appsmith.server.domains.Sequence;
|
||||
import com.appsmith.server.domains.User;
|
||||
|
|
@ -235,18 +236,23 @@ public class DatabaseChangelog {
|
|||
}
|
||||
|
||||
public static void installPluginToAllWorkspaces(MongockTemplate mongockTemplate, String pluginId) {
|
||||
for (Workspace workspace : mongockTemplate.findAll(Workspace.class)) {
|
||||
Query queryToFetchAllWorkspaceIds = new Query();
|
||||
/* Filter in only those workspaces that don't have the plugin installed */
|
||||
queryToFetchAllWorkspaceIds.addCriteria(Criteria.where("plugins.pluginId").ne(pluginId));
|
||||
/* Only read the workspace id and leave out other fields */
|
||||
queryToFetchAllWorkspaceIds.fields().include(fieldName(QWorkspace.workspace.id));
|
||||
List<Workspace> workspacesWithOnlyId = mongockTemplate.find(queryToFetchAllWorkspaceIds, Workspace.class);
|
||||
for (Workspace workspaceWithId : workspacesWithOnlyId) {
|
||||
Workspace workspace =
|
||||
mongockTemplate.findOne(query(where(fieldName(QWorkspace.workspace.id)).is(workspaceWithId.getId())),
|
||||
Workspace.class);
|
||||
|
||||
if (CollectionUtils.isEmpty(workspace.getPlugins())) {
|
||||
workspace.setPlugins(new HashSet<>());
|
||||
}
|
||||
|
||||
final Set<String> installedPlugins = workspace.getPlugins()
|
||||
.stream().map(WorkspacePlugin::getPluginId).collect(Collectors.toSet());
|
||||
|
||||
if (!installedPlugins.contains(pluginId)) {
|
||||
workspace.getPlugins()
|
||||
.add(new WorkspacePlugin(pluginId, WorkspacePluginStatus.FREE));
|
||||
}
|
||||
workspace.getPlugins()
|
||||
.add(new WorkspacePlugin(pluginId, WorkspacePluginStatus.FREE));
|
||||
|
||||
mongockTemplate.save(workspace);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2580,4 +2580,17 @@ public class DatabaseChangelog2 {
|
|||
|
||||
installPluginToAllWorkspaces(mongoTemplate, plugin.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method attempts to add GraphQL plugin to all workspaces once again since the last migration was
|
||||
* interrupted due to issues on prod cluster. Hence, during the last migration the plugin could not be installed in
|
||||
* few workspaces.The method installPluginToAllWorkspaces only installs the plugin in those workspaces where it is
|
||||
* missing.
|
||||
*/
|
||||
@ChangeSet(order = "037", id = "install-graphql-plugin-to-remaining-workspaces", author = "")
|
||||
public void reInstallGraphQLPluginToWorkspaces(MongockTemplate mongoTemplate) {
|
||||
Plugin graphQLPlugin = mongoTemplate
|
||||
.findOne(query(where("packageName").is("graphql-plugin")), Plugin.class);
|
||||
installPluginToAllWorkspaces(mongoTemplate, graphQLPlugin.getId());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user