Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow gradle plugin to create multiple migrate tasks for different (database) schemas #830

Closed
aldas opened this issue Aug 28, 2014 · 1 comment
Milestone

Comments

@aldas
Copy link
Contributor

aldas commented Aug 28, 2014

Currently "FlywayMigrateTask" depends on hard coded "project.flyway" property and it is really difficult to use gradle plugin when you need to migrate multiple different database instance schemas.

a la requirement: gradle build should be able to migrate 2 different (database instance) schemas before application/tests are run

task flywayMigrateA(type: org.flywaydb.gradle.task.FlywayMigrateTask) {
    extension = new org.flywaydb.gradle.FlywayExtension()
    extension.driver = "oracle.jdbc.OracleDriver"
    extension.schemas = ['DB1_SCHEMA_A']
    extension.locations = ['filesystem:database/A/']
    extension.sqlMigrationPrefix = "V"
    extension.initOnMigrate = true
    extension.outOfOrder = true
    extension.url = $databaseA_jdbc_connection_string
}

task flywayMigrateB(type: org.flywaydb.gradle.task.FlywayMigrateTask) {
    extension = new org.flywaydb.gradle.FlywayExtension()
    extension.driver = "oracle.jdbc.OracleDriver"
    extension.schemas = ['DB2_SCHEMA_B']
    extension.locations = ['filesystem:database/B/']
    extension.sqlMigrationPrefix = "V"
    extension.initOnMigrate = true
    extension.outOfOrder = true
    extension.url = $databaseB_jdbc_connection_string
}

so you could ./gradlew flywayMigrateA flywayMigrateB

It is curretly not possible so I changed org.flywaydb.gradle.task.AbstractFlywayTask extension property from private to protected.

private FlywayExtension extension

to

protected FlywayExtension extension

Now you'll be able to override extension from your custom tasks. There is probably nicer ways to to this but I'm not that good at Gradle/Groovy and this seems simple small change.

p.s. maybe it would be also good addition to change "prop" method from private to protected so if you need your own logic to get properties you do not need to reimplement almost all AbstractFlywayTask class as "createFlyway" method does not see your extended class prop method.

@aldas aldas changed the title Allow gladle plugin to create multiple migrate targets for different (database) schemas Allow gladle plugin to create multiple migrate tasks for different (database) schemas Aug 28, 2014
@aldas aldas changed the title Allow gladle plugin to create multiple migrate tasks for different (database) schemas Allow gradle plugin to create multiple migrate tasks for different (database) schemas Aug 28, 2014
axelfontaine pushed a commit that referenced this issue Oct 14, 2014
change for #830: allow tasks extending AbstractFlywayTask to set their o...
@axelfontaine
Copy link
Contributor

Thanks for issue and the pull request! Looks like an easy improvement. Merged into 3.1 due out before the end of this month.

Cheers
Axel

@axelfontaine axelfontaine added this to the Flyway 3.1 milestone Oct 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants