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_barAfter:
nice_foo nice_foo_to_bar nice_bar -------- --------------- -------- pk fk_foo pk fk_barChangeset:
<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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(liquibase.database.Database database) void
setFileOpener
(liquibase.resource.ResourceAccessor resourceAccessor) void
setFkNameToSourceTable
(String fkNameToSourceTable) void
setFkNameToTargetTable
(String fkNameToTargetTable) void
setMultiRelationTableName
(String multiRelationTableName) void
setSingleRelationFkName
(String singleRelationFkName) void
setSourceKeyName
(String sourceKeyName) void
setSourceTableName
(String sourceTableName) void
setUp()
liquibase.exception.ValidationErrors
validate
(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:
execute
in interfaceliquibase.change.custom.CustomTaskChange
- Throws:
liquibase.exception.CustomChangeException
-
getConfirmationMessage
- Specified by:
getConfirmationMessage
in interfaceliquibase.change.custom.CustomChange
-
setUp
public void setUp() throws liquibase.exception.SetupException- Specified by:
setUp
in interfaceliquibase.change.custom.CustomChange
- Throws:
liquibase.exception.SetupException
-
setFileOpener
public void setFileOpener(liquibase.resource.ResourceAccessor resourceAccessor) - Specified by:
setFileOpener
in interfaceliquibase.change.custom.CustomChange
-
validate
public liquibase.exception.ValidationErrors validate(liquibase.database.Database database) - Specified by:
validate
in interfaceliquibase.change.custom.CustomChange
-