I'm using Postgres DB and for migration I'm using Liquibase. I have an ORDERS table with the following columns:
ID | DATE | NAME | CREATOR | ...
I need to add a new column which will hold the user who has last modified the order - this column should be not-nullable and should have default value which is the CREATOR. For new orders I can solve the default value part of the business logic, but thing is I already have an existing orders and I need to set the default value when I create the new column. Now, I know I can set a hard-coded default value in Liquibase - but is there a way I could add the default value based on some other column of that table (for each entity).
Since no one answered here I'm posting the way I handled it:
I've done this in three different change-sets as the documentation recommends
You could use the
defaultValueComputed
attribute, which takes the name of a procedure or function. You would have to also create a changeset that creates the procedure.That might look something like this:
Alternatively, you could do this using the
<sql>
tag.