quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.7k stars 2.66k forks source link

Supports schema creation on Liquibase #12287

Open vu-bui opened 4 years ago

vu-bui commented 4 years ago

Description I'm using PostgreSQL with multiple datasources. Each is a schema in the same database and each of them has their own Liquibase migration. I have both quarkus.hibernate-orm.database.generation.create-schemas and quarkus.liquibase.migrate-at-start enabled, but since Liquibase migration runs before the schema generation, it fails to create changelog tables. The schema generation works well with hbm2ddl, but not Liquibase. It doesn't need to be in a multi-datasources setup, some simple configuration as below would also cause the issue

quarkus.hibernate-orm.database.default-schema=myschema
quarkus.hibernate-orm.database.generation.create-schemas=true
quarkus.liquibase.default-schema-name=myschema
quarkus.liquibase.change-log=db/com/example/myschema/changelog.xml
quarkus.liquibase.migrate-at-start=true

Implementation ideas I don't know if it's a weird idea or not but should the schema generation happen before Liquibase of Flyway migration?

UPDATE I didn't know we have support for this on Flyway before, so probably just something equivalent to quarkus.flyway.create-schemas for Liquibase?

gavinking commented 4 years ago

I don't understand: if you're using Liquibase, shouldn't you be using it to manage schema migration as well as data migration?

Remember that Hibernate's schema export is something mainly intended for use in testing and development. It's not meant to be used for real data migration tasks.

vu-bui commented 4 years ago

I use Liquibase for schema migration, but not schema creation. I don't think it's possible to do that with Liquibase since it'll need to have a schema to create changelog tracking tables before running any migration.

My point is to have a way that I only have to configure the JDBC connection for the application and it would handle the rest (schema creations, migrations, etc.) Because normally, a database is created for just an application, so instead of having other people to create the database along with a bunch of schemas (PostgreSQL in my case), the application would nicely handle it.

vu-bui commented 4 years ago

By schema, I mean the schema object, not the database structure. I just found out that Flyway extension does have support for this type of scenario with quarkus.flyway.create-schemas. Can we do the same with Liquibase extension? I updated the issue title to make it clearer.

develmac commented 3 years ago

Flyway supports this and it is really a disadvantage when using Liquibase (you would have to work around it).

flo-02-mu commented 2 years ago

We are running into the exact same issue when using quarkus.hibernate-orm.multitenant=SCHEMA: The schema creation on the production DB is handled outside of liquibase and thereby is missing during local tests. Support of schema creation would be really nice.

eijckron commented 2 years ago

We are also using the hibernate multi tenant setup and some support for this in the liquibase module would be helpful. The needed functionality would be:

With some directions on a preferred implementation I can try to help out to get this included.

HerrDerb commented 2 years ago

That this feature is not implemented yet, really bugs me. I pretty much hinders me to create a dev/test setup...

eijckron commented 2 years ago

@HerrDerb The workaround we currently use is to have 1 multi tenant datasource, not linked to any liquibase configuration. Per tenant we configure an additional datasource with the tenant specific schema and min 0 and max 1 connection. Each of these tenant specific datasources is linked to a liquibase configuration. This works fine for our current set-up with 2 tenants, it will most likely be ok for a 3rd but starts to become a burden at 5 and up.

gsmet commented 2 years ago

From what I can see, it's a limitation of Liquibase itself: https://stackoverflow.com/questions/36419328/liquibase-create-schema-for-postgres .

So I don't see what we can do with it. And no, we can't run Hibernate ORM schema generation prior to Liquibase. That would entirely defeat the purpose of Liquibase.