Skip to content

Instantly share code, notes, and snippets.

@salex89
Last active March 3, 2023 08:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save salex89/5a8295c93f254841405f7be1b41375a0 to your computer and use it in GitHub Desktop.
Save salex89/5a8295c93f254841405f7be1b41375a0 to your computer and use it in GitHub Desktop.
Spring application.yml useful snippets
spring:
datasource:
url: jdbc:h2:./repository/db;MV_STORE=FALSE # MV_STORE=FALSE to use the old 1.3 format
driver-class-name: org.h2.Driver
username: sa
# password: sa
jpa:
hibernate.ddl-auto: validate
# Lines dedicated only to generating the script file, it is not applied to the DB. These are from JPA, not from Hibernate
properties.javax.persistence.schema-generation.create-source: metadata
properties.javax.persistence.schema-generation.scripts.action: create
properties.javax.persistence.schema-generation.scripts.create-target: create.sql

Use if the DDL is needed as an exported file. This will work even if hibernate.ddl-auto is set to validate or other state which will not modify the database. Usefull to generate data migrations for tools like Flyway.

Settings for Create and Delete Source Properties (properties.javax.persistence.schema-generation.create-source)

metadata - Use the object/relational metadata in the application to create or delete the database artifacts.

script - Use a provided script for creating or deleting the database artifacts. 

metadata-then-script - Use a combination of object/relational metadata, then a user-provided script to create or delete the database artifacts.

script-then-metadata - Use a combination of a user-provided script, then the object/relational metadata to create and delete the database artifacts.

Schema Creation Actions (properties.javax.persistence.schema-generation.scripts.action)

none - No schema creation or deletion will take place.

create - The provider will create the database artifacts on application deployment. The artifacts will remain unchanged after application redeployment.

drop-and-create - Any artifacts in the database will be deleted, and the provider will create the database artifacts on deployment.

drop - Any artifacts in the database will be deleted on application deployment.

Create script location: properties.javax.persistence.schema-generation.scripts.create-target: create.sql

Drop script location: properties.javax.persistence.schema-generation.scripts.drop-target: drop.sql

@jahan-paisley
Copy link

Thanks a lot, mate for sharing this gist 🥇 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment