Liquibase Philosophy |
---|
Liquibase, is an Apache Licensed open source library written in Java for tracking, managing and applying database changes. |
Liquibase Links |
---|
|
CONCEPTS | |
---|---|
|
Developers store database changes in text-based files on their local development machines and apply them to their local databases. |
|
Change Sets are uniquely identified by the "author" and "id" attribute along with with the location of the changelog file and are the units Liquibase tracks execution of. |
|
Each changeset generally contains a change which describes the change/refactoring to apply to the database. Liquibase supports both descriptive changes that generate SQL for supported databases and raw SQL. |
|
Preconditions can be applied to either the changelog as a whole or individual change sets. If a precondition fails, Liquibase will stop execution. |
|
Contexts can be applied to changesets to control which are ran in different environments. For example, some changesets can be tagged as "production" and others as "test". If no context is specified, the changeset will run regardless of the execution context |
FEATURES |
---|
|
Best Practices |
---|
|
Liquibase Core |
---|
|
Liquibase Maven Plugin configuration |
---|
|
Maven Goals | |
---|---|
Drops all database objects owned by the user. Note that functions, procedures and packages are not dropped. |
|
Applies the DatabaseChangeLogs to the database. Useful as part of the build process. |
|
Writes a Liquibase tag to the database. |
|
Invokes Liquibase rollbacks on a database. |
|
Prints which changesets need to be applied to the database. |
|
Applies the DatabaseChangeLogs to the database, testing rollback. This is done by updating the database, rolling it back then updating it again. |
|
Generates the SQL that is required to update the database to the current version as specified in the DatabaseChangeLogs. |
Liquibase Commands | |
---|---|
|
Liquibase allows you to apply database changes you and other developers have added to the change log file. |
|
Liquibase allows you to undo changes you have made to your database, either automatically or via custom rollback SQL. |
|
While the best way to track database changes is by adding change sets during development, there are times when being able to perform database diffs is valuable, particularly near the end of a project as a double-check that all required changes are included in the change log. |
|
Depending on your development and release processes, you may not want Liquibase to directly update your database. |
|
Using change information stored in the change logs and an existing database, Liquibase can generate database change documentation. |
DDL - CREATE | ||
---|---|---|
CHANGE |
DESCRIPTION |
ROLLBACK |
Converts an existing column to be an auto-increment column |
|
|
Adds a new column to an existing table |
|
|
Adds a default value to the database definition for the specified column. One of defaultValue, defaultValueNumeric, defaultValueBoolean or defaultValueDate must be set |
|
|
Adds a foreign key constraint to an existing column |
|
|
Creates a lookup table containing values stored in a column and creates a foreign key to the new table. |
|
|
Adds a not-null constraint to an existing table. If a defaultNullValue attribute is passed, all null values for the column will be updated to the passed value before the constraint is applied. |
|
|
Adds creates a primary key out of an existing column or set of columns. |
|
|
Adds a unique constrant to an existing column or set of columns. |
|
|
Creates an index on an existing column or set of columns. |
|
|
Defines the definition for a stored procedure. This command is better to use for creating procedures than the raw sql command because it will not attempt to strip comments or break up lines. |
|
|
Creates a new database sequence |
|
|
Create Table |
|
|
Create a new database view |
|
DDL - DROP/UPDATE | ||
---|---|---|
CHANGE |
DESCRIPTION |
ROLLBACK |
Drops all foreign key constraints for a table |
|
|
Drop an existing column |
|
|
Removes the database default value for a column |
|
|
Drops an existing foreign key |
|
|
Drops an existing index |
|
|
Makes a column nullable |
|
|
Drops an existing primary key |
|
|
Drop an existing sequence |
|
|
Drops an existing table |
|
|
Drops an existing unique constraint |
|
|
Drops an existing view |
|
|
Alter properties of an existing sequence |
|
|
Modify data type |
|
|
Renames an existing column |
|
|
Renames an existing table |
|
|
Renames an existing view |
|
DML CHANGES | ||
---|---|---|
CHANGE |
DESCRIPTION |
ROLLBACK |
Deletes data from an existing table |
|
|
Inserts data into an existing table |
|
|
Concatenates the values in two columns, joins them by with string, and stores the resulting value in a new column. |
|
|
Updates data in an existing table |
|
OTHER CHANGES | ||
---|---|---|
CHANGE |
DESCRIPTION |
ROLLBACK |
Although Liquibase tries to provide a wide range of database refactorings, there are times you may want to create your own custom refactoring class. |
|
|
Executes a system command. Because this refactoring doesn’t generate SQL like most, using LiquiBase commands such as migrateSQL may not work as expected. Therefore, if at all possible use refactorings that generate SQL. |
|
|
Loads data from a CSV file into an existing table. A value of NULL in a cell will be converted to a database NULL rather than the string NULL |
|
|
Loads or updates data from a CSV file into an existing table. Differs from loadData by issuing a SQL batch that checks for the existence of a record. If found, the record is UPDATEd, else the record is INSERTed. Also, generates DELETE statements for a rollback. |
|
|
The sql tag allows you to specify whatever sql you want. It is useful for complex changes that aren’t supported through Liquibase’s automated refactoring tags and to work around bugs and limitations of Liquibase. The SQL contained in the sql tag can be multi-line. |
|
|
The sqlFile tag allows you to specify any sql statements and have it stored external in a file. It is useful for complex changes that are not supported through LiquiBase’s automated refactoring tags such as stored procedures. |
|
|
Applies a tag to the database for future rollback |
|