From aea09fe3997c540c0f66b21dcd1d9d40ceecad68 Mon Sep 17 00:00:00 2001 From: Michael Folz Date: Wed, 4 Sep 2024 11:45:23 +0200 Subject: [PATCH] #359 - Remove unused tables - add db migration script to remove unused tables - remove correlating entity classes and repositories --- .../terminology/MappingNotFoundException.java | 12 ---------- .../persistence/ContextualizedTermCode.java | 3 --- .../ContextualizedTermCodeRepository.java | 8 ------- .../ContextualizedTermCodeToCriteriaSet.java | 20 ---------------- .../terminology/persistence/CriteriaSet.java | 19 --------------- .../terminology/persistence/Mapping.java | 24 ------------------- .../persistence/MappingRepository.java | 13 ---------- .../db/migration/V10__drop_unused_tables.sql | 7 ++++++ 8 files changed, 7 insertions(+), 99 deletions(-) delete mode 100644 src/main/java/de/numcodex/feasibility_gui_backend/terminology/MappingNotFoundException.java delete mode 100644 src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCodeToCriteriaSet.java delete mode 100644 src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/CriteriaSet.java delete mode 100644 src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/Mapping.java delete mode 100644 src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/MappingRepository.java create mode 100644 src/main/resources/db/migration/V10__drop_unused_tables.sql diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/MappingNotFoundException.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/MappingNotFoundException.java deleted file mode 100644 index e73a89f5..00000000 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/MappingNotFoundException.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.numcodex.feasibility_gui_backend.terminology; - - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(value = HttpStatus.NOT_FOUND) -public class MappingNotFoundException extends RuntimeException { - - public MappingNotFoundException() { - } -} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCode.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCode.java index 66b2a1a1..c5b9a420 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCode.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCode.java @@ -20,9 +20,6 @@ public class ContextualizedTermCode { @Column(name = "termcode_id", nullable = false) private int termCodeId; @Basic - @Column(name = "mapping_id", nullable = true) - private Integer mappingId; - @Basic @Column(name = "ui_profile_id", nullable = true) private Integer uiProfileId; } diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCodeRepository.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCodeRepository.java index 54331f33..df7a92b7 100644 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCodeRepository.java +++ b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCodeRepository.java @@ -1,14 +1,6 @@ package de.numcodex.feasibility_gui_backend.terminology.persistence; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; public interface ContextualizedTermCodeRepository extends JpaRepository { - - @Query("select ct.contextTermcodeHash from CriteriaSet cs inner join ContextualizedTermCodeToCriteriaSet ctctcs on ctctcs.criteriaSetId = cs.id inner join ContextualizedTermCode ct on ctctcs.contextTermcodeHash = ct.contextTermcodeHash where ct.contextTermcodeHash in :contextTermCodeHashList and cs.url = :criteriaSetUrl") - List filterByCriteriaSetUrl(@Param("criteriaSetUrl") String criteriaSetUrl, - @Param("contextTermCodeHashList") List contextTermCodeHashList); } diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCodeToCriteriaSet.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCodeToCriteriaSet.java deleted file mode 100644 index ce2edc81..00000000 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/ContextualizedTermCodeToCriteriaSet.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.numcodex.feasibility_gui_backend.terminology.persistence; - -import jakarta.persistence.*; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Entity -@Table(name = "contextualized_termcode_to_criteria_set", schema = "public") -@Data -@EqualsAndHashCode -public class ContextualizedTermCodeToCriteriaSet { - @Id - @Basic - @Column(name = "context_termcode_hash", nullable = false, length = -1) - private String contextTermcodeHash; - @Id - @Basic - @Column(name = "criteria_set_id", nullable = false) - private int criteriaSetId; -} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/CriteriaSet.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/CriteriaSet.java deleted file mode 100644 index eb9beeb6..00000000 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/CriteriaSet.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.numcodex.feasibility_gui_backend.terminology.persistence; - -import jakarta.persistence.*; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Entity -@Table(name = "criteria_set", schema = "public") -@Data -@EqualsAndHashCode -public class CriteriaSet { - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Id - @Column(name = "id", nullable = false) - private int id; - @Basic - @Column(name = "url", nullable = false, length = -1) - private String url; -} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/Mapping.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/Mapping.java deleted file mode 100644 index ca9c6b12..00000000 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/Mapping.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.numcodex.feasibility_gui_backend.terminology.persistence; - -import jakarta.persistence.*; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Entity -@Data -@EqualsAndHashCode -public class Mapping { - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Id - @Column(name = "id", nullable = false) - private int id; - @Basic - @Column(name = "name", nullable = false, length = -1) - private String name; - @Basic - @Column(name = "type", nullable = false, length = -1) - private String type; - @Basic - @Column(name = "content", columnDefinition = "json", nullable = false) - private String content; -} diff --git a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/MappingRepository.java b/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/MappingRepository.java deleted file mode 100644 index f73df9ee..00000000 --- a/src/main/java/de/numcodex/feasibility_gui_backend/terminology/persistence/MappingRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.numcodex.feasibility_gui_backend.terminology.persistence; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.Optional; - -public interface MappingRepository extends JpaRepository { - - @Query("select m from ContextualizedTermCode ct left join Mapping m on ct.uiProfileId = m.id where ct.contextTermcodeHash = :contextualizedTermcodeHash") - Optional findByContextualizedTermcodeHash(@Param("contextualizedTermcodeHash") String contextualizedTermcodeHash); -} diff --git a/src/main/resources/db/migration/V10__drop_unused_tables.sql b/src/main/resources/db/migration/V10__drop_unused_tables.sql new file mode 100644 index 00000000..d44f921e --- /dev/null +++ b/src/main/resources/db/migration/V10__drop_unused_tables.sql @@ -0,0 +1,7 @@ +DROP INDEX idx_mapping_name_mapping; +ALTER TABLE contextualized_termcode DROP CONSTRAINT mapping_id_fk; +ALTER TABLE contextualized_termcode DROP COLUMN mapping_id; + +DROP TABLE mapping; +DROP TABLE contextualized_termcode_to_criteria_set; +DROP TABLE criteria_set; \ No newline at end of file