nkonev / r2dbc-migrate

R2DBC database migration library
https://nkonev.name/post/136
Apache License 2.0
99 stars 9 forks source link

Support the ability to create a schema before creating migration tables #18

Closed aikendaniel closed 2 years ago

aikendaniel commented 2 years ago

If we are specifying a non-default schema to use and the database is empty, the migration fails because the schema does not exist. It would be great to have r2dbc-migrate create the schema that is specified via r2dbc.migrate.migrations-schema if it does not exist.

I observed this behavior when using Postgres and a Spring Boot app. I understand that I can probably use a SqlR2dbcScriptDatabaseInitializer, but I think this feature should be baked into the library instead.

nkonev commented 2 years ago

@aikendaniel I think it can be something like "premigration script", in general it can be creating database, creating user and so on.

E. g.

r2dbc.migrate.pre-migrations-script="CREATE SCHEMA IF NOT EXISTS myschema;"
aikendaniel commented 2 years ago

That works for my use case! Would pointing to a .sql file be more flexible for multi-line scripts, though?

nkonev commented 2 years ago

Would pointing to a .sql file be more flexible for multi-line scripts

Interesting suggestion, I will explore how to reuse existing mechanisms to load those scripts.

nkonev commented 2 years ago

I've pushed 1.8.6 version. It gonna be available at Maven Central after some time. TL;DR;

aikendaniel commented 2 years ago

Thank you for the quick fix! I will get it into my project.