question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API: Make it possible to use pre-instantiated Java-based migrations

See original GitHub issue

Hi,

as we are using Spring with Flyway we want to use other beans inside the SpringJdbcMigrations. Therefore we created a new resolver which retrieves the SpringJdbcMigrations from the Spring application context. This way we are able to define the migrations inside the application context and reference other beans we would need for this migration inside the SpringJdbcMigraiton with the dependency injection mechanisms of Spring (@Autowired). Please have a look at the linked pull request and the tests how this is done.

If this pull request is accepted and integrated, then I would also add some documentation to the website project of Flyway on how to use this new resolver.

Thanks and regards,

Guy

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:9
  • Comments:26 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
simonzhong1985commented, Jan 15, 2019

Sry I forgot to mention our configuration:

@Configuration
class FlywayConfiguration {
    @Primary
    @Bean(name = "flywayInitializer")
    @DependsOn("springUtility") //or whatever your ApplicationContextAware is named
    FlywayMigrationInitializer flywayMigrationInitializer(){
      //your flyway init configuration...
    }
}

The trick here is to force FlywayMigrationInitializer to get instantiated after the ApplicationContextAware workaround

This has now been implemented generically using a new javaMigrations property in the API.

Spring users can use this to automatically use all JavaMigration Spring beans with Flyway:

import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.migration.JavaMigration;
import org.springframework.context.ApplicationContext;

...
ApplicationContext applicationContext = ...; // obtain a reference to Spring's ApplicationContext.

Flyway flyway = Flyway.configure()
    .dataSource(url, user, password)
    // Add all Spring-instantiated JavaMigration beans
    .javaMigrations(applicationContext.getBeansOfType(JavaMigration.class).values().toArray(new JavaMigration[0]))
    .load();
flyway.migrate();

@axelfontaine Could you help to provide one example to show how to inject spring bean into class implementation of JavaMigration interface?

Thanks, Simon

4reactions
axelfontainecommented, Dec 11, 2018

This has now been implemented generically using a new javaMigrations property in the API.

Spring users can use this to automatically use all JavaMigration Spring beans with Flyway:

import org.flywaydb.core.Flyway;
import org.flywaydb.core.api.migration.JavaMigration;
import org.springframework.context.ApplicationContext;

...
ApplicationContext applicationContext = ...; // obtain a reference to Spring's ApplicationContext.

Flyway flyway = Flyway.configure()
    .dataSource(url, user, password)
    // Add all Spring-instantiated JavaMigration beans
    .javaMigrations(applicationContext.getBeansOfType(JavaMigration.class).values().toArray(new JavaMigration[0]))
    .load();
flyway.migrate();
Read more comments on GitHub >

github_iconTop Results From Across the Web

hooks - Flyway by Redgate • Database Migrations Made Easy.
The Flyway API lets you pass pre-instantiated Java-based migrations using the javaMigrations property. Spring users can use this to automatically use all ...
Read more >
Use an SQL migration file in the Flyway Java API
I created a java class and inherited from the JdbcMigrations class and the ClassPathScanner picks that up just fine. What do I need...
Read more >
Migrate on-premises Java applications to AWS using AWS ...
Remotely migrate on-premises Java based applications to the AWS Cloud using AWS App2Container with a worker machine.
Read more >
Tutorial | Building REST services with Spring
REST has quickly become the de-facto standard for building web services on the web because they're easy to build and easy to consume....
Read more >
Using Pre-Authenticated Requests - Oracle Help Center
Oracle Cloud Infrastructure Object Storage service's pre-authenticated request ... requests using the Console, CLI, or by using an SDK to access the API....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found