From 47b5af04163c80d07221b7c01be2fb1f6ad3f0e3 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Fri, 15 Nov 2024 17:54:16 +0100
Subject: [PATCH 01/20] bump dependency versions:
- spring boot 2.2.7 to 3.3.5
- maven.compiler 17 to 21
- lombok 1.18.34 to 1.18.36
- javadoc 3.10.1 to 3.11.1
- adapt readme and github workflows accordingly
---
.github/workflows/maven-publish.yml | 4 +---
README.md | 4 ++--
pom.xml | 13 ++++++-------
3 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml
index a8373f2..856cd8c 100644
--- a/.github/workflows/maven-publish.yml
+++ b/.github/workflows/maven-publish.yml
@@ -17,9 +17,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v4
with:
- # using java 17 for now, to match original
- # todo: migrate to java 21 (LTS)
- java-version: 17
+ java-version: 21
distribution: 'temurin'
cache: maven
# https://central.sonatype.org/publish/generate-portal-token/
diff --git a/README.md b/README.md
index f43f5c8..a312883 100644
--- a/README.md
+++ b/README.md
@@ -56,8 +56,8 @@ public class Rdf_Migration_0001_Init implements RdfProductionMigration {
**Stack:**
- - **Java** (recommended JDK 17)
- - **Maven** (recommended 3.2.5 or higher)
+ - **Java** (recommended JDK 21)
+ - **Maven** (recommended 3.9.9 or higher)
### Package the application
diff --git a/pom.xml b/pom.xml
index cad6eaf..f2ea7f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,9 +7,8 @@
org.springframework.boot
spring-boot-starter-parent
-
-
- 2.2.7.RELEASE
+
+ 3.3.5
@@ -56,15 +55,15 @@
UTF-8
- 17
- 17
+ 21
+ 21
- 1.18.34
+ 1.18.36
4.6
- 3.10.1
+ 3.11.1
3.3.1
0.6.0
3.2.7
From a63f4cbcabe653c10d43a4ab0db964b0222e3db5 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Tue, 19 Nov 2024 13:00:57 +0100
Subject: [PATCH 02/20] rely on spring-boot for java and lombok version
management
---
pom.xml | 23 +++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)
diff --git a/pom.xml b/pom.xml
index f2ea7f1..c7bd0c1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,17 +51,10 @@
-
UTF-8
-
-
- 21
- 21
-
-
- 1.18.36
-
-
+
+ 21
+
4.6
3.11.1
3.3.1
@@ -70,21 +63,15 @@
-
-
-
org.springframework.boot
spring-boot-starter-data-mongodb
-
-
-
-
org.projectlombok
lombok
- ${lombok.version}
+
+
From 1e7e766c6fca5c67c7222873712fc7f9db3e3ada Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Tue, 19 Nov 2024 13:11:38 +0100
Subject: [PATCH 03/20] remove redundant UTF-8 property from pom.xml
it is already covered by spring-boot-starter-parent:
https://docs.spring.io/spring-boot/maven-plugin/using.html
---
pom.xml | 2 --
1 file changed, 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index c7bd0c1..ec46894 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,8 +51,6 @@
- UTF-8
-
21
4.6
From cefd746423d0b0cc7f0bc281b34adaf60450e25e Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Tue, 19 Nov 2024 13:20:43 +0100
Subject: [PATCH 04/20] use full plugin names for version properties in pom
---
pom.xml | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/pom.xml b/pom.xml
index ec46894..8beb91a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,11 +53,11 @@
21
- 4.6
- 3.11.1
- 3.3.1
- 0.6.0
- 3.2.7
+ 4.6
+ 3.11.1
+ 3.3.1
+ 0.6.0
+ 3.2.7
@@ -77,7 +77,7 @@
com.mycila
license-maven-plugin
- ${plugin.mavenlic.version}
+ ${plugins.license-maven-plugin.version}
com/mycila/maven/plugin/license/templates/MIT.txt
@@ -102,7 +102,7 @@
org.sonatype.central
central-publishing-maven-plugin
- ${plugin.publishing.version}
+ ${plugins.central-publishing-maven-plugin.version}
true
central
@@ -116,7 +116,7 @@
org.apache.maven.plugins
maven-gpg-plugin
- ${plugin.gpg.version}
+ ${plugins.maven-gpg-plugin.version}
sign-artifacts
@@ -137,7 +137,7 @@
org.apache.maven.plugins
maven-source-plugin
- ${plugin.source.version}
+ ${plugins.maven-source-plugin.version}
attach-sources
@@ -150,7 +150,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- ${plugin.javadoc.version}
+ ${plugins.maven-javadoc-plugin.version}
attach-javadocs
From 318ac87320b178fb32f5d722dad0377a2a6ad101 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Tue, 19 Nov 2024 13:50:42 +0100
Subject: [PATCH 05/20] use java 17 for backward compatibility
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 8beb91a..fd5ed73 100644
--- a/pom.xml
+++ b/pom.xml
@@ -51,7 +51,7 @@
- 21
+ 17
4.6
3.11.1
From 81cf46923963ffc90640a6ca80b28897dace1e20 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Mon, 18 Nov 2024 23:23:45 +0100
Subject: [PATCH 06/20] add RdfMigrationCrudRepository and RdfMigrationJpa with
basic test
---
pom.xml | 36 ++++++++--
.../database/RdfMigrationCrudRepository.java | 31 +++++++++
.../rdf/migration/entity/RdfMigrationJpa.java | 52 +++++++++++++++
.../rdf/migration/RdfMigrationJpaTests.java | 66 +++++++++++++++++++
4 files changed, 179 insertions(+), 6 deletions(-)
create mode 100644 src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
create mode 100644 src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
create mode 100644 src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
diff --git a/pom.xml b/pom.xml
index fd5ed73..70a5d99 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,7 @@
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
@@ -9,7 +9,7 @@
spring-boot-starter-parent
3.3.5
-
+
org.fairdatateam.rdf
@@ -47,7 +47,7 @@
Vojtech Knaisl
https://github.com/vknaisl
-
+
@@ -61,10 +61,31 @@
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
org.springframework.boot
spring-boot-starter-data-mongodb
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+
+ org.postgresql
+ postgresql
+ runtime
+
+
+ com.h2database
+ h2
+ test
+
+
org.projectlombok
lombok
@@ -72,6 +93,7 @@
+
@@ -106,7 +128,8 @@
true
central
-
+
false
@@ -126,7 +149,8 @@
true
-
+
diff --git a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
new file mode 100644
index 0000000..5c410d6
--- /dev/null
+++ b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
@@ -0,0 +1,31 @@
+/*
+ * The MIT License
+ * Copyright © 2019 DTL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.fairdatateam.rdf.migration.database;
+
+import org.fairdatateam.rdf.migration.entity.RdfMigrationJpa;
+
+import org.springframework.data.repository.CrudRepository;
+
+public interface RdfMigrationCrudRepository extends CrudRepository {
+
+}
diff --git a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java b/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
new file mode 100644
index 0000000..1080e9a
--- /dev/null
+++ b/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
@@ -0,0 +1,52 @@
+/*
+ * The MIT License
+ * Copyright © 2019 DTL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.fairdatateam.rdf.migration.entity;
+
+import java.time.Instant;
+
+import org.springframework.data.annotation.CreatedDate;
+
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import lombok.Data;
+
+@Data
+@Entity
+public class RdfMigrationJpa {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private long id;
+
+ @CreatedDate
+ private Instant createdAt;
+
+ private Integer number;
+
+ private String name;
+
+ private String description;
+
+}
diff --git a/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java b/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
new file mode 100644
index 0000000..a26dc13
--- /dev/null
+++ b/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
@@ -0,0 +1,66 @@
+/*
+ * The MIT License
+ * Copyright © 2019 DTL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.fairdatateam.rdf.migration;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.fairdatateam.rdf.migration.database.RdfMigrationCrudRepository;
+import org.fairdatateam.rdf.migration.entity.RdfMigrationJpa;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+
+
+// https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.autoconfigured-spring-data-jpa
+// https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.detecting-configuration
+// https://spring.io/guides/gs/multi-module
+
+@DataJpaTest
+public class RdfMigrationJpaTests {
+
+ @Autowired
+ private TestEntityManager entityManager;
+
+ @Autowired
+ private RdfMigrationCrudRepository repository;
+
+ @Test
+ public void testGeneratedFields() {
+ this.entityManager.persist(new RdfMigrationJpa());
+ assertEquals(1, this.repository.count());
+ RdfMigrationJpa migration = this.repository.findAll().iterator().next();
+ assertNotNull(migration.getId());
+ assertNotNull(migration.getCreatedAt());
+ }
+
+ @SpringBootApplication
+ static class TestConfiguration {
+
+ }
+
+}
From d5e8f762f8804b065b601f8e8a64d18227fb49b9 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Tue, 19 Nov 2024 14:08:25 +0100
Subject: [PATCH 07/20] fix ID type for RdfMigrationRepository (mongo)
---
.../rdf/migration/database/RdfMigrationRepository.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationRepository.java b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationRepository.java
index d2a1ab8..ce3387d 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationRepository.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationRepository.java
@@ -23,6 +23,8 @@
package org.fairdatateam.rdf.migration.database;
import org.fairdatateam.rdf.migration.entity.RdfMigration;
+
+import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
@@ -31,6 +33,6 @@
* @author Vojtech Knaisl (vknaisl)
* @since 1.0.0
*/
-public interface RdfMigrationRepository extends MongoRepository {
+public interface RdfMigrationRepository extends MongoRepository {
}
From 3ab7825ae1be5f3db72eabba2eabed13bf0239aa Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Tue, 19 Nov 2024 16:16:10 +0100
Subject: [PATCH 08/20] use @RequiredArgsConstructor and add javadoc comments
---
.../database/RdfMigrationCrudRepository.java | 7 ++++
.../rdf/migration/entity/RdfMigrationJpa.java | 38 +++++++++++++++++++
.../rdf/migration/RdfMigrationJpaTests.java | 14 +++++--
3 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
index 5c410d6..180b704 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
@@ -26,6 +26,13 @@
import org.springframework.data.repository.CrudRepository;
+/**
+ * A repository for storing {@link RdfMigrationJpa}
+ * entities in a relational database such as PostgreSQL.
+ *
+ * @author dennisvang
+ * @since 2.1.0
+ */
public interface RdfMigrationCrudRepository extends CrudRepository {
}
diff --git a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java b/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
index 1080e9a..ff73a09 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
@@ -25,28 +25,66 @@
import java.time.Instant;
import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
+import jakarta.persistence.Column;
import jakarta.persistence.Entity;
+import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Data;
+import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+/**
+ * A record in the migration history of an RDF triple-store.
+ *
+ * The migration history itself is stored in a relational database, e.g. PostgreSQL,
+ * via the {@link org.fairdatateam.rdf.migration.database.RdfMigrationCrudRepository}
+ * repository interface.
+ *
+ * @author dennisvang
+ * @since 2.1.0
+ */
@Data
+@RequiredArgsConstructor
@Entity
+@EntityListeners(AuditingEntityListener.class)
public class RdfMigrationJpa {
+ /**
+ * An auto-generated internal database record id
+ */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
+ /**
+ * An auto-generated creation timestamp
+ */
+ // CreatedDate requires auditing config:
+ // https://docs.spring.io/spring-data/jpa/reference/auditing.html#jpa.auditing.configuration
@CreatedDate
+ @Column(updatable = false)
private Instant createdAt;
+ /**
+ * A migration number
+ */
+ @NonNull
private Integer number;
+ /**
+ * A migration name
+ */
+ @NonNull
private String name;
+ /**
+ * A migration description
+ */
+ @NonNull
private String description;
}
diff --git a/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java b/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
index a26dc13..6197a3d 100644
--- a/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
+++ b/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
@@ -34,12 +34,16 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+
+import lombok.extern.slf4j.Slf4j;
// https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.autoconfigured-spring-data-jpa
// https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.detecting-configuration
// https://spring.io/guides/gs/multi-module
+@Slf4j
@DataJpaTest
public class RdfMigrationJpaTests {
@@ -51,16 +55,20 @@ public class RdfMigrationJpaTests {
@Test
public void testGeneratedFields() {
- this.entityManager.persist(new RdfMigrationJpa());
+ // create new migration in database
+ this.entityManager.persist(new RdfMigrationJpa(1, "foo", "bar"));
+ // test
assertEquals(1, this.repository.count());
RdfMigrationJpa migration = this.repository.findAll().iterator().next();
assertNotNull(migration.getId());
- assertNotNull(migration.getCreatedAt());
+ assertNotNull(migration.getCreatedAt());
+ log.info("created at: " + migration.getCreatedAt());
}
@SpringBootApplication
+ @EnableJpaAuditing
static class TestConfiguration {
-
+ // for lack of an actual application
}
}
From 31b5ff63623403db3b53f3be5888e4f43b58b6e4 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Tue, 19 Nov 2024 16:34:52 +0100
Subject: [PATCH 09/20] test with repository instead of entity manager
---
.../fairdatateam/rdf/migration/entity/RdfMigrationJpa.java | 2 +-
.../fairdatateam/rdf/migration/RdfMigrationJpaTests.java | 6 +-----
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java b/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
index ff73a09..af7c18a 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
@@ -40,7 +40,7 @@
/**
* A record in the migration history of an RDF triple-store.
*
- * The migration history itself is stored in a relational database, e.g. PostgreSQL,
+ * The migration history itself is stored in a relational database, for example PostgreSQL,
* via the {@link org.fairdatateam.rdf.migration.database.RdfMigrationCrudRepository}
* repository interface.
*
diff --git a/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java b/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
index 6197a3d..8bf3732 100644
--- a/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
+++ b/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
@@ -33,7 +33,6 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
-import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import lombok.extern.slf4j.Slf4j;
@@ -47,16 +46,13 @@
@DataJpaTest
public class RdfMigrationJpaTests {
- @Autowired
- private TestEntityManager entityManager;
-
@Autowired
private RdfMigrationCrudRepository repository;
@Test
public void testGeneratedFields() {
// create new migration in database
- this.entityManager.persist(new RdfMigrationJpa(1, "foo", "bar"));
+ repository.save(new RdfMigrationJpa(1, "foo", "bar"));
// test
assertEquals(1, this.repository.count());
RdfMigrationJpa migration = this.repository.findAll().iterator().next();
From 6d5480e9729f8690ac0c6fa4445942af82a41378 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 21 Nov 2024 09:32:21 +0100
Subject: [PATCH 10/20] rename classes for consistency
---
.../database/RdfMigrationCrudRepository.java | 6 +++---
...itory.java => RdfMigrationMongoRepository.java} | 6 +++---
.../{RdfMigrationJpa.java => JpaRdfMigration.java} | 2 +-
.../{RdfMigration.java => MongoRdfMigration.java} | 6 +++---
.../migration/entity/RdfMigrationAnnotation.java | 6 +++---
.../runner/RdfProductionMigrationRunner.java | 14 +++++++-------
...tionJpaTests.java => JpaRdfMigrationTests.java} | 8 ++++----
7 files changed, 24 insertions(+), 24 deletions(-)
rename src/main/java/org/fairdatateam/rdf/migration/database/{RdfMigrationRepository.java => RdfMigrationMongoRepository.java} (85%)
rename src/main/java/org/fairdatateam/rdf/migration/entity/{RdfMigrationJpa.java => JpaRdfMigration.java} (98%)
rename src/main/java/org/fairdatateam/rdf/migration/entity/{RdfMigration.java => MongoRdfMigration.java} (94%)
rename src/test/java/org/fairdatateam/rdf/migration/{RdfMigrationJpaTests.java => JpaRdfMigrationTests.java} (92%)
diff --git a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
index 180b704..7f84a78 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationCrudRepository.java
@@ -22,17 +22,17 @@
*/
package org.fairdatateam.rdf.migration.database;
-import org.fairdatateam.rdf.migration.entity.RdfMigrationJpa;
+import org.fairdatateam.rdf.migration.entity.JpaRdfMigration;
import org.springframework.data.repository.CrudRepository;
/**
- * A repository for storing {@link RdfMigrationJpa}
+ * A repository for storing {@link JpaRdfMigration}
* entities in a relational database such as PostgreSQL.
*
* @author dennisvang
* @since 2.1.0
*/
-public interface RdfMigrationCrudRepository extends CrudRepository {
+public interface RdfMigrationCrudRepository extends CrudRepository {
}
diff --git a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationRepository.java b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationMongoRepository.java
similarity index 85%
rename from src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationRepository.java
rename to src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationMongoRepository.java
index ce3387d..470f966 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationRepository.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/database/RdfMigrationMongoRepository.java
@@ -22,17 +22,17 @@
*/
package org.fairdatateam.rdf.migration.database;
-import org.fairdatateam.rdf.migration.entity.RdfMigration;
+import org.fairdatateam.rdf.migration.entity.MongoRdfMigration;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
- * A Mongo repository for manipulating with {@link RdfMigration}
+ * A Mongo repository for manipulating with {@link MongoRdfMigration}
*
* @author Vojtech Knaisl (vknaisl)
* @since 1.0.0
*/
-public interface RdfMigrationRepository extends MongoRepository {
+public interface RdfMigrationMongoRepository extends MongoRepository {
}
diff --git a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java b/src/main/java/org/fairdatateam/rdf/migration/entity/JpaRdfMigration.java
similarity index 98%
rename from src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
rename to src/main/java/org/fairdatateam/rdf/migration/entity/JpaRdfMigration.java
index af7c18a..25c5a2f 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationJpa.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/entity/JpaRdfMigration.java
@@ -51,7 +51,7 @@
@RequiredArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
-public class RdfMigrationJpa {
+public class JpaRdfMigration {
/**
* An auto-generated internal database record id
diff --git a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigration.java b/src/main/java/org/fairdatateam/rdf/migration/entity/MongoRdfMigration.java
similarity index 94%
rename from src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigration.java
rename to src/main/java/org/fairdatateam/rdf/migration/entity/MongoRdfMigration.java
index d4ac3b8..55dfb20 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigration.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/entity/MongoRdfMigration.java
@@ -35,7 +35,7 @@
/**
* RdfMigration encapsulates information about concrete migration. The information is saved in the
- * database through {@link org.fairdatateam.rdf.migration.database.RdfMigrationRepository}
+ * database through {@link org.fairdatateam.rdf.migration.database.RdfMigrationMongoRepository}
*
* @author Vojtech Knaisl (vknaisl)
* @since 1.0.0
@@ -45,7 +45,7 @@
@AllArgsConstructor
@Getter
@Setter
-public class RdfMigration {
+public class MongoRdfMigration {
/**
* An internal Mongo DB Id
@@ -73,7 +73,7 @@ public class RdfMigration {
*/
protected LocalDateTime createdAt;
- public RdfMigration(Integer number, String name, String description) {
+ public MongoRdfMigration(Integer number, String name, String description) {
this.number = number;
this.name = name;
this.description = description;
diff --git a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationAnnotation.java b/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationAnnotation.java
index f834a3e..2365ef8 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationAnnotation.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/entity/RdfMigrationAnnotation.java
@@ -39,14 +39,14 @@
public @interface RdfMigrationAnnotation {
/**
- * A number of the migration in your application ({@link org.fairdatateam.rdf.migration.entity.RdfMigration#number})
+ * A number of the migration in your application ({@link org.fairdatateam.rdf.migration.entity.MongoRdfMigration#number})
*
* @return A getter for the value
*/
int number();
/**
- * A name of the migration ({@link org.fairdatateam.rdf.migration.entity.RdfMigration#name})
+ * A name of the migration ({@link org.fairdatateam.rdf.migration.entity.MongoRdfMigration#name})
*
* @return A getter for the value
*/
@@ -54,7 +54,7 @@
/**
* A quick description of the purpose of the migration
- * ({@link org.fairdatateam.rdf.migration.entity.RdfMigration#description})
+ * ({@link org.fairdatateam.rdf.migration.entity.MongoRdfMigration#description})
*
* @return A getter for the value
*/
diff --git a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java b/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java
index 5e91625..34128ee 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java
@@ -23,8 +23,8 @@
package org.fairdatateam.rdf.migration.runner;
import lombok.extern.slf4j.Slf4j;
-import org.fairdatateam.rdf.migration.database.RdfMigrationRepository;
-import org.fairdatateam.rdf.migration.entity.RdfMigration;
+import org.fairdatateam.rdf.migration.database.RdfMigrationMongoRepository;
+import org.fairdatateam.rdf.migration.entity.MongoRdfMigration;
import org.fairdatateam.rdf.migration.entity.RdfMigrationAnnotation;
import org.springframework.context.ApplicationContext;
@@ -44,14 +44,14 @@ public class RdfProductionMigrationRunner {
/**
* A repository for storing information about metadata into a database
*/
- private RdfMigrationRepository rdfMigrationRepository;
+ private RdfMigrationMongoRepository rdfMigrationRepository;
/**
* A Spring application context that is needed to retrieve a concrete annotated migration class defined by a user
*/
private ApplicationContext appContext;
- public RdfProductionMigrationRunner(RdfMigrationRepository rdfMigrationRepository,
+ public RdfProductionMigrationRunner(RdfMigrationMongoRepository rdfMigrationRepository,
ApplicationContext appContext) {
this.rdfMigrationRepository = rdfMigrationRepository;
this.appContext = appContext;
@@ -63,10 +63,10 @@ public RdfProductionMigrationRunner(RdfMigrationRepository rdfMigrationRepositor
*/
public void run() {
log.info("Production Migration of RDF Store started");
- List migrationsInDB = rdfMigrationRepository.findAll();
+ List migrationsInDB = rdfMigrationRepository.findAll();
int lastMigrationNumber = migrationsInDB
.stream()
- .map(RdfMigration::getNumber)
+ .map(MongoRdfMigration::getNumber)
.max(Integer::compareTo)
.orElse(0);
@@ -84,7 +84,7 @@ public void run() {
.filter(m -> getAnnotation(m).number() > lastMigrationNumber)
.sorted(Comparator.comparingInt(m -> getAnnotation(m).number()))
.forEach(m -> {
- RdfMigration mEntity = new RdfMigration(getAnnotation(m).number(),
+ MongoRdfMigration mEntity = new MongoRdfMigration(getAnnotation(m).number(),
getAnnotation(m).name(),
getAnnotation(m).description());
log.info("Production Migration (n. {}) started", mEntity.getNumber());
diff --git a/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java b/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationTests.java
similarity index 92%
rename from src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
rename to src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationTests.java
index 8bf3732..63a2eec 100644
--- a/src/test/java/org/fairdatateam/rdf/migration/RdfMigrationJpaTests.java
+++ b/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationTests.java
@@ -26,7 +26,7 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.fairdatateam.rdf.migration.database.RdfMigrationCrudRepository;
-import org.fairdatateam.rdf.migration.entity.RdfMigrationJpa;
+import org.fairdatateam.rdf.migration.entity.JpaRdfMigration;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,7 +44,7 @@
@Slf4j
@DataJpaTest
-public class RdfMigrationJpaTests {
+public class JpaRdfMigrationTests {
@Autowired
private RdfMigrationCrudRepository repository;
@@ -52,10 +52,10 @@ public class RdfMigrationJpaTests {
@Test
public void testGeneratedFields() {
// create new migration in database
- repository.save(new RdfMigrationJpa(1, "foo", "bar"));
+ repository.save(new JpaRdfMigration(1, "foo", "bar"));
// test
assertEquals(1, this.repository.count());
- RdfMigrationJpa migration = this.repository.findAll().iterator().next();
+ JpaRdfMigration migration = this.repository.findAll().iterator().next();
assertNotNull(migration.getId());
assertNotNull(migration.getCreatedAt());
log.info("created at: " + migration.getCreatedAt());
From 6c834b261b2292362debe4983f2abc2723e70403 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 21 Nov 2024 10:20:35 +0100
Subject: [PATCH 11/20] rename RdfProductionAnnotation to Migratable
---
README.md | 2 +-
.../{RdfProductionMigration.java => Migratable.java} | 4 ++--
.../migration/runner/RdfProductionMigrationRunner.java | 8 ++++----
3 files changed, 7 insertions(+), 7 deletions(-)
rename src/main/java/org/fairdatateam/rdf/migration/runner/{RdfProductionMigration.java => Migratable.java} (92%)
diff --git a/README.md b/README.md
index a312883..7cef91d 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@ That's all! You can start creating your migrations. See the example below.
name = "Init migration",
description = "Load initial data into Triple Store")
@Service
-public class Rdf_Migration_0001_Init implements RdfProductionMigration {
+public class Rdf_Migration_0001_Init implements Migratable {
@Autowired
protected Repository repository;
diff --git a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigration.java b/src/main/java/org/fairdatateam/rdf/migration/runner/Migratable.java
similarity index 92%
rename from src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigration.java
rename to src/main/java/org/fairdatateam/rdf/migration/runner/Migratable.java
index 632ca89..c571e5a 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigration.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/runner/Migratable.java
@@ -24,12 +24,12 @@
/**
* An interface that is required to be implemented by a target migration class. A logic of the migration should be
- * included in the method {@link RdfProductionMigration#runMigration()}
+ * included in the method {@link Migratable#runMigration()}
*
* @author Vojtech Knaisl (vknaisl)
* @since 1.0.0
*/
-public interface RdfProductionMigration {
+public interface Migratable {
/**
* A content of the migration
diff --git a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java b/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java
index 34128ee..12b9120 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java
@@ -74,11 +74,11 @@ public void run() {
.values()
.stream()
.map(o -> {
- if (!(o instanceof RdfProductionMigration)) {
- log.error("Defined Migration has to be type of RdfProductionMigration");
+ if (!(o instanceof Migratable)) {
+ log.error("Defined Migration has to implement Migratable");
return null;
}
- return (RdfProductionMigration) o;
+ return (Migratable) o;
})
.filter(Objects::nonNull)
.filter(m -> getAnnotation(m).number() > lastMigrationNumber)
@@ -101,7 +101,7 @@ public void run() {
* @param migration A migration from which we want to extract annotation
* @return The desired annotation
*/
- private RdfMigrationAnnotation getAnnotation(RdfProductionMigration migration) {
+ private RdfMigrationAnnotation getAnnotation(Migratable migration) {
return migration.getClass().getAnnotation(RdfMigrationAnnotation.class);
}
From 7b963fe8df867b1e55ac10fbdb39e24714e6d4a4 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 21 Nov 2024 10:29:32 +0100
Subject: [PATCH 12/20] rename RdfProductionMigrationRunner to
RdfMigrationRunner
and remove production qualifiers
---
README.md | 4 ++--
pom.xml | 2 +-
.../org/fairdatateam/rdf/migration/package-info.java | 2 +-
...nMigrationRunner.java => RdfMigrationRunner.java} | 12 ++++++------
4 files changed, 10 insertions(+), 10 deletions(-)
rename src/main/java/org/fairdatateam/rdf/migration/runner/{RdfProductionMigrationRunner.java => RdfMigrationRunner.java} (90%)
diff --git a/README.md b/README.md
index 7cef91d..fee75ba 100644
--- a/README.md
+++ b/README.md
@@ -10,9 +10,9 @@ Firstly, you need to define a migration runner bean in your configuration.
```java
@Bean
-public RdfProductionMigrationRunner rdfProductionMigrationRunner(RdfMigrationRepository rdfMigrationRepository,
+public RdfMigrationRunner rdfMigrationRunner(RdfMigrationRepository rdfMigrationRepository,
ApplicationContext appContext) {
- RdfProductionMigrationRunner mr = new RdfProductionMigrationRunner(rdfMigrationRepository, appContext);
+ RdfMigrationRunner mr = new RdfMigrationRunner(rdfMigrationRepository, appContext);
mr.run();
return mr;
}
diff --git a/pom.xml b/pom.xml
index 70a5d99..964cb3c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,7 +18,7 @@
jar
Spring RDF Migration
- Library for production migration of RDF Triple store
+ Library for migration of RDF Triple store
https://github.com/FAIRDataTeam/spring-rdf-migration
2019
diff --git a/src/main/java/org/fairdatateam/rdf/migration/package-info.java b/src/main/java/org/fairdatateam/rdf/migration/package-info.java
index 9c48a02..e3b7d65 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/package-info.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/package-info.java
@@ -21,7 +21,7 @@
* THE SOFTWARE.
*/
/**
- * A package related to production migrations of RDF Triple Stores. It fits into a Spring environment, and it uses
+ * A package related to migrations of RDF Triple Stores. It fits into a Spring environment, and it uses
* MongoDB as a database for storing metadata about already executed migrations
*/
package org.fairdatateam.rdf.migration;
\ No newline at end of file
diff --git a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java b/src/main/java/org/fairdatateam/rdf/migration/runner/RdfMigrationRunner.java
similarity index 90%
rename from src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java
rename to src/main/java/org/fairdatateam/rdf/migration/runner/RdfMigrationRunner.java
index 12b9120..dc1c92b 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfProductionMigrationRunner.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/runner/RdfMigrationRunner.java
@@ -39,7 +39,7 @@
* @since 1.0.0
*/
@Slf4j
-public class RdfProductionMigrationRunner {
+public class RdfMigrationRunner {
/**
* A repository for storing information about metadata into a database
@@ -51,7 +51,7 @@ public class RdfProductionMigrationRunner {
*/
private ApplicationContext appContext;
- public RdfProductionMigrationRunner(RdfMigrationMongoRepository rdfMigrationRepository,
+ public RdfMigrationRunner(RdfMigrationMongoRepository rdfMigrationRepository,
ApplicationContext appContext) {
this.rdfMigrationRepository = rdfMigrationRepository;
this.appContext = appContext;
@@ -62,7 +62,7 @@ public RdfProductionMigrationRunner(RdfMigrationMongoRepository rdfMigrationRepo
* them with already completed annotation, and runs the migrations that weren't run yet.
*/
public void run() {
- log.info("Production Migration of RDF Store started");
+ log.info("Migration of RDF Store started");
List migrationsInDB = rdfMigrationRepository.findAll();
int lastMigrationNumber = migrationsInDB
.stream()
@@ -87,12 +87,12 @@ public void run() {
MongoRdfMigration mEntity = new MongoRdfMigration(getAnnotation(m).number(),
getAnnotation(m).name(),
getAnnotation(m).description());
- log.info("Production Migration (n. {}) started", mEntity.getNumber());
+ log.info("Migration (n. {}) started", mEntity.getNumber());
m.runMigration();
rdfMigrationRepository.save(mEntity);
- log.info("Production Migration (n. {}) ended", mEntity.getNumber());
+ log.info("Migration (n. {}) ended", mEntity.getNumber());
});
- log.info("Production Migration of RDF Store ended");
+ log.info("Migration of RDF Store ended");
}
/**
From 50f651b511d026769970bb56f39db811b3aa4c14 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 21 Nov 2024 10:35:59 +0100
Subject: [PATCH 13/20] rename RdfMigrationRunner to MongoRdfMigrationRunner
for consistency with upcoming JpaRdfMigrationRunner
---
...{RdfMigrationRunner.java => MongoRdfMigrationRunner.java} | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
rename src/main/java/org/fairdatateam/rdf/migration/runner/{RdfMigrationRunner.java => MongoRdfMigrationRunner.java} (97%)
diff --git a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfMigrationRunner.java b/src/main/java/org/fairdatateam/rdf/migration/runner/MongoRdfMigrationRunner.java
similarity index 97%
rename from src/main/java/org/fairdatateam/rdf/migration/runner/RdfMigrationRunner.java
rename to src/main/java/org/fairdatateam/rdf/migration/runner/MongoRdfMigrationRunner.java
index dc1c92b..f0e7e4c 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/runner/RdfMigrationRunner.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/runner/MongoRdfMigrationRunner.java
@@ -39,7 +39,7 @@
* @since 1.0.0
*/
@Slf4j
-public class RdfMigrationRunner {
+public class MongoRdfMigrationRunner {
/**
* A repository for storing information about metadata into a database
@@ -51,7 +51,7 @@ public class RdfMigrationRunner {
*/
private ApplicationContext appContext;
- public RdfMigrationRunner(RdfMigrationMongoRepository rdfMigrationRepository,
+ public MongoRdfMigrationRunner(RdfMigrationMongoRepository rdfMigrationRepository,
ApplicationContext appContext) {
this.rdfMigrationRepository = rdfMigrationRepository;
this.appContext = appContext;
@@ -106,4 +106,3 @@ private RdfMigrationAnnotation getAnnotation(Migratable migration) {
}
}
-
From d4f99220052ce61653397ddd5c96b32b3c4900f3 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 21 Nov 2024 10:47:27 +0100
Subject: [PATCH 14/20] Q&D implementation of JpaRdfMIgrationRunner as copy of
MongoRdfMigrationRunner
lots of duplicated code, but this is easiest due to coupling with repository and entity
todo: DRY up
---
.../runner/JpaRdfMigrationRunner.java | 110 ++++++++++++++++++
1 file changed, 110 insertions(+)
create mode 100644 src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
diff --git a/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java b/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
new file mode 100644
index 0000000..61c89c2
--- /dev/null
+++ b/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
@@ -0,0 +1,110 @@
+/*
+ * The MIT License
+ * Copyright © 2019 DTL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.fairdatateam.rdf.migration.runner;
+
+import lombok.extern.slf4j.Slf4j;
+import org.fairdatateam.rdf.migration.database.RdfMigrationCrudRepository;
+import org.fairdatateam.rdf.migration.entity.JpaRdfMigration;
+import org.fairdatateam.rdf.migration.entity.RdfMigrationAnnotation;
+import org.springframework.context.ApplicationContext;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+/**
+ * The class contains a logic about executing the migration
+ *
+ * @author Vojtech Knaisl (vknaisl)
+ * @since 1.0.0
+ */
+@Slf4j
+public class JpaRdfMigrationRunner {
+
+ /**
+ * A repository for storing information about metadata into a database
+ */
+ private RdfMigrationCrudRepository rdfMigrationRepository;
+
+ /**
+ * A Spring application context that is needed to retrieve a concrete annotated migration class defined by a user
+ */
+ private ApplicationContext appContext;
+
+ public JpaRdfMigrationRunner(RdfMigrationCrudRepository rdfMigrationRepository,
+ ApplicationContext appContext) {
+ this.rdfMigrationRepository = rdfMigrationRepository;
+ this.appContext = appContext;
+ }
+
+ /**
+ * The method executes a migration process. It loads all migrations from the Spring Application context, filters
+ * them with already completed annotation, and runs the migrations that weren't run yet.
+ */
+ public void run() {
+ log.info("Migration of RDF Store started");
+ Iterable migrationsInDB = rdfMigrationRepository.findAll();
+ Stream migrations = StreamSupport.stream(migrationsInDB.spliterator(), false);
+ int lastMigrationNumber = migrations
+ .map(JpaRdfMigration::getNumber)
+ .max(Integer::compareTo)
+ .orElse(0);
+
+ appContext.getBeansWithAnnotation(RdfMigrationAnnotation.class)
+ .values()
+ .stream()
+ .map(o -> {
+ if (!(o instanceof Migratable)) {
+ log.error("Defined Migration has to implement Migratable");
+ return null;
+ }
+ return (Migratable) o;
+ })
+ .filter(Objects::nonNull)
+ .filter(m -> getAnnotation(m).number() > lastMigrationNumber)
+ .sorted(Comparator.comparingInt(m -> getAnnotation(m).number()))
+ .forEach(m -> {
+ JpaRdfMigration mEntity = new JpaRdfMigration(getAnnotation(m).number(),
+ getAnnotation(m).name(),
+ getAnnotation(m).description());
+ log.info("Migration (n. {}) started", mEntity.getNumber());
+ m.runMigration();
+ rdfMigrationRepository.save(mEntity);
+ log.info("Migration (n. {}) ended", mEntity.getNumber());
+ });
+ log.info("Migration of RDF Store ended");
+ }
+
+ /**
+ * A helper method for retrieving an annotation from the provided object
+ *
+ * @param migration A migration from which we want to extract annotation
+ * @return The desired annotation
+ */
+ private RdfMigrationAnnotation getAnnotation(Migratable migration) {
+ return migration.getClass().getAnnotation(RdfMigrationAnnotation.class);
+ }
+
+}
From 8f227ab989acfea1c998bab1d63bb00e26d84972 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Sun, 24 Nov 2024 23:11:42 +0100
Subject: [PATCH 15/20] annotate JpaRdfMigrationRunner as service
---
.../rdf/migration/runner/JpaRdfMigrationRunner.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java b/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
index 61c89c2..4b1dc3b 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
@@ -27,9 +27,9 @@
import org.fairdatateam.rdf.migration.entity.JpaRdfMigration;
import org.fairdatateam.rdf.migration.entity.RdfMigrationAnnotation;
import org.springframework.context.ApplicationContext;
+import org.springframework.stereotype.Service;
import java.util.Comparator;
-import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@@ -41,6 +41,7 @@
* @since 1.0.0
*/
@Slf4j
+@Service
public class JpaRdfMigrationRunner {
/**
From b54f43a290ca39ca911b09b6bfe8635de7bb5110 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Sun, 24 Nov 2024 23:13:06 +0100
Subject: [PATCH 16/20] add JpaRdfMigrationRunnerTests
work in progress (test fails)
---
.../migration/JpaRdfMigrationRunnerTests.java | 71 +++++++++++++++++++
1 file changed, 71 insertions(+)
create mode 100644 src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationRunnerTests.java
diff --git a/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationRunnerTests.java b/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationRunnerTests.java
new file mode 100644
index 0000000..23337b5
--- /dev/null
+++ b/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationRunnerTests.java
@@ -0,0 +1,71 @@
+/*
+ * The MIT License
+ * Copyright © 2019 DTL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package org.fairdatateam.rdf.migration;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.fairdatateam.rdf.migration.database.RdfMigrationCrudRepository;
+import org.fairdatateam.rdf.migration.entity.RdfMigrationAnnotation;
+import org.fairdatateam.rdf.migration.runner.JpaRdfMigrationRunner;
+import org.fairdatateam.rdf.migration.runner.Migratable;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+import org.springframework.stereotype.Service;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@SpringBootTest
+@AutoConfigureTestDatabase
+public class JpaRdfMigrationRunnerTests {
+
+ @Autowired
+ private RdfMigrationCrudRepository repository;
+
+ @Autowired
+ private JpaRdfMigrationRunner runner;
+
+ @Test
+ public void testRun() {
+ runner.run();
+ assertEquals(1, repository.count());
+ }
+
+ @SpringBootApplication
+ @EnableJpaAuditing
+ static class TestConfiguration {
+ // for lack of an actual application
+ }
+
+ @RdfMigrationAnnotation(number = 1, name = "test", description = "test")
+ @Service
+ private class TestMigration implements Migratable {
+ public void runMigration() {
+ log.info("running migration");
+ }
+ }
+}
From 52f97aeb9e0a2603a431cae79ec520433621e141 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 28 Nov 2024 17:31:14 +0100
Subject: [PATCH 17/20] fix test for JpaRdfMigrationRunner
---
.../rdf/migration/entity/JpaRdfMigration.java | 2 ++
.../migration/runner/JpaRdfMigrationRunner.java | 4 ++--
.../rdf/migration/JpaRdfMigrationRunnerTests.java | 15 +++++++++------
.../rdf/migration/JpaRdfMigrationTests.java | 3 +--
4 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/fairdatateam/rdf/migration/entity/JpaRdfMigration.java b/src/main/java/org/fairdatateam/rdf/migration/entity/JpaRdfMigration.java
index 25c5a2f..18265d4 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/entity/JpaRdfMigration.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/entity/JpaRdfMigration.java
@@ -24,6 +24,7 @@
import java.time.Instant;
+import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@@ -49,6 +50,7 @@
*/
@Data
@RequiredArgsConstructor
+@NoArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
public class JpaRdfMigration {
diff --git a/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java b/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
index 4b1dc3b..4e0c4b4 100644
--- a/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
+++ b/src/main/java/org/fairdatateam/rdf/migration/runner/JpaRdfMigrationRunner.java
@@ -47,12 +47,12 @@ public class JpaRdfMigrationRunner {
/**
* A repository for storing information about metadata into a database
*/
- private RdfMigrationCrudRepository rdfMigrationRepository;
+ private final RdfMigrationCrudRepository rdfMigrationRepository;
/**
* A Spring application context that is needed to retrieve a concrete annotated migration class defined by a user
*/
- private ApplicationContext appContext;
+ private final ApplicationContext appContext;
public JpaRdfMigrationRunner(RdfMigrationCrudRepository rdfMigrationRepository,
ApplicationContext appContext) {
diff --git a/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationRunnerTests.java b/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationRunnerTests.java
index 23337b5..d1df1e7 100644
--- a/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationRunnerTests.java
+++ b/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationRunnerTests.java
@@ -59,13 +59,16 @@ public void testRun() {
@EnableJpaAuditing
static class TestConfiguration {
// for lack of an actual application
- }
- @RdfMigrationAnnotation(number = 1, name = "test", description = "test")
- @Service
- private class TestMigration implements Migratable {
- public void runMigration() {
- log.info("running migration");
+ // dummy migration to test
+ @RdfMigrationAnnotation(number = 1, name = "test", description = "test")
+ @Service
+ private static class TestMigration implements Migratable {
+ public void runMigration() {
+ log.info("running test migration");
+ }
}
}
+
+
}
diff --git a/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationTests.java b/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationTests.java
index 63a2eec..05818f7 100644
--- a/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationTests.java
+++ b/src/test/java/org/fairdatateam/rdf/migration/JpaRdfMigrationTests.java
@@ -56,9 +56,8 @@ public void testGeneratedFields() {
// test
assertEquals(1, this.repository.count());
JpaRdfMigration migration = this.repository.findAll().iterator().next();
- assertNotNull(migration.getId());
assertNotNull(migration.getCreatedAt());
- log.info("created at: " + migration.getCreatedAt());
+ log.info("created at: {}", migration.getCreatedAt());
}
@SpringBootApplication
From 54a975124e8037771a0f5a4abdb43f5cef21e64b Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 28 Nov 2024 17:33:07 +0100
Subject: [PATCH 18/20] bump minor version to 2.1.0
added support for postgres in a backward compatible manner
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 964cb3c..7b1f409 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
org.fairdatateam.rdf
spring-rdf-migration
- 2.0.0
+ 2.1.0
jar
Spring RDF Migration
From afd6e6d849bd6ea5d52fec71dd1623f172a7cd63 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 28 Nov 2024 21:26:21 +0100
Subject: [PATCH 19/20] Revert "bump minor version to 2.1.0"
This reverts commit 54a975124e8037771a0f5a4abdb43f5cef21e64b.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 7b1f409..964cb3c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
org.fairdatateam.rdf
spring-rdf-migration
- 2.1.0
+ 2.0.0
jar
Spring RDF Migration
From c99fbe214262ce96ff05a8c160526e48a1f72bd5 Mon Sep 17 00:00:00 2001
From: dennisvang <29799340+dennisvang@users.noreply.github.com>
Date: Thu, 28 Nov 2024 21:26:50 +0100
Subject: [PATCH 20/20] bump major version to 3.0.0
actually we made some backward-incompatible changes:
- renamed interface from RdfProductionMigration to Migratable
- renamed RdfMigrationRepository to RdfMigrationMongoRepository (for consistency)
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 964cb3c..05be068 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
org.fairdatateam.rdf
spring-rdf-migration
- 2.0.0
+ 3.0.0
jar
Spring RDF Migration