Reputation: 366
I have a spring boot project which initially uses hibernate.ddl-auto: update command to create schema. Now i want to migrate to liquibase, so for this steps followed are:
diffChangeLog
on cmd to generate existing schema -> got generated in db/changelog folder.changelogSync
on cmd, I was able to create liquibase related table(changeLog and lock) and all existing schema related insert statement were also inserted.So far so good. now i want to move this change to production, When my spring boot project starts it should automatically run changelogSync
command before hand and then boot strap the project, so that i don't need to run these command manually. how can i achieve this?
Upvotes: 0
Views: 558
Reputation: 1608
There are 2 ways which you can use. Change your pipeline(in jenkins or bamboo or any other tool) so you can execute changelogSync
before even you start your application(advantage of this is that liquibase command is totally decoupled from your app). The second approach is to implement CommandLineRunner
like this:
@Component
public class CommandLineAppStartupRunner implements CommandLineRunner {
@Override
public void run(String...args) throws Exception {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("liquibase changelogSync");//or any other command
}
}
You can even pass your command as argument to command line runner if you want.
Upvotes: 0
Reputation: 367
As far as diffChangeLog is concerned it is used to point out the differences in general and generates changes to resolve most of them. Where the changeLogSync commands ONLY marks all undeployed changes in your changelog as executed in your database, it does not deploy any changes. From what understand this is not the best approach to migrate the database.
Upvotes: 0