Skip to content

Commit

Permalink
feat(migrate): migrate history uniqueIdentifier in collaboration_proj…
Browse files Browse the repository at this point in the history
…ect (#2377)

* migrate history uniqueIdentifier in collaboration_project

* modify unique key name

* fix ut test

* response to reveiw
  • Loading branch information
PeachThinking authored May 14, 2024
1 parent 6a0eaea commit b7605ac
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ private ProjectEntity getProjectEntity() {
entity.setOrganizationId(1L);
entity.setLastModifierId(1L);
entity.setCreatorId(1L);
entity.setUniqueIdentifier("ODC_" + UUID.randomUUID());
return entity;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ALTER TABLE `collaboration_project` ADD COLUMN `unique_identifier` VARCHAR(128) DEFAULT NULL COMMENT 'Unique identifier, from external system';
ALTER TABLE `collaboration_project` ADD COLUMN `unique_identifier` VARCHAR(128) DEFAULT NULL COMMENT 'Unique identifier, may from external system or UUID generated by ODC if no external identifier';
UPDATE `collaboration_project` set `unique_identifier`=concat('ODC_', uuid()) where unique_identifier IS NULL;
ALTER TABLE `collaboration_project` ADD UNIQUE KEY `uk_collaboration_project_unique_identifier` (`unique_identifier`);
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,10 @@ public class ProjectEntity {

@Column(name = "last_modifier_id", nullable = false)
private Long lastModifierId;

/**
* Unique identifier, may from external system or UUID generated by ODC if no external identifier
*/
@Column(name = "unique_identifier", nullable = false)
private String uniqueIdentifier;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -150,6 +151,7 @@ public void createProjectIfNotExists(@NotNull User user) {
projectEntity.setLastModifierId(user.getCreatorId());
projectEntity.setOrganizationId(user.getOrganizationId());
projectEntity.setDescription("Built-in project for bastion user " + user.getAccountName());
projectEntity.setUniqueIdentifier(generateProjectUniqueIdentifier());
ProjectEntity saved = repository.saveAndFlush(projectEntity);
// Grant DEVELOPER role to bastion user, and all other roles to user creator(admin)
Map<ResourceRoleName, ResourceRoleEntity> resourceRoleName2Entity =
Expand Down Expand Up @@ -179,6 +181,7 @@ public Project create(@NotNull @Valid Project project) {
project.setLastModifier(currentInnerUser());
project.setArchived(false);
project.setBuiltin(false);
project.setUniqueIdentifier(generateProjectUniqueIdentifier());
ProjectEntity saved = repository.save(modelToEntity(project));
List<UserResourceRole> userResourceRoles = resourceRoleService.saveAll(
project.getMembers().stream()
Expand Down Expand Up @@ -518,4 +521,8 @@ private Long currentUserId() {
private InnerUser currentInnerUser() {
return new InnerUser(authenticationFacade.currentUser(), null);
}

private String generateProjectUniqueIdentifier() {
return "ODC_" + UUID.randomUUID().toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class Project implements SecurityResource, OrganizationIsolated, Serializ

@JsonProperty(access = Access.READ_ONLY)
private Date dbObjectLastSyncTime;
private String uniqueIdentifier;

@Override
public String resourceId() {
Expand Down

0 comments on commit b7605ac

Please sign in to comment.