10/31/2016 - 12:17 PM

Spring application.yml useful snippets

Spring application.yml useful snippets

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

    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
    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