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

feat(database): Sync current user database objects with all projects when grouping databases #4236

Open
wants to merge 1 commit into
base: dev/4.3.x
Choose a base branch
from
Open
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
Expand Up @@ -68,5 +68,12 @@ public SuccessResponse<Boolean> syncDatabaseObjects(@RequestBody SyncDBObjectReq
return Responses.success(dbSchemaIndexService.syncDatabaseObjects(req));
}

@ApiOperation(value = "syncCurrentUserDatabaseObjectsWithProject",
notes = "Sync all database objects under the project that the current user is joining")
@RequestMapping(value = "/syncAllWithProject", method = RequestMethod.POST)
public SuccessResponse<Boolean> syncCurrentUserDatabaseObjectsWithProject() {
return Responses.success(dbSchemaIndexService.syncCurrentUserDatabaseObjectsWithProject());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public interface DatabaseRepository extends JpaRepository<DatabaseEntity, Long>,

List<DatabaseEntity> findByProjectIdAndExisted(Long projectId, Boolean existed);

List<DatabaseEntity> findByProjectIdInAndExistedAndObjectSyncStatusNot(Collection<Long> projectIds, Boolean existed,
DBObjectSyncStatus dbObjectSyncStatus);

List<DatabaseEntity> findByIdIn(Collection<Long> ids);

List<DatabaseEntity> findByNameIn(Collection<String> name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,17 @@ public Set<Database> listExistDatabasesByProjectId(@NonNull Long projectId) {
.map(databaseMapper::entityToModel).collect(Collectors.toSet());
}

@SkipAuthorize("internal usage")
public Set<Database> listExistAndNotPendingDatabasesByProjectIdIn(@NonNull Collection<Long> projectIds) {
if (CollectionUtils.isEmpty(projectIds)) {
return Collections.emptySet();
}
return databaseRepository
.findByProjectIdInAndExistedAndObjectSyncStatusNot(projectIds, true, DBObjectSyncStatus.PENDING)
.stream()
.map(databaseMapper::entityToModel).collect(Collectors.toSet());
}

@SkipAuthorize("internal usage")
public Set<Database> listDatabaseByNames(@NotEmpty Collection<String> names) {
return databaseRepository.findByNameIn(names).stream().map(databaseMapper::entityToModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ public QueryDBObjectResp listDatabaseObjects(@NonNull @Valid QueryDBObjectParams
return resp;
}

public Boolean syncCurrentUserDatabaseObjectsWithProject() {
this.databaseService.refreshExpiredPendingDBObjectStatus();
long userId = authenticationFacade.currentUserId();
Set<Long> joinedProjectIds = projectService.getMemberProjectIds(userId);
if (CollectionUtils.isEmpty(joinedProjectIds)) {
return true;
}
dbSchemaSyncTaskManager
.submitTaskByDatabases(databaseService.listExistAndNotPendingDatabasesByProjectIdIn(joinedProjectIds));
return true;
}

public Boolean syncDatabaseObjects(@NonNull @Valid SyncDBObjectReq req) {
this.databaseService.refreshExpiredPendingDBObjectStatus();
Set<Database> databases = new HashSet<>();
Expand Down