Skip to content

Commit

Permalink
Add support for schema creation using Liquibase.
Browse files Browse the repository at this point in the history
We now support schema creation and schema migration by generating Liquibase changesets from mapped entities. We also support evolution of schema by comparing existing tables with mapped entities to compute differential changesets.

Closes #756
Original pull request: #1520
  • Loading branch information
kurtn718 authored and mp911de committed Jun 6, 2023
1 parent b92586f commit 5f4ef2f
Show file tree
Hide file tree
Showing 14 changed files with 886 additions and 74 deletions.
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<properties>
<dist.id>spring-data-jdbc</dist.id>
<springdata.commons>3.2.0-SNAPSHOT</springdata.commons>
<liquibase.version>4.21.1</liquibase.version>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>

<!-- dependency versions -->
Expand Down Expand Up @@ -91,6 +92,29 @@
</roles>
<timezone>-6</timezone>
</developer>
<developer>
<id>ogierke</id>
<name>Oliver Gierke</name>
<email>ogierke(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Contributor</role>
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<id>kurtn718</id>
<name>Kurt Niemi</name>
<email>kniemi(at)vmware.com</email>
<organization>VMware.</organization>
<organizationUrl>https://vmware.com</organizationUrl>
<roles>
<role>Project Contributor</role>
</roles>
<timezone>-5</timezone>
</developer>

</developers>

<profiles>
Expand Down
55 changes: 8 additions & 47 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,6 @@

<inceptionYear>2017</inceptionYear>

<developers>
<developer>
<id>schauder</id>
<name>Jens Schauder</name>
<email>jschauder(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Lead</role>
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<id>gregturn</id>
<name>Greg L. Turnquist</name>
<email>gturnquist(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Contributor</role>
</roles>
<timezone>-6</timezone>
</developer>
<developer>
<id>ogierke</id>
<name>Oliver Gierke</name>
<email>ogierke(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Contributor</role>
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<id>mpaluch</id>
<name>Mark Paluch</name>
<email>mpaluch(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Contributor</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -269,6 +222,14 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

</dependencies>


Expand Down
25 changes: 0 additions & 25 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,6 @@

<inceptionYear>2018</inceptionYear>

<developers>
<developer>
<id>mpaluch</id>
<name>Mark Paluch</name>
<email>mpaluch(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Lead</role>
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<id>ogierke</id>
<name>Oliver Gierke</name>
<email>ogierke(at)pivotal.io</email>
<organization>Pivotal Software, Inc.</organization>
<organizationUrl>https://pivotal.io</organizationUrl>
<roles>
<role>Project Lead</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down
10 changes: 9 additions & 1 deletion spring-data-relational/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
<artifactId>spring-core</artifactId>
</dependency>

<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down Expand Up @@ -97,6 +105,6 @@
<scope>test</scope>
</dependency>

</dependencies>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ protected void applyDefaults(BasicRelationalPersistentProperty persistentPropert
persistentProperty.setForceQuote(isForceQuote());
persistentProperty.setExpressionEvaluator(this.expressionEvaluator);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.relational.core.mapping.schemasqlgeneration;

import org.springframework.data.relational.core.sql.SqlIdentifier;

import java.util.Objects;


/**
* Models a Column for generating SQL for Schema generation.
*
* @author Kurt Niemi
* @since 3.2
*/
public record ColumnModel(String name, String type, boolean nullable, boolean identityColumn) {

public ColumnModel(String name, String type) {
this(name, type, false, false);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ColumnModel that = (ColumnModel) o;
return Objects.equals(name, that.name);
}

@Override
public int hashCode() {
return Objects.hash(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.relational.core.mapping.schemasqlgeneration;

/**
* Interface for mapping a Java type to a Database type.
*
* To customize the mapping an instance of a class implementing {@link DatabaseTypeMapping} interface
* can be set on the {@link SchemaModel} class.
*
* @author Kurt Niemi
* @since 3.2
*/
public interface DatabaseTypeMapping {
public String databaseTypeFromClass(Class<?> type);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.relational.core.mapping.schemasqlgeneration;

import java.util.HashMap;


/**
* Class that provides a default implementation of mapping Java type to a Database type.
*
* To customize the mapping an instance of a class implementing {@link DatabaseTypeMapping} interface
* can be set on the {@link SchemaModel} class
*
* @author Kurt Niemi
* @since 3.2
*/
public class DefaultDatabaseTypeMapping implements DatabaseTypeMapping {

final HashMap<Class<?>,String> mapClassToDatabaseType = new HashMap<Class<?>,String>();

public DefaultDatabaseTypeMapping() {

mapClassToDatabaseType.put(String.class, "VARCHAR(255 BYTE)");
mapClassToDatabaseType.put(Boolean.class, "TINYINT");
mapClassToDatabaseType.put(Double.class, "DOUBLE");
mapClassToDatabaseType.put(Float.class, "FLOAT");
mapClassToDatabaseType.put(Integer.class, "INT");
mapClassToDatabaseType.put(Long.class, "BIGINT");
}
public String databaseTypeFromClass(Class<?> type) {

return mapClassToDatabaseType.get(type);
}
}
Loading

0 comments on commit 5f4ef2f

Please sign in to comment.