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

Add migration support for jpa repositories (e.g.postgres) #7

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
47b5af0
bump dependency versions:
dennisvang Nov 15, 2024
a63f4cb
rely on spring-boot for java and lombok version management
dennisvang Nov 19, 2024
1e7e766
remove redundant UTF-8 property from pom.xml
dennisvang Nov 19, 2024
cefd746
use full plugin names for version properties in pom
dennisvang Nov 19, 2024
318ac87
use java 17 for backward compatibility
dennisvang Nov 19, 2024
81cf469
add RdfMigrationCrudRepository and RdfMigrationJpa with basic test
dennisvang Nov 18, 2024
d5e8f76
fix ID type for RdfMigrationRepository (mongo)
dennisvang Nov 19, 2024
3ab7825
use @RequiredArgsConstructor and add javadoc comments
dennisvang Nov 19, 2024
31b5ff6
test with repository instead of entity manager
dennisvang Nov 19, 2024
6d5480e
rename classes for consistency
dennisvang Nov 21, 2024
6c834b2
rename RdfProductionAnnotation to Migratable
dennisvang Nov 21, 2024
7b963fe
rename RdfProductionMigrationRunner to RdfMigrationRunner
dennisvang Nov 21, 2024
50f651b
rename RdfMigrationRunner to MongoRdfMigrationRunner
dennisvang Nov 21, 2024
d4f9922
Q&D implementation of JpaRdfMIgrationRunner as copy of MongoRdfMigrat…
dennisvang Nov 21, 2024
8f227ab
annotate JpaRdfMigrationRunner as service
dennisvang Nov 24, 2024
b54f43a
add JpaRdfMigrationRunnerTests
dennisvang Nov 24, 2024
52f97ae
fix test for JpaRdfMigrationRunner
dennisvang Nov 28, 2024
54a9751
bump minor version to 2.1.0
dennisvang Nov 28, 2024
afd6e6d
Revert "bump minor version to 2.1.0"
dennisvang Nov 28, 2024
c99fbe2
bump major version to 3.0.0
dennisvang Nov 28, 2024
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
4 changes: 1 addition & 3 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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

Expand Down
86 changes: 47 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- https://docs.spring.io/spring-boot/maven-plugin/using.html -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- TODO: upgrade spring boot (support for 2.2.x ended in 2020) -->
<!-- https://spring.io/projects/spring-boot#support -->
<version>2.2.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
<!-- https://spring.io/projects/spring-boot#support -->
<version>3.3.5</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<groupId>org.fairdatateam.rdf</groupId>
<artifactId>spring-rdf-migration</artifactId>
<version>2.0.0</version>
<version>3.0.0</version>
<packaging>jar</packaging>

<name>Spring RDF Migration</name>
<description>Library for production migration of RDF Triple store</description>
<description>Library for migration of RDF Triple store</description>
<url>https://github.com/FAIRDataTeam/spring-rdf-migration</url>
<inceptionYear>2019</inceptionYear>

Expand Down Expand Up @@ -48,52 +47,59 @@
<developer>
<name>Vojtech Knaisl</name>
<url>https://github.com/vknaisl</url>
</developer>
</developer>
</developers>

<properties>
<!-- Project -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Maven -->
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>

<!-- Core -->
<lombok.version>1.18.34</lombok.version>

<!-- Plugins -->
<plugin.mavenlic.version>4.6</plugin.mavenlic.version>
<plugin.javadoc.version>3.10.1</plugin.javadoc.version>
<plugin.source.version>3.3.1</plugin.source.version>
<plugin.publishing.version>0.6.0</plugin.publishing.version>
<plugin.gpg.version>3.2.7</plugin.gpg.version>
<java.version>17</java.version>

<plugins.license-maven-plugin.version>4.6</plugins.license-maven-plugin.version>
<plugins.maven-javadoc-plugin.version>3.11.1</plugins.maven-javadoc-plugin.version>
<plugins.maven-source-plugin.version>3.3.1</plugins.maven-source-plugin.version>
<plugins.central-publishing-maven-plugin.version>0.6.0</plugins.central-publishing-maven-plugin.version>
<plugins.maven-gpg-plugin.version>3.2.7</plugins.maven-gpg-plugin.version>
</properties>

<dependencies>
<!-- ////////////////// -->
<!-- Spring -->
<!-- ////////////////// -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<!-- ////////////////// -->
<!-- Core -->
<!-- ////////////////// -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<!-- version managed by spring-boot: -->
<!-- https://docs.spring.io/spring-boot/appendix/dependency-versions/coordinates.html -->
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>${plugin.mavenlic.version}</version>
<version>${plugins.license-maven-plugin.version}</version>
<configuration>
<header>com/mycila/maven/plugin/license/templates/MIT.txt</header>
<properties>
Expand All @@ -118,11 +124,12 @@
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>${plugin.publishing.version}</version>
<version>${plugins.central-publishing-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>central</publishingServerId>
<!-- visit https://central.sonatype.com/publishing/deployments to publish manually -->
<!-- visit https://central.sonatype.com/publishing/deployments to publish
manually -->
<!-- also visit that site to debug validation issues -->
<autoPublish>false</autoPublish>
</configuration>
Expand All @@ -132,7 +139,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${plugin.gpg.version}</version>
<version>${plugins.maven-gpg-plugin.version}</version>
<executions>
<execution>
<id>sign-artifacts</id>
Expand All @@ -142,7 +149,8 @@
</goals>
<configuration>
<bestPractices>true</bestPractices>
<!-- set gpg.keyname via command line if necessary (default: first found) -->
<!-- set gpg.keyname via command line if necessary (default: first
found) -->
</configuration>
</execution>
</executions>
Expand All @@ -153,7 +161,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${plugin.source.version}</version>
<version>${plugins.maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -166,7 +174,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${plugin.javadoc.version}</version>
<version>${plugins.maven-javadoc-plugin.version}</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.JpaRdfMigration;

import org.springframework.data.repository.CrudRepository;

/**
* 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<JpaRdfMigration, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +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<RdfMigration, String> {
public interface RdfMigrationMongoRepository extends MongoRepository<MongoRdfMigration, ObjectId> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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 lombok.NoArgsConstructor;
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, for example PostgreSQL,
* via the {@link org.fairdatateam.rdf.migration.database.RdfMigrationCrudRepository}
* repository interface.
*
* @author dennisvang
* @since 2.1.0
*/
@Data
@RequiredArgsConstructor
@NoArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
public class JpaRdfMigration {

/**
* 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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,7 +45,7 @@
@AllArgsConstructor
@Getter
@Setter
public class RdfMigration {
public class MongoRdfMigration {

/**
* An internal Mongo DB Id
Expand Down Expand Up @@ -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;
Expand Down
Loading