title: Triggering Flyway migration before each test
body: <p>I'm implementing an integration test suite in a Spring Boot project. My project is using Flyway for database migration.</p>
  <p>My test class looks similar to this:</p>
  <pre><code>@SpringBootTest
  @AutoConfigureMockMvc
  @Testcontainers
  internal class MyIntegrationTest {
      @Container
      private val postgres = postgresContainer
  
      @Autowired
      private lateinit var mockMvc: MockMvc
  
      // ... several test cases
  }
  </code></pre>
  <p>Spring Boot runs Flyway migration at application context startup. The problem is that <code>@SpringBootTest</code> starts application context only once, so my DB is initialized only <strong>before all tests</strong> and not <strong>before each test</strong>.</p>
  <p>I also tried injecting a Flyway field in my test class:</p>
  <pre><code>@Autowired
  private lateinit var flyway: Flyway
  
  @BeforeEach
  fun setup() {
      flyway.migrate()
  }
  </code></pre>
  <p>but there is <code>No qualifying bean of type 'org.flywaydb.core.Flyway' available</code>.</p>
  <p>So, which is the right way to trigger migration before each test?</p>
  <p><strong>NOTES</strong>:</p>
  <ul>
  <li>(PostgreSQL) test container is correctly created and started for each single test.</li>
  <li>I'm using this config in application.properties: <code>spring.flyway.enabled=false</code></li>
  </ul>