title: Spring Boot Test: execute different sql scripts in tests depending on the active profile?
body: <p>Is it possible with Spring Boot Test to set a conditional execution of sql scripts depending on the active profile?
  I mean, I have my integration tests for repositories annotated with some @sql annotations like:</p>
  
  <pre><code>@Sql(scripts = "/scripts/entity_test_clear.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
  </code></pre>
  
  <ul>
  <li><p>For a profile h2 I want to execute <strong>entity_test_clear.sql</strong></p></li>
  <li><p>For a profile mysql I want to execute <strong>entity_test_clear_mysql.sql</strong></p></li>
  </ul>
  
  <p>The reason for it is that I use diffrent syntax for these databases, particularly this one:</p>
  
  <ul>
  <li><code>ALTER TABLE organisation ALTER COLUMN org_id RESTART WITH 1;</code></li>
  <li><code>ALTER TABLE organisation AUTO_INCREMENT = 1;</code></li>
  </ul>
  
  <p>Mysql doesn't understand the syntax #1, while h2 doesn't understand the syntax #2 (despite the mysql mode set, like MODE=MYSQL)</p>
  
  <p>By default, I use h2 for IT tests, but also, in some rarer cases, I would like to check everything works smoothly with mysql too.</p>
  
  <p>P.S I could of course try a straight-forward solution with <code>@Profile</code> and hard code two copies of each test for h2 and mysql, but it is coupled with huge code duplication in tests, which I would like to avoid.</p>
  
  <p><strong>EDITED:</strong>
  The test case looks like this:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @DataJpaTest
  @AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE)
  public class EntityRepositoryTestIT {
  
      @Autowired
      private EntityRepository entityRepository;
  
  @Test
  @Sql(scripts = {"/scripts/entity_test_data.sql", "/scripts/entity_test_data_many.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
  @Sql(scripts = "/scripts/entity_test_clear.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
  public void findTest() {
      Page&lt;Entity&gt; e = entityRepository.findBySomeDetails(1L, PageRequest.of(0, 20));
      Assert.assertEquals(3, e.getContent().size());
      Assert.assertEquals(1, e.getContent().get(0).getResources().size());
  // more asserts
  
  }
  </code></pre>
  
  <p>Thank you for any suggestions!</p>