I'm evaluating Liquibase and trying to figure out if it has any advantages for data migrations over just using SQL scripts. Suppose I'm doing the following:
My version 0 database schema looks like this:
CREATE TABLE `Person` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`firstName` varchar(255) NOT NULL,
`lastName` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);
The database is populated with some existing data represented by the following insert:
INSERT INTO `Person` (`id`, `firstName`, `lastName`) VALUES (1, 'foo', 'bar');
I then decide to add another column to the Person table that is not null but I don't want to lose any existing data. The migration script from version 0 to version 1 would look like this:
ALTER TABLE `Person` ADD COLUMN `dob` date DEFAULT NULL;
UPDATE `Person` set `dob` = '1970-01-01';
ALTER TABLE `Person` MODIFY COLUMN `dob` NOT NULL;
Could Liquibase make this use case easier?