Arthur
Arthur

Reputation: 3473

How liquibase determines, what changes should be applied?

I am newbie in liquibase, I've read liquibase docs, but still didn't find, how liquibase determines current version of the DB and what changes should be applied on update.

For example, if to consider SQL script from liquibase site main page:

First run of the update, sql file is:

--liquibase formatted sql

--changeset nvoxland:1
create table person (
  id int not null primary key,
  firstname varchar(80),
  lastname varchar(80) not null,
  state varchar(2)
);

Second run of the update, the script is

--liquibase formatted sql

--changeset nvoxland:1
create table person (
  id int not null primary key,
  firstname varchar(80),
  lastname varchar(80) not null,
  state varchar(2)
);

--changeset nvoxland:2
alter table person MODIFY column firstname varchar(8)

Third run is:

--liquibase formatted sql

--changeset nvoxland:1
create table person (
  id int not null primary key,
  firstname varchar(80),
  lastname varchar(80) not null,
  state varchar(2)
);

--changeset nvoxland:2
alter table person MODIFY column firstname varchar(8)

--changeset nvoxland:3
alter table person MODIFY column firstname varchar(10)

4th run:

--liquibase formatted sql

--changeset nvoxland:1
create table person (
  id int not null primary key,
  firstname varchar(80),
  lastname varchar(80) not null,
  state varchar(2)
);

--changeset nvoxland:2
alter table person MODIFY column firstname varchar(8)

--changeset nvoxland:3
alter table person MODIFY column firstname varchar(10)

--changeset nvoxland:4
alter table person MODIFY column firstname varchar(8)

5th run is:

--liquibase formatted sql

--changeset nvoxland:1
create table person (
  id int not null primary key,
  firstname varchar(80),
  lastname varchar(80) not null,
  state varchar(2)
);

--changeset nvoxland:2
alter table person MODIFY column firstname varchar(8)

--changeset nvoxland:3
alter table person MODIFY column firstname varchar(10)

--changeset nvoxland:4
alter table person MODIFY column firstname varchar(8)

--changeset nvoxland:5
alter table person MODIFY column firstname varchar(15)

What will be happened on 5th update run and how liquibase will determine, that after 4th run database version will be "4" and need to modify column to 15 chars length?

May be, liquibase adds some "version" table to the database, where it inserts the latest version of the applied changeset/patch?

Thank you!

Upvotes: 1

Views: 1803

Answers (1)

slim
slim

Reputation: 41223

http://www.liquibase.org/documentation/index.html says:

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. When Liquibase runs, it queries the DATABASECHANGELOG table for the changesets that are marked as executed and then executes all changesets in the changelog file that have not yet been executed.

Upvotes: 6

Related Questions