Skip to content

FlyWay migration doesn't run before the datasource or jdbctemplate is used. #8649

@olayinkasf

Description

@olayinkasf

I am using autoconfiguration with @EnableAutoConfiguration and I have a Configuration class that depends on the database schema. I find it weird that the FlyWay migration isn't executed before I am able to use the DataSource or the JdbcTemplate.

What have I done to work around this?

@Configuration
public class DatabaseConfiguration {

    private final JdbcTemplate jdbcTemplate;

    @Autowired
    public DatabaseConfiguration(JdbcTemplate jdbcTemplate, FlywayMigrationInitializer flywayMigrationInitializer) {
        this.jdbcTemplate = jdbcTemplate;
    }
}

As you can see I am not using the FlywayMigrationInitializer since I have no use for it but it does what I want but I do not like how.

This would be a lot nicer but it doesn't force the migration to run.

@Configuration
@AutoConfigureAfter(FlywayAutoConfiguration.class)
public class DatabaseConfiguration {

    private final JdbcTemplate jdbcTemplate;

    @Autowired
    public DatabaseConfiguration(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions