How changes are constructed and run when reading changelogs:
To implement a new change:
Implementing automatic rollback support
The easiest way to allow automatic rollback support is by overriding the createInverses() method. If there are no corresponding inverse changes, you can override the generateRollbackStatements(*) and canRollBack() methods.
Notes for generated SQL:
Because migration and rollback scripts can be generated for execution at a different time, or against a different database, changes you implement cannot directly reference data in the database. For example, you cannot implement a change that selects all rows from a database and modifies them based on the primary keys you find because when the SQL is actually run, those rows may not longer exist and/or new rows may have been added.
We chose the name "change" over "refactoring" because changes will sometimes change functionality whereas true refactoring will not.
Database
Definition at line 51 of file Change.java.
Public Member Functions | |
| String | getChangeName () |
| Returns the name of this change. | |
| String | getTagName () |
| Returns the tag name of this change. | |
| void | executeStatements (Database database) throws JDBCException, UnsupportedChangeException |
| Executes the statements in this change against the database passed in the argument. | |
| void | saveStatements (Database database, Writer writer) throws IOException, UnsupportedChangeException, StatementNotSupportedOnDatabaseException |
| Outputs the SQL statements generated by this change. | |
| void | executeRollbackStatements (Database database) throws JDBCException, UnsupportedChangeException, RollbackImpossibleException |
| Rolls back the statements in this change against the Database passed as argument. | |
| void | saveRollbackStatement (Database database, Writer writer) throws IOException, UnsupportedChangeException, RollbackImpossibleException, StatementNotSupportedOnDatabaseException |
| Outputs the statements necessary to roll back this change. | |
| SqlStatement[] | generateStatements (Database database) throws UnsupportedChangeException |
| Generates the SQL statements required to run the change. | |
| SqlStatement[] | generateRollbackStatements (Database database) throws UnsupportedChangeException, RollbackImpossibleException |
| Generates the SQL statements required to roll back the change. | |
| boolean | canRollBack () |
| Can this change be rolled back. | |
| String | getConfirmationMessage () |
| Confirmation message to be displayed after the change is executed. | |
| Element | createNode (Document currentChangeLogDOM) |
| Creates an XML element (of type Element) of the change object, and adds it to the Document object passed as argument. | |
| String | getMD5Sum () |
| Calculates the MD5 hash for the string representation of the XML element of this change. | |
| void | setFileOpener (FileOpener fileOpener) |
| Sets the fileOpener that should be used for any file loading and resource finding for files that are provided by the user. | |
| void | setUp () throws SetupException |
| This method will be called after the no arg constructor and all of the properties have been set to allow the task to do any heavy tasks or more importantly generate any exceptions to report to the user about the settings provided. | |
| String liquibase.change.Change.getChangeName | ( | ) |
Returns the name of this change.
Implemented in liquibase.change.AbstractChange.
| String liquibase.change.Change.getTagName | ( | ) |
Returns the tag name of this change.
Implemented in liquibase.change.AbstractChange.
| void liquibase.change.Change.executeStatements | ( | Database | database | ) | throws JDBCException, UnsupportedChangeException |
Executes the statements in this change against the database passed in the argument.
| database | the reference to the target Database to which the statements are executed |
| JDBCException | if there were problems executing the statements | |
| UnsupportedChangeException | if this change is not supported by the Database passed as argument |
Implemented in liquibase.change.AbstractChange.
| void liquibase.change.Change.saveStatements | ( | Database | database, | |
| Writer | writer | |||
| ) | throws IOException, UnsupportedChangeException, StatementNotSupportedOnDatabaseException |
Outputs the SQL statements generated by this change.
| database | the target Database associated to this change's statements | |
| writer | the target Writer to which the statements are appended |
| IOException | if there were problems appending the statements to the writer | |
| UnsupportedChangeException | if this change is not supported by the Database passed as argument |
Implemented in liquibase.change.AbstractChange.
| void liquibase.change.Change.executeRollbackStatements | ( | Database | database | ) | throws JDBCException, UnsupportedChangeException, RollbackImpossibleException |
Rolls back the statements in this change against the Database passed as argument.
| database | the target Database associated to this change's rollback statements |
| JDBCException | if there were problems executing the rollback statements | |
| UnsupportedChangeException | if this change is not supported by the Database passed as argument | |
| RollbackImpossibleException | if rollback is not supported for this change |
Implemented in liquibase.change.AbstractChange.
| void liquibase.change.Change.saveRollbackStatement | ( | Database | database, | |
| Writer | writer | |||
| ) | throws IOException, UnsupportedChangeException, RollbackImpossibleException, StatementNotSupportedOnDatabaseException |
Outputs the statements necessary to roll back this change.
| database | the target Database associated to this change's rollback statements | |
| writer | writer the target Writer to which the rollback statements are appended |
| IOException | if there were problems appending the rollback statements to the writer | |
| UnsupportedChangeException | if this change is not supported by the Database passed as argument | |
| RollbackImpossibleException | if rollback is not supported for this change |
Implemented in liquibase.change.AbstractChange.
| SqlStatement [] liquibase.change.Change.generateStatements | ( | Database | database | ) | throws UnsupportedChangeException |
Generates the SQL statements required to run the change.
| database | databasethe target Database associated to this change's statements |
| UnsupportedChangeException | if this change is not supported by the Database passed as argument |
Implemented in liquibase.change.AbstractSQLChange, liquibase.change.AddAutoIncrementChange, liquibase.change.AddColumnChange, liquibase.change.AddDefaultValueChange, liquibase.change.AddForeignKeyConstraintChange, liquibase.change.AddLookupTableChange, liquibase.change.AddNotNullConstraintChange, liquibase.change.AddPrimaryKeyChange, liquibase.change.AddUniqueConstraintChange, liquibase.change.AlterSequenceChange, liquibase.change.CreateIndexChange, liquibase.change.CreateSequenceChange, liquibase.change.CreateTableChange, liquibase.change.CreateViewChange, liquibase.change.custom.CustomChangeWrapper, liquibase.change.DropColumnChange, liquibase.change.DropDefaultValueChange, liquibase.change.DropForeignKeyConstraintChange, liquibase.change.DropIndexChange, liquibase.change.DropNotNullConstraintChange, liquibase.change.DropPrimaryKeyChange, liquibase.change.DropSequenceChange, liquibase.change.DropTableChange, liquibase.change.DropUniqueConstraintChange, liquibase.change.DropViewChange, liquibase.change.ExecuteShellCommandChange, liquibase.change.InsertDataChange, liquibase.change.MergeColumnChange, liquibase.change.ModifyColumnChange, liquibase.change.RenameColumnChange, liquibase.change.RenameTableChange, and liquibase.change.RenameViewChange.
Referenced by liquibase.change.AbstractChange.executeStatements(), and liquibase.change.AbstractChange.saveStatements().
| SqlStatement [] liquibase.change.Change.generateRollbackStatements | ( | Database | database | ) | throws UnsupportedChangeException, RollbackImpossibleException |
Generates the SQL statements required to roll back the change.
| database | database databasethe target Database associated to this change's rollback statements |
| UnsupportedChangeException | if this change is not supported by the Database passed as argument | |
| RollbackImpossibleException | if rollback is not supported for this change |
Implemented in liquibase.change.AbstractChange, and liquibase.change.custom.CustomChangeWrapper.
| boolean liquibase.change.Change.canRollBack | ( | ) |
Can this change be rolled back.
Implemented in liquibase.change.AbstractChange, and liquibase.change.custom.CustomChangeWrapper.
| String liquibase.change.Change.getConfirmationMessage | ( | ) |
Confirmation message to be displayed after the change is executed.
Implemented in liquibase.change.AddAutoIncrementChange, liquibase.change.AddColumnChange, liquibase.change.AddDefaultValueChange, liquibase.change.AddForeignKeyConstraintChange, liquibase.change.AddLookupTableChange, liquibase.change.AddNotNullConstraintChange, liquibase.change.AddPrimaryKeyChange, liquibase.change.AddUniqueConstraintChange, liquibase.change.AlterSequenceChange, liquibase.change.CreateIndexChange, liquibase.change.CreateSequenceChange, liquibase.change.CreateTableChange, liquibase.change.CreateViewChange, liquibase.change.custom.CustomChangeWrapper, liquibase.change.DropColumnChange, liquibase.change.DropDefaultValueChange, liquibase.change.DropForeignKeyConstraintChange, liquibase.change.DropIndexChange, liquibase.change.DropNotNullConstraintChange, liquibase.change.DropPrimaryKeyChange, liquibase.change.DropSequenceChange, liquibase.change.DropTableChange, liquibase.change.DropUniqueConstraintChange, liquibase.change.DropViewChange, liquibase.change.ExecuteShellCommandChange, liquibase.change.InsertDataChange, liquibase.change.MergeColumnChange, liquibase.change.ModifyColumnChange, liquibase.change.RawSQLChange, liquibase.change.RenameColumnChange, liquibase.change.RenameTableChange, liquibase.change.RenameViewChange, and liquibase.change.SQLFileChange.
| Element liquibase.change.Change.createNode | ( | Document | currentChangeLogDOM | ) |
Creates an XML element (of type Element) of the change object, and adds it to the Document object passed as argument.
| currentChangeLogDOM | the current Document where this element is being added |
Implemented in liquibase.change.AddAutoIncrementChange, liquibase.change.AddColumnChange, liquibase.change.AddDefaultValueChange, liquibase.change.AddForeignKeyConstraintChange, liquibase.change.AddLookupTableChange, liquibase.change.AddNotNullConstraintChange, liquibase.change.AddPrimaryKeyChange, liquibase.change.AddUniqueConstraintChange, liquibase.change.AlterSequenceChange, liquibase.change.CreateIndexChange, liquibase.change.CreateSequenceChange, liquibase.change.CreateTableChange, liquibase.change.CreateViewChange, liquibase.change.custom.CustomChangeWrapper, liquibase.change.DropColumnChange, liquibase.change.DropDefaultValueChange, liquibase.change.DropForeignKeyConstraintChange, liquibase.change.DropIndexChange, liquibase.change.DropNotNullConstraintChange, liquibase.change.DropPrimaryKeyChange, liquibase.change.DropSequenceChange, liquibase.change.DropTableChange, liquibase.change.DropUniqueConstraintChange, liquibase.change.DropViewChange, liquibase.change.ExecuteShellCommandChange, liquibase.change.InsertDataChange, liquibase.change.MergeColumnChange, liquibase.change.ModifyColumnChange, liquibase.change.RawSQLChange, liquibase.change.RenameColumnChange, liquibase.change.RenameTableChange, liquibase.change.RenameViewChange, and liquibase.change.SQLFileChange.
Referenced by liquibase.change.AbstractChange.getMD5Sum().
| String liquibase.change.Change.getMD5Sum | ( | ) |
Calculates the MD5 hash for the string representation of the XML element of this change.
Implemented in liquibase.change.AbstractChange, and liquibase.change.SQLFileChange.