Class LiquibaseChangeSetWriter
java.lang.Object
org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter
Use this class to write Liquibase ChangeSets.
This writer uses MappingContext
as input to determine mapped entities. Entities can be filtered through a
schema filter
to include/exclude entities. By default, all entities within the
mapping context are considered for computing the expected schema.
This writer operates in two modes:
- Initial Schema Creation
- Differential Schema Change Creation
initial mode
allows creating the full schema without considering any existing
tables. The differential schema mode
uses a Database
object to
determine existing tables and columns. It creates in addition to table creations also changes to drop tables, drop
columns and add columns. By default, the DROP TABLE
and the
DROP COLUMN
filters exclude all tables respective columns from being
dropped.
In differential schema mode, table and column names are compared using a case-insensitive comparator, see
Collator.PRIMARY
.
The writer can be configured to use specific ChangeLogSerializers and ChangeLogParsers defaulting to YAML.
- Since:
- 3.2
- Author:
- Kurt Niemi, Mark Paluch
-
Field Summary
-
Constructor Summary
ConstructorDescriptionLiquibaseChangeSetWriter
(MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> mappingContext) Use this to generate a ChangeSet that can be used on an empty database. -
Method Summary
Modifier and TypeMethodDescriptionprotected liquibase.changelog.ChangeSet
createChangeSet
(org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter.ChangeSetMetadata metadata, liquibase.changelog.DatabaseChangeLog databaseChangeLog) Creates an initial ChangeSet.protected liquibase.changelog.ChangeSet
createChangeSet
(org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter.ChangeSetMetadata metadata, liquibase.database.Database database, liquibase.changelog.DatabaseChangeLog databaseChangeLog) Creates a diff ChangeSet by comparingDatabase
withmapped entities
.void
setChangeLogParser
(liquibase.parser.ChangeLogParser changeLogParser) Set theChangeLogParser
.void
setChangeLogSerializer
(liquibase.serializer.ChangeLogSerializer changeLogSerializer) Set theChangeLogSerializer
.void
setDropColumnFilter
(BiPredicate<String, String> dropColumnFilter) Set the filter predicate to identify columns within a table to drop.void
setDropTableFilter
(Predicate<String> dropTableFilter) Set the filter predicate to identify tables to drop.void
setSchemaFilter
(Predicate<RelationalPersistentEntity<?>> schemaFilter) Set the filter predicate to identify for which entities to create schema definitions.void
setSqlTypeMapping
(SqlTypeMapping sqlTypeMapping) Configure SQL type mapping.void
writeChangeSet
(Resource changeLogResource) Write a Liquibase ChangeSet containing all tables as initial ChangeSet.void
writeChangeSet
(Resource changeLogResource, liquibase.database.Database database) Write a Liquibase ChangeSet using aDatabase
to identify the differences between mapped entities and the existing database.void
writeChangeSet
(Resource changeLogResource, org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter.ChangeSetMetadata metadata) Write a Liquibase ChangeSet containing all tables as initial ChangeSet.void
writeChangeSet
(Resource changeLogResource, org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter.ChangeSetMetadata metadata, liquibase.database.Database database) Write a Liquibase ChangeSet using aDatabase
to identify the differences between mapped entities and the existing database.
-
Field Details
-
DEFAULT_AUTHOR
- See Also:
-
-
Constructor Details
-
LiquibaseChangeSetWriter
public LiquibaseChangeSetWriter(MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> mappingContext) Use this to generate a ChangeSet that can be used on an empty database.- Parameters:
mappingContext
- source to determine persistent entities, must not be null.
-
-
Method Details
-
setSqlTypeMapping
Configure SQL type mapping. Defaults toDefaultSqlTypeMapping
.- Parameters:
sqlTypeMapping
- must not be null.
-
setChangeLogSerializer
public void setChangeLogSerializer(liquibase.serializer.ChangeLogSerializer changeLogSerializer) Set theChangeLogSerializer
.- Parameters:
changeLogSerializer
- must not be null.
-
setChangeLogParser
public void setChangeLogParser(liquibase.parser.ChangeLogParser changeLogParser) Set theChangeLogParser
.- Parameters:
changeLogParser
- must not be null.
-
setSchemaFilter
Set the filter predicate to identify for which entities to create schema definitions. Existing tables for excluded entities will show up insetDropTableFilter(Predicate)
. Returningtrue
includes the entity;false
excludes the entity from schema creation.- Parameters:
schemaFilter
- must not be null.
-
setDropTableFilter
Set the filter predicate to identify tables to drop. The predicate accepts the table name. Returningtrue
will delete the table;false
retains the table.- Parameters:
dropTableFilter
- must not be null.
-
setDropColumnFilter
Set the filter predicate to identify columns within a table to drop. The predicate accepts the table- and column name. Returningtrue
will delete the column;false
retains the column.- Parameters:
dropColumnFilter
- must not be null.
-
writeChangeSet
Write a Liquibase ChangeSet containing all tables as initial ChangeSet.- Parameters:
changeLogResource
- resource that ChangeSet will be written to (or append to an existing ChangeSet file). The resource must resolve to a validResource.getFile()
.- Throws:
IOException
- in case of I/O errors.
-
writeChangeSet
public void writeChangeSet(Resource changeLogResource, liquibase.database.Database database) throws IOException, liquibase.exception.LiquibaseException Write a Liquibase ChangeSet using aDatabase
to identify the differences between mapped entities and the existing database.- Parameters:
changeLogResource
- resource that ChangeSet will be written to (or append to an existing ChangeSet file). The resource must resolve to a validResource.getFile()
.database
- database to identify the differences.- Throws:
liquibase.exception.LiquibaseException
IOException
- in case of I/O errors.
-
writeChangeSet
public void writeChangeSet(Resource changeLogResource, org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter.ChangeSetMetadata metadata) throws IOException Write a Liquibase ChangeSet containing all tables as initial ChangeSet.- Parameters:
changeLogResource
- resource that ChangeSet will be written to (or append to an existing ChangeSet file).metadata
- the ChangeSet metadata.- Throws:
IOException
- in case of I/O errors.
-
writeChangeSet
public void writeChangeSet(Resource changeLogResource, org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter.ChangeSetMetadata metadata, liquibase.database.Database database) throws liquibase.exception.LiquibaseException, IOException Write a Liquibase ChangeSet using aDatabase
to identify the differences between mapped entities and the existing database.- Parameters:
changeLogResource
- resource that ChangeSet will be written to (or append to an existing ChangeSet file).metadata
- the ChangeSet metadata.database
- database to identify the differences.- Throws:
liquibase.exception.LiquibaseException
IOException
- in case of I/O errors.
-
createChangeSet
protected liquibase.changelog.ChangeSet createChangeSet(org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter.ChangeSetMetadata metadata, liquibase.changelog.DatabaseChangeLog databaseChangeLog) Creates an initial ChangeSet.- Parameters:
metadata
- must not be null.databaseChangeLog
- must not be null.- Returns:
- the initial ChangeSet.
-
createChangeSet
protected liquibase.changelog.ChangeSet createChangeSet(org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter.ChangeSetMetadata metadata, liquibase.database.Database database, liquibase.changelog.DatabaseChangeLog databaseChangeLog) throws liquibase.exception.LiquibaseException Creates a diff ChangeSet by comparingDatabase
withmapped entities
.- Parameters:
metadata
- must not be null.databaseChangeLog
- must not be null.- Returns:
- the diff ChangeSet.
- Throws:
liquibase.exception.LiquibaseException
-