Back to Home

Liquibase: an example of automated rollback of changes to a relational database

database migrations · database tools · liquibase

Liquibase: an example of automated rollback of changes to a relational database

    Instead of the foreword


    The article will be interesting to those who at least once thought about the issue of rolling changes (patch) to a relational database. The article will not be interesting to those who have already mastered and use Liquibase. The main purpose of this article is to provide a link to a repository with an example of use. As an example, I chose the roll-up of HR sample-schema to the Oracle database (a list of all supported databases ) - anyone can download a repository and play at home. The desire to demonstrate an example is caused by a discussion of this issue on the sql.ru resource .


    What is Liquibase?


    What is Liquibase, you can find on the official website of the product. I would like to note a couple of good articles on this resource:
    Database migration management with Liquibase
    Using Liquibase without a headache. 10 tips from real-world development experience


    Why am I using Liquibase


    My choice settled on this tool, as:


    1) The tool keeps track of which changeset has already been applied to this database instance and rolls only those that have not rolled yet and which still need to be rolled. If during the run-up the application of any change fell with an error, then after eliminating the reason, you restart the run-up and Liquibase continues execution from the changeset on which it stopped.


    2) The ability to set the changeset attributes runOnChange and runAlways significantly simplifies the management of changes, in particular, recreatable objects.


    3) The context property allows you to perform / not make changeset depending on the current environment (for example, do not run unit tests on the prod).


    This was not a complete list of features.


    Repository


    He is here . It lists "hard" (tables, indexes, integrity constraints) and "soft" (triggers, procedures, views) objects, changesets with sql and sqlFile tags, with and without runOnChange and runAlways attributes.


    What is not in the repository


    Due to the lack of need for a repository, there are no such useful features / steps that I usually use in my projects:


    • Preconditions - allow you to set the condition for the implementation of changeset-a;
    • Compilation of circuit objects at the end of a run. In Oracle, this is dbms_utility.compile_schema (user, false);
    • Run unit tests.

    Read Next