Second migration in build.gradle

I use gradle. And in my build.gradle I set my flyway credentials for my database as follows:

"def flywayUrl = System.getenv("flywayUrl") ?: project["flyway.url"]
def flywayUser = System.getenv("flywayUser") ?: project["flyway.user"]
def flywayPassword = System.getenv("flywayPassword") ?: project["flyway.password"]

project["flyway.url"] = flywayUrl
project["flyway.user"] = flywayUser
project["flyway.password"] = flywayPassword"

This database is in a docker-container.
Now I built a second database docker-container. This should be the database for my tests. Of course it should have the same structure and since we use Flyway I thought it would be super practical to use the migrations for productive-database and the testing-database. So I wanted to migrate my testing-database with all my Flyway-Migrations:

task flywayMigrateTesting(type: org.flywaydb.gradle.task.FlywayMigrateTask) {     
    url = "jdbc:mysql://db-testing:3306/prf2?useSSL=true&useUnicode=yes&characterEncoding=UTF-8"
    user = "user"
    password = "password"
    println("flywayMigrateTesting für URL: "+ url)
}
As you can see I did it as the official documentation explains it (https://documentation.red-gate.com/fd/gradle-task-184127407.html) but it just do nothing.

I did a println and the url which was printed is correct. But somehow it do nothing at all on my database.
When I run the command with infos (./gradlew flywayMigrateTesting -i) I can see, that the wrong database is used:
Database: jdbc:mysql://db:3306/prf2 (MySQL 11.1)
this is my productive database. It should "db-testing" and not "db".

I also just set up a random url, user and password
task flywayMigrateTesting(type: org.flywaydb.gradle.task.FlywayMigrateTask) {     
    url = "jdbc:mysql://db-testingZZZZZZZZZZZ:3306/prf2?useSSL=true&useUnicode=yes&characterEncoding=UTF-8"
    user = "userZZZZZZZZZZZ"
    password = "passwordZZZZZZZZZZZ"
    println("flywayMigrateTesting für URL: "+ url)
}
and just don't get an error. It just returns "BUILD SUCCESSFUL", which is for me a indicator, that my variables url, user, password aren't used at all. They are just ignored.

And finally, to make sure my container is correctly set up and not the root problem, I changed the url of the origin migration to my testing database and it worked. It completely migrated my testing database. But it seems not to be possible to migrate a second database.

Please don't tell me flyway is there to migrate a database by scripts to get always the necessary database structure, while it is not able to migrate more than one database.
Tagged:

Answers

  • Peter_LawsPeter_Laws Posts: 278 Silver 2
    edited July 29, 2024 8:33AM
    Hi chris080,

    Please could you clarify if in your second instance you're overwriting the flywayMigrateTesting task with the new parameters, or using a second definition such as it detailed in the documentation you referenced?

    E.G
    task migrateDatabase1(type: org.flywaydb.gradle.task.FlywayMigrateTask) {    url = 'jdbc:h2:mem:mydb1'    user = 'myUsr1'    password = 'mySecretPwd1'}
    task migrateDatabase2(type: org.flywaydb.gradle.task.FlywayMigrateTask) {    url = 'jdbc:h2:mem:mydb2'    user = 'myUsr2'    password = 'mySecretPwd2'}

    (source)
    Kind regards
    Peter Laws | Redgate Software
    Have you visited our Help Center?

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file