Any advantages to using Liquibase for database migrations?
liquibase, sql
Solution
I went through the same thing recently. See: Adding a non-nullable column to existing table fails. Is the "value" attribute being ignored?
There is no way (in a single SQL statement) to add a column with a value for existing rows without setting that as the column's default value. So if you want the existing rows to have a different value than new rows added (including if you do not want a default value on the column at all) you will need at least two SQL statements. So using liquibase you would still need to add this column in the three steps you describe.
So my answer to your question is: Yes there are advantages of using liquibase over just maintaining a series of SQL scripts. But this is not one of them. :)
Problem
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?