5

I have server which contains multiple databases, now i need to deploy the code on all the database in parallel, Is it possible in flyway to achieve this because for each database i need to have separate config file. So i wanted to know how to achieve in such way all the config will trigger in parallel.

Regards, Adarsh

2 Answers 2

6

Why do you need a separate config file for each database? You can override most/all the data in the config file using the various Flyway command switches documented here:

http://flywaydb.org/documentation/commandline/migrate.html

For example, you can use the -URL switch to override the JDBC connection string in the config file. This allows you to have a single config file but to run the upgrade against different target databases.

It is generally preferable to use these switches as it avoids duplication of code. (You won't need to maintain so many config files.) It also means you can avoid putting stuff like passwords into your source code.

Next step is to create a script that runs flyway migrate against each of your target databases. For example, you could write a script that does something like:

flyway migrate -url:jdbc:mysql://<host>:<port>/<database1>
flyway migrate -url:jdbc:mysql://<host>:<port>/<database2>
flyway migrate -url:jdbc:mysql://<host>:<port>/<database3>
flyway migrate -url:jdbc:mysql://<host>:<port>/<database4>

Now when you run this script each of your databases will be updated in sequence.

Alternatively, if you need the updates to run in parallel rather than in sequence, you need to find a way to schedule for each line to run at the same time. One way you could achieve this is to use an automation tool like Octopus Deploy to orchestrate your deployments.

If you want to use Octopus Deploy you may find this step template useful. This step template also includes a "Drift-Check" feature to ensure that your databases are in sync:

Flyway migrate step template for Octopus Deploy

If you plan to use any other tool you may find this PowerShell script useful (copied from the link above) where $locationsPath, $targetUrl, $targetUser and $targetPassword are all variables.

# Executing deployment
Write-Host "*******************************************"
Write-Host "Executing deployment:"
Write-Host " - - - - - - - - - - - - - - - - - - - - -"
    $arguments = @(
        "migrate"
        "-locations=filesystem:$locationsPath",
        "-url=$targetUrl",
        "-user=$targetUser",
        "-password=$targetPassword"
    )
Write-Host "Executing the following command: & $flywayCmd $arguments"

& $flywayCmd $arguments

Regards, Alex

(Open disclosure: I am a pre-sales engineer at Redgate Software. I wrote the step template mentioned above and worked with a team to build FlySQL, a tool that helps MySQL Flyway users to build their projects more efficiently.)

Sign up to request clarification or add additional context in comments.

5 Comments

Hi Alex, Thanks for the details provide that switching of URL, was a nice tip for me. But I have situation like for each database the code will be different so my SQL folder path for the each database will be a separate path it will not be common one, how I should handle in this scenario. I hope in this scenario at least I should have the database wise and folder path file separate config files. if this is the case , is there way to handle the multiple config file.
Hi Adarsh, In this case I believe the -locations switch will be useful. It allows you to add a specific relative path to a set of SQL scripts. You could tweak this switch per database you deploy to. In general, it is a wise idea to try to minimise such customisations for particular environments as it can make testing and maintenence a pain. It is very easy to underestimate the costs involved here.
Thanks Alex , I would like to know more on Octopus Deploy, is it a similar to flyway or its totally different and do we have command line utility for deploying so that a Jenkins job can use that command line utility available and trigger the deploy. Or else is octopus deploy is similar to jenkins deploy because when i was checking on that , i found it with the UI deployment so wanted some more info on it . could you please share some details of it
Octopus is an automation tool, like Jenkins, rather than a database deployment tool like Flyway. While Jenkins is ideal for builds/tests, Octopus is designed for deploys. Effectively it is a distributed PowerShell scheduling tool with native support for deploying web apps etc on the MS stack (they are adding Linux support). My step template extends Octopus to call Flyway to deploy your database. You'll need to package your Flyway project in a NuGet package. Typically this is something that would be handled by Jenkins etc. More info: octopus.com
Thanks for the details
2

In the Flyway documentation it describes a switch do specify a different config file. This way you

"To use an alternative configuration file use -configFiles=path/to/myAlternativeConfig.conf"

This way you should be able to use the same sql folder and yet apply different config settings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.