Liquibase - General Workflow

Once you have Liquibase going, this is the General Workflow.

A requirement comes in for a database change

Make a change to the Liquibase files

  1. Create a new branch, switch to that branch.

SQL

Usually there’s one transation file per database. Locate this file and open it.

Make changes to the file. For example…

1
2
3
4
5
6
7
8
9
-- changeset Mark:48378-09
Alter table Reconciles
add constraint Reconciles_EndDate_Def
default 0.00 for BalanceEnding;


-- changeset Mark:48378-11
create unique index Reconciled_BankAccountIdStatementClosingDate_Unique
on dbo.Reconciles(BankAccountId, StatementClosingDate);

In this case you need a comment above each sql command. “– changeset xxx:yyy” the combination of xxx:yyy must be unique and once liquibase proceses this it can never be changed - so be careful. but later you can add commands to undo the effect of that command.

Typically I use xxx = my name, yyy is broken into a task number, and a change for that task number. For example 48378-09 means task 48378, change 09.

XML

If you are using XML based liquibase files, then you need to add a new entry to the file.

1
2
3
4
5
6
7
8
9
10
11
<changeSet author="MarkWachdorf" id="63162-addColumn-3">
<addColumn catalogName="dd"
schemaName= "dbo"
tableName="DbColumn">
<column name="AngularAddToModel"
type="varchar(1)"/>
<column name="AngularShowOnAddEditForm"
type="varchar(1)">
</column>
</addColumn>
</changeSet>

In this case I am adding a couple of columns to the DbColumn database.

Execute Liquibase

1
liquibase update

or

1
liquibase updateSQL --changelog-file=dd_changelog.xml

Will scan the files and execute the changesets that have not yet been executed. If you have a change that has already been executed, then liquibase will not execute it again. If you get an error, then you need to fix the error and execute the command again.

Commit your branch