I want to apply the initial schema using spring.sql.init on application.yml and then use r2dbc.migrate to do the migration. However, the default behavior is that R2dbcMigrateAutoConfiguration.R2dbcMigrateBlockingInvoker bean is initialized first, and then SqlR2dbcScriptDatabaseInitializer is initialized later. The call order is reversed and the application crashes.
# schema.sql
-- users
CREATE TABLE IF NOT EXISTS users (
id BIGSERIAL PRIMARY KEY,
email VARCHAR(191) UNIQUE NOT NULL,
name VARCHAR(191),
hash_salt VARCHAR(500) NOT NULL,
roles VARCHAR(16)[]
);
Caused by: io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: [42P01] relation "users" does not exist
Temp Solution
When initializing R2dbcMigrateBlockingInvoker, it tells SqlR2dbcScriptDatabaseInitializer that it needs a dependency (I don't know if this is best) so that SqlR2dbcScriptDatabaseInitializer is called first and R2dbcMigrateBlockingInvoker is called later. I also tried using @DependOn or @AutoConfigureAfter but it didn't work well.
Issue
I want to apply the initial schema using
spring.sql.init
onapplication.yml
and then user2dbc.migrate
to do the migration. However, the default behavior is thatR2dbcMigrateAutoConfiguration.R2dbcMigrateBlockingInvoker
bean is initialized first, and thenSqlR2dbcScriptDatabaseInitializer
is initialized later. The call order is reversed and the application crashes.application.yml
Temp Solution
When initializing
R2dbcMigrateBlockingInvoker
, it tellsSqlR2dbcScriptDatabaseInitializer
that it needs a dependency (I don't know if this is best) so thatSqlR2dbcScriptDatabaseInitializer
is called first andR2dbcMigrateBlockingInvoker
is called later. I also tried using@DependOn
or@AutoConfigureAfter
but it didn't work well.repository
Expect
r2dbc.migrate
andspring.sql.init
to be used together by havingSqlR2dbcScriptDatabaseInitializer
called first and thenR2dbcMigrateBlockingInvoker
.Thank you for your awesome project.