Skip to content

Commit 6ab2df5

Browse files
committed
Order DataSourceScriptDatabaseInitializer last
Change the order of `DataSourceScriptDatabaseInitializerDetector` so that it always runs last. This update allows script initialization to be combined with a high-level migration tool such as Flyway. Closes gh-26692
1 parent dafd511 commit 6ab2df5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/init/DataSourceScriptDatabaseInitializerDetector.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.boot.sql.init.dependency.AbstractBeansOfTypeDatabaseInitializerDetector;
2323
import org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector;
24+
import org.springframework.core.Ordered;
2425

2526
/**
2627
* A {@link DatabaseInitializerDetector} for {@link DataSourceScriptDatabaseInitializer}.
@@ -29,9 +30,16 @@
2930
*/
3031
class DataSourceScriptDatabaseInitializerDetector extends AbstractBeansOfTypeDatabaseInitializerDetector {
3132

33+
static final int PRECEDENCE = Ordered.LOWEST_PRECEDENCE - 100;
34+
3235
@Override
3336
protected Set<Class<?>> getDatabaseInitializerBeanTypes() {
3437
return Collections.singleton(DataSourceScriptDatabaseInitializer.class);
3538
}
3639

40+
@Override
41+
public int getOrder() {
42+
return PRECEDENCE;
43+
}
44+
3745
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
insert into PERSON (first_name, last_name) values ('Phillip', 'Webb');

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-flyway/src/test/java/smoketest/flyway/SampleFlywayApplicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class SampleFlywayApplicationTests {
3232

3333
@Test
3434
void testDefaultSettings() {
35-
assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON", Integer.class)).isEqualTo(1);
35+
assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON", Integer.class)).isEqualTo(2);
3636
}
3737

3838
}

0 commit comments

Comments
 (0)