-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for schema creation using Liquibase.
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
Showing
14 changed files
with
886 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ava/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...springframework/data/relational/core/mapping/schemasqlgeneration/DatabaseTypeMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
47 changes: 47 additions & 0 deletions
47
...ramework/data/relational/core/mapping/schemasqlgeneration/DefaultDatabaseTypeMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.