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

Provide spring-boot-starter-liquibase-starter starter module (feature request) #662

Closed
marceloverdijk opened this issue Apr 11, 2014 · 6 comments
Labels
status: duplicate A duplicate of another issue

Comments

@marceloverdijk
Copy link

It would be nice to to have auto-configured support for running liquibase migrations.

@marceloverdijk
Copy link
Author

@marceloverdijk
Copy link
Author

What we can do is create a Liquibase auto configuration creating a SpringLiquibase bean which automatically runs migrations from e.g. classpath:/migrations/

I can work this further out via pull request if you are interested?

@marceloverdijk
Copy link
Author

What I did for now was adding the SpringLiquibase bean to my Application.java class like:

@Bean
public SpringLiquibase liquibase() {
    SpringLiquibase liquibase = new SpringLiquibase();
    liquibase.setChangeLog("classpath:/db/changelog/db.changelog-master.yaml");
    liquibase.setDataSource(dataSource);
    return liquibase;
}

Note that also the compile("org.liquibase:liquibase-core") dependency is needed.

This way during startup the database migrations (changelog) are executed automatically.

@marceloverdijk
Copy link
Author

@dsyer I have this almost implemented.

I'm only stuck at the unit tests related to the LiquibaseServiceLocatorApplicationListener which sets the Spring Boot specific SpringPackageScanClassResolver.

@Test
public void testDefaultSpringLiquibase() throws Exception {
    this.context.register(EmbeddedDataSourceConfiguration.class,
            LiquibaseAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.addApplicationListener(new LiquibaseServiceLocatorApplicationListener());
//          I'm adding the LiquibaseServiceLocatorApplicationListener above but the listener does not seem to be executed
//          The assertThat below on SpringPackageScanClassResolver fails
    this.context.refresh();
    SpringLiquibase liquibase = this.context.getBean(SpringLiquibase.class);

//      ServiceLocator.setInstance(new CustomResolverServiceLocator(
//              new SpringPackageScanClassResolver(logger)));
//          When I uncomment above lines then unit test runs succesfully

    ServiceLocator instance = ServiceLocator.getInstance();
    Field field = ReflectionUtils.findField(ServiceLocator.class, "classResolver");
    field.setAccessible(true);
    Object resolver = field.get(instance);
    assertThat(resolver, instanceOf(SpringPackageScanClassResolver.class));

    assertEquals("classpath:/db/changelog/db.changelog-master.yaml", liquibase.getChangeLog());
}

See the inline code comments. Basically I'm unable to execute the LiquibaseServiceLocatorApplicationListener in the test case.

Any idea?

@dsyer
Copy link
Member

dsyer commented Apr 16, 2014

The LiquibaseServiceLocatorApplicationListener is a listener for a Spring Boot event (ApplicationStartedEvent) and you aren't using Spring Boot (i.e. SpringApplication to start your app, so that even is never fired). Should be easy to fix?

@dsyer
Copy link
Member

dsyer commented Apr 21, 2014

Duplicates #687

@dsyer dsyer closed this as completed Apr 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants