-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
185 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
server/src/main/java/access/config/ApplicationConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package access.config; | ||
|
||
import access.manage.EntityType; | ||
import access.model.Application; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.persistence.AttributeConverter; | ||
import lombok.SneakyThrows; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class ApplicationConverter implements AttributeConverter<Set<Application>, String> { | ||
|
||
private final static ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@SneakyThrows | ||
@Override | ||
public String convertToDatabaseColumn(Set<Application> attribute) { | ||
return objectMapper.writeValueAsString(attribute); | ||
} | ||
|
||
@SneakyThrows | ||
@Override | ||
@SuppressWarnings("unchecked") | ||
public Set<Application> convertToEntityAttribute(String dbData) { | ||
Set<Map<String, String>> set = objectMapper.readValue(dbData, Set.class); | ||
return set.stream().map(m -> new Application(m.get("manageId"), EntityType.valueOf(m.get("manageType")))).collect(Collectors.toSet()); | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
server/src/main/java/access/db.migration/V11__migrate_applications.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
server/src/main/java/access/model/DistinctManagerIdentifiers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package access.model; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class DistinctManagerIdentifiers { | ||
|
||
private String identifiers; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
server/src/main/java/db/mysql/migration/V11_0__migrate_applications.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package db.mysql.migration; | ||
|
||
import access.manage.EntityType; | ||
import access.model.Application; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.SneakyThrows; | ||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.datasource.SingleConnectionDataSource; | ||
|
||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
|
||
public class V11_0__migrate_applications extends BaseJavaMigration { | ||
|
||
public void migrate(Context context) { | ||
JdbcTemplate jdbcTemplate = | ||
new JdbcTemplate(new SingleConnectionDataSource(context.getConnection(), true)); | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
jdbcTemplate.query("SELECT id, manage_id, manage_type FROM roles", rs -> { | ||
long roleId = rs.getLong("id"); | ||
jdbcTemplate.update("UPDATE roles SET identifier = ? WHERE id = ?", UUID.randomUUID().toString(), roleId); | ||
|
||
String manageId = rs.getString("manage_id"); | ||
String manageType = rs.getString("manage_type"); | ||
Set<Application> applications = Set.of(new Application(manageId, EntityType.valueOf(manageType))); | ||
String jsonNode; | ||
try { | ||
jsonNode = objectMapper.writeValueAsString(applications); | ||
} catch (JsonProcessingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
jdbcTemplate.update("UPDATE roles SET applications = ?", jsonNode); | ||
}); | ||
} | ||
} |
27 changes: 2 additions & 25 deletions
27
server/src/main/resources/db/mysql/migration/V10_0__multiple_applications.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,2 @@ | ||
CREATE TABLE `applications` | ||
( | ||
`id` bigint NOT NULL AUTO_INCREMENT, | ||
`manage_id` varchar(255) NOT NULL, | ||
`manage_type` varchar(255) NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE INDEX `applications_unique_manage` (`manage_id`,`manage_type`) | ||
) ENGINE = InnoDB | ||
AUTO_INCREMENT = 1 | ||
DEFAULT CHARSET = utf8mb4; | ||
|
||
CREATE TABLE `roles_applications` | ||
( | ||
`id` bigint NOT NULL AUTO_INCREMENT, | ||
`role_id` bigint NOT NULL, | ||
`application_id` bigint NOT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `user_roles_unique_user_role` (`user_id`, `role_id`), | ||
CONSTRAINT `fk_roles_applications_role` FOREIGN KEY (`role_id`) REFERENCES `roles` (`id`) ON DELETE CASCADE, | ||
CONSTRAINT `fk_roles_applications_application` FOREIGN KEY (`application_id`) REFERENCES `applications` (`id`) ON DELETE CASCADE | ||
) ENGINE = InnoDB | ||
AUTO_INCREMENT = 1 | ||
DEFAULT CHARSET = utf8mb4; | ||
|
||
ALTER TABLE `roles` add `identifier` varchar(255) DEFAULT NULL; | ||
ALTER TABLE `roles` add `identifier` varchar(255) DEFAULT NULL; | ||
ALTER TABLE `roles` add `applications` json DEFAULT NULL; |
3 changes: 3 additions & 0 deletions
3
server/src/main/resources/db/mysql/migration/V12_0__not_null_role_identifier.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
ALTER TABLE `roles` MODIFY `identifier` varchar(255) NOT NULL; | ||
ALTER TABLE `roles` MODIFY `applications` json NOT NULL; | ||
ALTER TABLE `roles` DROP COLUMN `manage_id`; | ||
ALTER TABLE `roles` DROP COLUMN `manage_type`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.