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.
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.
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.tocco.nice2.dbrefactoring.spi.liquibase.JdbcHelper
JdbcHelper.SqlFunction<A,B> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute(liquibase.database.Database database) voidsetFileOpener(liquibase.resource.ResourceAccessor resourceAccessor) voidsetFkNameToSourceTable(String fkNameToSourceTable) voidsetFkNameToTargetTable(String fkNameToTargetTable) voidsetMultiRelationTableName(String multiRelationTableName) voidsetSingleRelationFkName(String singleRelationFkName) voidsetSourceKeyName(String sourceKeyName) voidsetSourceTableName(String sourceTableName) voidsetUp()liquibase.exception.ValidationErrorsvalidate(liquibase.database.Database database) Methods inherited from class ch.tocco.nice2.dbrefactoring.spi.liquibase.JdbcHelper
ddlStatement, tableExists, uniqueIndexExists, withConnection, withResultSet, withStatement
-
Constructor Details
-
SingleToMultiRelationChange
public SingleToMultiRelationChange()
-
-
Method Details
-
getSourceTableName
-
setSourceTableName
-
getSourceKeyName
-
setSourceKeyName
-
getSingleRelationFkName
-
setSingleRelationFkName
-
getMultiRelationTableName
-
setMultiRelationTableName
-
getFkNameToSourceTable
-
setFkNameToSourceTable
-
getFkNameToTargetTable
-
setFkNameToTargetTable
-
execute
public void execute(liquibase.database.Database database) throws liquibase.exception.CustomChangeException - Specified by:
executein interfaceliquibase.change.custom.CustomTaskChange- Throws:
liquibase.exception.CustomChangeException
-
getConfirmationMessage
- Specified by:
getConfirmationMessagein interfaceliquibase.change.custom.CustomChange
-
setUp
public void setUp() throws liquibase.exception.SetupException- Specified by:
setUpin interfaceliquibase.change.custom.CustomChange- Throws:
liquibase.exception.SetupException
-
setFileOpener
public void setFileOpener(liquibase.resource.ResourceAccessor resourceAccessor) - Specified by:
setFileOpenerin interfaceliquibase.change.custom.CustomChange
-
validate
public liquibase.exception.ValidationErrors validate(liquibase.database.Database database) - Specified by:
validatein interfaceliquibase.change.custom.CustomChange
-