title: Testcontainers: execute TC_INITSCRIPT at each test
body: <p>In a quakus project, I successfully set up testcontainers using only the following configuration:</p>
  <pre><code>%test.quarkus.datasource.driver=org.testcontainers.jdbc.ContainerDatabaseDriver
  %test.quarkus.hibernate-orm.dialect=org.hibernate.dialect.PostgreSQL9Dialect
  %test.quarkus.datasource.url=jdbc:tc:postgresql:11:///dbname?TC_INITSCRIPT=file:my-file.sql
  </code></pre>
  <p>This is amazing how easy it is.</p>
  <p>However, as I test the deletion of entities, I'd like to execute the initscript before each test, i.a. start each test with the initial DB.</p>
  <p>Any idea how to achieve it?</p>
  <p>I also tested by creating the PostgreSQLContainer from the test class in order to manage its lifecycle as I need. The problem is that the container port value is random, I need to set it in quarkus configuration but it doesn't work (it seems to be too late: &quot;Connection to 127.0.0.1:6432 refused&quot;). I did it this way:</p>
  <pre><code>@Testcontainers
  @QuarkusTest
  class MyTest {
  
    class MyPostgreSQLContainer(imageName: String) : PostgreSQLContainer&lt;MyPostgreSQLContainer&gt;(imageName)
  
    companion object {
  
      @Container
      val postgres = MyPostgreSQLContainer(&quot;postgres:11&quot;)
        .withDatabaseName(&quot;integtest&quot;)
        .withUsername(&quot;postgres&quot;)
        .withPassword(&quot;pwd&quot;)
        .withExposedPorts(5432)
  
      @BeforeAll
      @JvmStatic
      internal fun beforeAll() {
  
        postgres.start()
        System.setProperty(&quot;QUARKUS_DATASOURCE_JDBC_URL&quot;, &quot;jdbc:postgresql://127.0.0.1:${postgres.firstMappedPort}/kpi_integtest&quot;);
        println(&quot;BeforeAll init() method called&quot;)
      }
  
    }
  </code></pre>
  <p>with the application.properties config:</p>
  <pre><code>quarkus.datasource.jdbc.url=jdbc:postgresql://127.0.0.1:6432/integtest
  </code></pre>