testcontainers-java icon indicating copy to clipboard operation
testcontainers-java copied to clipboard

Add r2dbc:tc TC_INITSCRIPT

Open jamesward opened this issue 2 years ago • 1 comments

Please add a way to specify a TC_INITSCRIPT with the R2DBC automagic stuff r2dbc:tc (like exists on the jdbc:tc stuff). Thanks!

jamesward avatar Nov 19 '21 22:11 jamesward

Friendly note to those who are looking for an alternative: use ResourceDatabasePopulator

@Profile("test")
@Configuration
open class TestContainerPopulationConfig(
    private val connectionFactory: ConnectionFactory
) : InitializingBean {
    override fun afterPropertiesSet() {
        runBlocking {
            val databasePopulator = ResourceDatabasePopulator()
            databasePopulator.addScripts(
                ClassPathResource("db/db-schema.sql"),
            )
            databasePopulator.populate(connectionFactory).awaitFirstOrNull()
        }
    }
}

although it would still be nice if TC_INITSCRIPT works for R2DBC anyways 😃

mscheong01 avatar Dec 02 '22 08:12 mscheong01