Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing the schema-generation.scripts properties in the application.properties #14771

Closed
agoncal opened this issue Feb 2, 2021 · 5 comments · Fixed by #16483
Closed

Exposing the schema-generation.scripts properties in the application.properties #14771

agoncal opened this issue Feb 2, 2021 · 5 comments · Fixed by #16483
Labels
area/hibernate-orm Hibernate ORM good first issue Good for newcomers kind/enhancement New feature or request
Milestone

Comments

@agoncal
Copy link
Contributor

agoncal commented Feb 2, 2021

Description

This follows a discussion on Zulip[1].

To generate the DDL for JPA and/or Panache entities, I can use the schema-generation.scripts properties in the persistence.xml file as follow:

<property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.scripts.create-target" value="create.ddl"/
<property name="javax.persistence.schema-generation.scripts.drop-target" value="drop.ddl"/>

This works well, but I am trying to avoid using the persistence.xml and only use the application.properties instead. I couldn't find these properties in the Quarkus documentation, so I tried several formats but none work:

javax.persistence.schema-generation.scripts.action=drop-and-create
quarkus.javax.persistence.schema-generation.scripts.action=drop-and-create
quarkus.hibernate-orm.schema-generation.scripts.action=drop-and-create

It looks like these properties are not exposed. It would be very nice to have them so we can get the DDL files without having the persistence.xml.

[1] https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/Any.20way.20to.20have.20a.20scripts.2Ecreate-target.20property.20.3F

@agoncal agoncal added the kind/enhancement New feature or request label Feb 2, 2021
@ghost ghost added the triage/needs-triage label Feb 2, 2021
@Sanne
Copy link
Member

Sanne commented Feb 2, 2021

something different than the existing quarkus.hibernate-orm.database.generation ?

@Sanne Sanne added the area/hibernate-orm Hibernate ORM label Feb 2, 2021
@agoncal
Copy link
Contributor Author

agoncal commented Feb 2, 2021

The quarkus.hibernate-orm.database.generation is equivalent to the standard JPA javax.persistence.schema-generation.database.action property. It has an impact on the schema generated in the database (none, create, drop-and-create, drop).

The javax.persistence.schema-generation.scripts.action property (came later, I think in JPA 2.1) is about the schema definition. This property generates the DDL scripts, but does not generate the schema itself.

In fact, in JPA, you can have both properties to generate the database schema as well as the DDL script.

https://thorben-janssen.com/standardized-schema-generation-data-loading-jpa-2-1/

@Sanne
Copy link
Member

Sanne commented Feb 2, 2021 via email

@agoncal
Copy link
Contributor Author

agoncal commented Feb 3, 2021

As you know, there are several strategies when mapping objects to a DB. Existing DB, starting from scratch, entities first, DB first.... So I'm not sure generating the DDL out of the entities should be the default in dev mode. Would that mean that these values would be the default ?

javax.persistence.schema-generation.scripts.action=drop-and-create
javax.persistence.schema-generation.scripts.create-target=create.sql
javax.persistence.schema-generation.scripts.drop-target="drop.sql

Because in JPA, the default is none:

javax.persistence.schema-generation.scripts.action=none
javax.persistence.schema-generation.database.action=none

So, TBH, I prefer the good old JPA way (no DB schema generation, no DDL generation, and you have to change the values if needed). So, if you want to be consistent with the existing Quarkus properties, maybe something like:

quarkus.hibernate-orm.database.generation=none | create | drop-and-create | drop
quarkus.hibernate-orm.scripts.generation=none | create | drop-and-create | drop
quarkus.hibernate-orm.scripts.generation.create-target=create.sql | <my create file>.sql
quarkus.hibernate-orm.scripts.generation.drop-target=drop.sql | <my drop file>.sql 

Today, to get my DDL I need a persistence.xml (which is sad ;o). And to ease the DDL generation without starting Quarkus, I use this trick, using the JPA API:

public class GenerateDDL {

  public static void main(String[] args) {
    Persistence.generateSchema("<name of the persistence unit>", null);
    System.exit(0);
  }
}

@gsmet gsmet added good first issue Good for newcomers and removed triage/needs-triage labels Feb 4, 2021
@TomasHofman
Copy link
Contributor

I'm going to take a look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM good first issue Good for newcomers kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants