I'm setting up a release process to upgrade our production environment as easily as possible.
To achieve that concerning database, I've chosen liquibase. Each time an environment is upgrade :
- The code is deliver on servers,
mvn liquibase:diff
is run to generate a changeLog with previous versionmvn spring-boot:run
is run to start the application and execute liquibase with the new changeLog, and so, adapt the database from code entity freshly delivered.
The problem is that if a field in a java @Entity
is, for example, moved to an other entity, liquibase will remove the column without transfering data to the new field location.
So my question is, can we configure liquibase to avoid column and table drop ? To be able to copy datas to their new locations, and after that, effectively remove the column (or table) for good ?
We're using spring-boot 2.1.2 and the liquibase maven plugin 3.4.1. Our database is on MySQL 5.7.27.
I've try to find how to export all database creation/alteration changeSet
in one changeLog.xml
and all drop changeSet
in an other changeLog.xml
.
Like that we can execute between these two changeLog
, a third changeLog
dedicated to copy data to thier new location.
Bu didn't find solution in liquibase documentation : https://www.liquibase.org/documentation/diff.html
To illustrate my example :
v1:
@Entity
public class Person {
private long id;
private String name;
private String phoneNumber;
}
Became
v2: (creation of entity Phone to replace field phoneNumber of entity Person)
@Entity
public class Person {
private long id;
private String name;
private Phone phone;
}
@Entity
public class Phone {
private long id;
private String phoneNumber;
private String brand;
}
So when v2 is delivered on server and mvn liquibase:diff
is run, the result changeLog will drop column phoneNumber and create column phone in table person.
Without transfering data from table person, filed phoneNumber to the new table phone in field phoneNumber.
I want to execute changeLog (manually wrote) that copy Person.phoneNumber to new entity Phone.phoneNumber.
Is that possible ? Or there is any trick to do that properly ? Or maybe I'm using liquibase in bad way to achieve that ?
Thanks a lot !