Class LiquibaseChangeSetWriter

java.lang.Object
org.springframework.data.jdbc.core.mapping.schema.LiquibaseChangeSetWriter

public class LiquibaseChangeSetWriter extends Object
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
The 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

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Use this to generate a ChangeSet that can be used on an empty database.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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 comparing Database with mapped entities.
    void
    setChangeLogParser(liquibase.parser.ChangeLogParser changeLogParser)
    Set the ChangeLogParser.
    void
    setChangeLogSerializer(liquibase.serializer.ChangeLogSerializer changeLogSerializer)
    Set the ChangeLogSerializer.
    void
    Set the filter predicate to identify columns within a table to drop.
    void
    Set the filter predicate to identify tables to drop.
    void
    Set the filter predicate to identify for which entities to create schema definitions.
    void
    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 a Database 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 a Database to identify the differences between mapped entities and the existing database.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • setSqlTypeMapping

      public void setSqlTypeMapping(SqlTypeMapping sqlTypeMapping)
      Configure SQL type mapping. Defaults to DefaultSqlTypeMapping.
      Parameters:
      sqlTypeMapping - must not be null.
    • setChangeLogSerializer

      public void setChangeLogSerializer(liquibase.serializer.ChangeLogSerializer changeLogSerializer)
      Set the ChangeLogSerializer.
      Parameters:
      changeLogSerializer - must not be null.
    • setChangeLogParser

      public void setChangeLogParser(liquibase.parser.ChangeLogParser changeLogParser)
      Set the ChangeLogParser.
      Parameters:
      changeLogParser - must not be null.
    • setSchemaFilter

      public void setSchemaFilter(Predicate<RelationalPersistentEntity<?>> schemaFilter)
      Set the filter predicate to identify for which entities to create schema definitions. Existing tables for excluded entities will show up in setDropTableFilter(Predicate). Returning true includes the entity; false excludes the entity from schema creation.
      Parameters:
      schemaFilter - must not be null.
    • setDropTableFilter

      public void setDropTableFilter(Predicate<String> dropTableFilter)
      Set the filter predicate to identify tables to drop. The predicate accepts the table name. Returning true will delete the table; false retains the table.
      Parameters:
      dropTableFilter - must not be null.
    • setDropColumnFilter

      public void setDropColumnFilter(BiPredicate<String,String> dropColumnFilter)
      Set the filter predicate to identify columns within a table to drop. The predicate accepts the table- and column name. Returning true will delete the column; false retains the column.
      Parameters:
      dropColumnFilter - must not be null.
    • writeChangeSet

      public void writeChangeSet(Resource changeLogResource) 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). The resource must resolve to a valid Resource.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 a Database 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 valid Resource.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 a Database 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 comparing Database with mapped entities.
      Parameters:
      metadata - must not be null.
      databaseChangeLog - must not be null.
      Returns:
      the diff ChangeSet.
      Throws:
      liquibase.exception.LiquibaseException