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

Changes to support generating Liquibase change-sets #1520

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f5fa502
Initial Data Model for Schema SQL Generation (#1481)
kurtn718 Apr 13, 2023
201ba55
Initial changes for SQLGenerationDataModel to perform differences bet…
kurtn718 Apr 25, 2023
e5e993f
Remove Serializable
kurtn718 Apr 30, 2023
ebde99f
Add liquibase as an optional dependency
kurtn718 May 11, 2023
4d08588
Initial changes for Generating Liquibase changeset
kurtn718 May 11, 2023
f7a5ead
Remove classes not used for generating Liquibase change set
kurtn718 May 19, 2023
989d4b2
Make DerivedSqlIdentifier public - as we need to create one
kurtn718 May 19, 2023
7e21cfc
Fix Unit Test
kurtn718 May 19, 2023
046d916
Generate Liquibase changesets for table additions, modifications, and…
kurtn718 May 19, 2023
33e3308
Re-run new-issue-branch script after rebase
kurtn718 May 20, 2023
2335a4b
Re-add things lost in rebase
kurtn718 May 20, 2023
a22eccc
cleanup - remove unnecessary changes
kurtn718 May 20, 2023
d2d7845
Refactoring - move logic for generating Liquibase Change Sets into it…
kurtn718 May 21, 2023
023b34f
Additional refactoring on LiquibaseChangeSetGenerator
kurtn718 May 21, 2023
03597b9
Refactor rename SchemaSQLGenerationDataModel to SchemaModel
kurtn718 May 22, 2023
86c52f1
Refactor Database type mapping and provide Default implementation to …
kurtn718 May 24, 2023
c68584b
Add additional Javadocs
kurtn718 May 24, 2023
c9efa82
Additional Javadoc's
kurtn718 May 24, 2023
9757b71
Refactoring - make SchemaModel class purely a model class (and not pe…
kurtn718 May 24, 2023
0c01a9c
Change to use Records for pure data types
kurtn718 May 25, 2023
e3e123d
Use predicate to define all Liquibase specific tables
kurtn718 May 25, 2023
cf21d29
Add predicate with default implementation to not drop any external ta…
kurtn718 May 25, 2023
c9841c5
Remove usage of DerivedSqlIdentifier as what we get from Liquibase wh…
kurtn718 May 26, 2023
1693d24
Fix unit tests
kurtn718 May 26, 2023
212d07a
Changes for not requiring @Table annotation
kurtn718 May 26, 2023
9749dcf
For Liquibase changeset generation - Use Spring Resource instead of a…
kurtn718 May 26, 2023
0ea5833
Ensure all author(s) are listed in parent pom - and remove from other…
kurtn718 May 26, 2023
187e55d
Cleanup - remove un-needed imports (fix build errors)
kurtn718 May 31, 2023
d8b105d
Polishing.
mp911de Jun 1, 2023
e4f1a0a
Polishing.
mp911de Jun 2, 2023
e85ab13
Polishing.
mp911de Jun 5, 2023
cd8d041
Add documentation.
mp911de Jun 5, 2023
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
26 changes: 25 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1480-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand All @@ -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
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1480-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
58 changes: 9 additions & 49 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1480-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-1480-SNAPSHOT</version>
</parent>

<properties>
Expand All @@ -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,13 @@
<scope>test</scope>
</dependency>

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

</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.jdbc.core.mapping.schema;

import java.util.Objects;

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

public Column(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;
Column that = (Column) 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,66 @@
/*
* 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.jdbc.core.mapping.schema;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.UUID;

import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.util.ClassUtils;

/**
* 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 SqlTypeMapping} interface can be set on the {@link Tables} class
*
* @author Kurt Niemi
* @since 3.2
*/
public class DefaultSqlTypeMapping implements SqlTypeMapping {

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

public DefaultSqlTypeMapping() {

typeMap.put(String.class, "VARCHAR(255 BYTE)");
typeMap.put(Boolean.class, "TINYINT");
typeMap.put(Double.class, "DOUBLE");
typeMap.put(Float.class, "FLOAT");
typeMap.put(Integer.class, "INT");
typeMap.put(Long.class, "BIGINT");

typeMap.put(BigInteger.class, "BIGINT");
typeMap.put(BigDecimal.class, "NUMERIC");

typeMap.put(UUID.class, "UUID");

typeMap.put(LocalDate.class, "DATE");
typeMap.put(LocalTime.class, "TIME");
typeMap.put(LocalDateTime.class, "TIMESTAMP");

typeMap.put(ZonedDateTime.class, "TIMESTAMPTZ");
}

@Override
public String getColumnType(RelationalPersistentProperty property) {
return typeMap.get(ClassUtils.resolvePrimitiveIfNecessary(property.getActualType()));
}
}
Loading