Reputation: 5899
I want to pull out the pre-deployment Flyway version number of my production database so I can use this in my continuous deployment pipeline (Jenkins) in case I do a rollback later.
How can I achieve this?
One option would be to query the flyway history table, but I can't work out a fail-safe way of achieving this.
Upvotes: 2
Views: 4328
Reputation: 5899
I have fashioned an answer, although it feels like a big of a hack. I run --dryRunOutput in migrate as a means to get flyway to output the version number to the screen, as info doesn't do this for some reason.
I read the output into a file (because DOS makes it hard to pipe or pass into a variable) then isolate the output line starting with "Current". I then pick the second token using : as my delimeter. There's probably an easier way, and I wish I could use flyway info instead of migrate as my method feels hacky, but at least it works for now.
flyway -dryRunOutput=test.sql migrate | FIND "Current" >currentversion.txt
for /f "delims=" %%x in (currentversion.txt) do set CURRENTVERSIONLINE=%%x
for /f "tokens=1,2 delims=:" %%a in ("%CURRENTVERSIONLINE%") do set CURRENTVERSION=%%b
echo Version : %CURRENTVERSION%
Upvotes: 1
Reputation: 35169
The following one-liner does what you want:
flyway info | grep Success | tail -1 | cut -f3 "-d|" | xargs
Upvotes: 0