diff --git a/docker-compose.yml b/docker-compose.yml index 6d0c70b0..6c7ed639 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,6 +26,7 @@ services: - DB_URL=jdbc:mysql://db/elide?serverTimezone=UTC - OAUTH_ENABLED=${OAUTH_ENABLED:-false} - JWKS_URL=${JWKS_URL} + - HIBERNATE_HBM2DDL_AUTO=create depends_on: db: condition: service_healthy diff --git a/docs/docs/elide/configuration.md b/docs/docs/elide/configuration.md index 4c6e0fc3..fa811af4 100644 --- a/docs/docs/elide/configuration.md +++ b/docs/docs/elide/configuration.md @@ -52,6 +52,20 @@ The following configurations can be placed in the properties file called **jpada - **DB_URL**: The persistence DB URL, such as "jdbc:mysql://localhost/elide?serverTimezone=UTC". - **DB_DRIVER**: The SQL DB driver class name, such as "com.mysql.jdbc.Driver". - **DB_DIALECT**: The SQL DB dialect name, such as "org.hibernate.dialect.MySQLDialect". +- **HIBERNATE_HBM2DDL_AUTO**: What to do with existing JPA database when webservice starts; can be one of the 4 values: + + 1. _validate_: validate that the schema matches, make no changes to the schema of the database. _This is the default + value of **HIBERNATE_HBM2DDL_AUTO**_ + 2. _update_: update the schema to reflect the entities being persisted + 3. _create_: creates the schema necessary for your entities, destroying any previous data. + 4. _create-drop_: create the schema as in create above, but also drop the schema at the end of the session. This is + great in development or for testing. + + :::note + + This property is exactly the same as [Hibernate `hibernate.hbm2ddl.auto` property]. + + ::: CI/CD ----- @@ -115,6 +129,8 @@ Note that how `my-webservice-repo-changes` is used to bridge the event dispatche [GitHub Action - How to set up]: https://docs.github.com/en/actions/security-guides/encrypted-secrets +[Hibernate `hibernate.hbm2ddl.auto` property]: https://stackoverflow.com/questions/18077327/hibernate-hbm2ddl-auto-possible-values-and-what-they-do + [Java system properties]: https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html [jersey-webservice-template-jpa-data-models]: https://github.com/QubitPi/jersey-webservice-template-jpa-data-models [jersey-webservice-template-jpa-data-models-acceptance-tests]: https://github.com/QubitPi/jersey-webservice-template-jpa-data-models-acceptance-tests diff --git a/src/main/java/com/qubitpi/ws/jersey/template/application/BinderFactory.java b/src/main/java/com/qubitpi/ws/jersey/template/application/BinderFactory.java index 616ddd56..e6aed860 100644 --- a/src/main/java/com/qubitpi/ws/jersey/template/application/BinderFactory.java +++ b/src/main/java/com/qubitpi/ws/jersey/template/application/BinderFactory.java @@ -198,7 +198,7 @@ private static Properties getDefaultDbConfigs() { final Properties dbProperties = new Properties(); dbProperties.put("hibernate.show_sql", "true"); - dbProperties.put("hibernate.hbm2ddl.auto", "update"); + dbProperties.put("hibernate.hbm2ddl.auto", JPA_DATASTORE_CONFIG.hibernateMbm2ddlAuto()); dbProperties.put("hibernate.dialect", JPA_DATASTORE_CONFIG.dbDialect()); dbProperties.put("hibernate.current_session_context_class", "thread"); dbProperties.put("hibernate.jdbc.use_scrollable_resultset", "true"); diff --git a/src/main/java/com/qubitpi/ws/jersey/template/config/JpaDatastoreConfig.java b/src/main/java/com/qubitpi/ws/jersey/template/config/JpaDatastoreConfig.java index d9c1a0f3..4a19311a 100644 --- a/src/main/java/com/qubitpi/ws/jersey/template/config/JpaDatastoreConfig.java +++ b/src/main/java/com/qubitpi/ws/jersey/template/config/JpaDatastoreConfig.java @@ -89,4 +89,27 @@ public interface JpaDatastoreConfig extends Config { @NotNull @Key("DB_DIALECT") String dbDialect(); + + + /** + * What to do with existing JPA database when webservice starts. + *
+ * Can be one of the 4 values: + *