zonkyio / embedded-database-spring-test

A library for creating isolated embedded databases for Spring-powered integration tests.
Apache License 2.0
399 stars 37 forks source link

Support for flyway.postgresql.transactional.lock #240

Closed davwil00 closed 1 year ago

davwil00 commented 1 year ago

I've seen a change in the embedded-postgres library to support flyway.postgresql.transactional.lock https://github.com/zonkyio/embedded-postgres/issues/96#issuecomment-1345670001

Is is possible to set this somewhere so that it's read? I have a FlywayMigrationStrategy configuration class which is used when the application is run but this isn't picked up in the tests

tomix26 commented 1 year ago

Hi @davwil00, thanks for letting me know. It's a bug.

I thought that io.zonky.test.db.flyway.Flyway.FlywayDescriptor was flexible enough to capture any flyway settings, but unfortunately the pluginRegister property (where the transaction lock setting is stored) is now excluded and not taken into account.

I'll try to fix it as soon as possible. It will be fixed in the next version.

davwil00 commented 1 year ago

Thank you for the fast turnaround, much appreciated.

flaviut commented 1 year ago

I don't understand any of this configuration stuff, but I've run into this issue too while using this really great tool. I've ended up being able to fix it using the following code:

import org.flywaydb.core.api.configuration.FluentConfiguration
import org.springframework.boot.autoconfigure.flyway.FlywayConfigurationCustomizer
import org.springframework.context.annotation.Configuration

@Configuration
class FlywayConfig : FlywayConfigurationCustomizer {
    override fun customize(configuration: FluentConfiguration) {
        // Disable the transactional lock in Flyway that breaks all non-transactional migrations since v9.1.2 of the plugin
        // See https://github.com/flyway/flyway/issues/3508
        configuration.configuration(
            mapOf(
                "flyway.postgresql.transactional.lock" to "false",
            )
        )
    }
}

Not sure if there's better way to do this, and this particular method I think will impact both tests & runtime configuration, but it works for me.