I have an existing mysql table with two columns a and b.
I now want to add a column c to that table.
c should be nullable, should have a default value of NULL, except in those rows where column b has the value 10. Where b has the value 10, c should have a value X.
I understand that it is fairly simple to do this using SQL, but I want to do this using liquibase, since liquibase is what we use for our schema migrations.
Step 1: Add the update Change Type to your changeset with the needed attributes as it is shown in the examples. Step 2: Deploy your changeset by running the update command. Now, you should see an updated table. Note: You can use the update Change Type in combination with loadData and loadUpdateData Change Types.
The changeset tag is a unit of change that Liquibase executes on a database and which is used to group database Liquibase Change Types together. A list of changes created by multiple changesets are tracked in a changelog.
Have you already tried something like this?
<addColumn tableName="SGW_PRODOTTI_INFO_ATTRIBUTE">
<column name="AlternativeListPrice" type="double" defaultValue="0.0">
<constraints nullable="true"/>
</column>
</addColumn>
I think the best solution without using plain sql is following:
Use addColumn change, as Walter wrote;
Use update change.
You can choose to use both changes within a changeset, but a good practice is to separate each one by a separated changeset for liquibase transaction/rollback purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With