Class SingleToMultiRelationChange

java.lang.Object
ch.tocco.nice2.dbrefactoring.spi.liquibase.JdbcHelper
ch.tocco.nice2.dbrefactoring.impl.liquibase.SingleToMultiRelationChange
All Implemented Interfaces:
liquibase.change.custom.CustomChange, liquibase.change.custom.CustomTaskChange

public class SingleToMultiRelationChange extends JdbcHelper implements liquibase.change.custom.CustomTaskChange
Use this change to update your data if you want to change a n:1 or a n:0..1 relation to a n:n relation.

Before:

     nice_foo     nice_bar
     --------     --------
     pk           pk
     fk_bar
 
After:
     nice_foo     nice_foo_to_bar     nice_bar
     --------     ---------------     --------
     pk           fk_foo              pk
                  fk_bar
 
Changeset:
   <changeSet id="copyRelations/2.4.16" context="schemaDefinition" author="anonymous">
     <preConditions>
       <sqlCheck expectedResult="0">
         select count(*) from nice_foo_to_bar
       </sqlCheck>
     </preConditions>
     <customChange class="ch.tocco.nice2.dbrefactoring.impl.liquibase.SingleToMultiRelationChange">
       <param name="sourceTableName" value="nice_foo"/>
       <param name="sourceKeyName" value="id"/> (optional; "pk" = default)
       <param name="singleRelationFkName" value="fk_bar"/>
       <param name="multiRelationTableName" value="nice_foo_to_bar"/>
       <param name="fkNameToSourceTable" value="fk_foo"/>
       <param name="fkNameToTargetTable" value="fk_bar"/>
     </customChange>
   </changeSet>
 

Please note, that this CustomTaskChange only creates the records in your n:n table (nice_foo_to_bar in this example). You have to create this table and also to drop the foreign key on your source table (nice_foo.fk_bar in this example) on your own.

  • Constructor Details

    • SingleToMultiRelationChange

      public SingleToMultiRelationChange()
  • Method Details

    • getSourceTableName

      public String getSourceTableName()
    • setSourceTableName

      public void setSourceTableName(String sourceTableName)
    • getSourceKeyName

      public String getSourceKeyName()
    • setSourceKeyName

      public void setSourceKeyName(String sourceKeyName)
    • getSingleRelationFkName

      public String getSingleRelationFkName()
    • setSingleRelationFkName

      public void setSingleRelationFkName(String singleRelationFkName)
    • getMultiRelationTableName

      public String getMultiRelationTableName()
    • setMultiRelationTableName

      public void setMultiRelationTableName(String multiRelationTableName)
    • getFkNameToSourceTable

      public String getFkNameToSourceTable()
    • setFkNameToSourceTable

      public void setFkNameToSourceTable(String fkNameToSourceTable)
    • getFkNameToTargetTable

      public String getFkNameToTargetTable()
    • setFkNameToTargetTable

      public void setFkNameToTargetTable(String fkNameToTargetTable)
    • execute

      public void execute(liquibase.database.Database database) throws liquibase.exception.CustomChangeException
      Specified by:
      execute in interface liquibase.change.custom.CustomTaskChange
      Throws:
      liquibase.exception.CustomChangeException
    • getConfirmationMessage

      public String getConfirmationMessage()
      Specified by:
      getConfirmationMessage in interface liquibase.change.custom.CustomChange
    • setUp

      public void setUp() throws liquibase.exception.SetupException
      Specified by:
      setUp in interface liquibase.change.custom.CustomChange
      Throws:
      liquibase.exception.SetupException
    • setFileOpener

      public void setFileOpener(liquibase.resource.ResourceAccessor resourceAccessor)
      Specified by:
      setFileOpener in interface liquibase.change.custom.CustomChange
    • validate

      public liquibase.exception.ValidationErrors validate(liquibase.database.Database database)
      Specified by:
      validate in interface liquibase.change.custom.CustomChange