Skip to content

Commit

Permalink
Add quarkus.hibernate-orm.scripts.generation.delimiter config property
Browse files Browse the repository at this point in the history
This property represents the statement delimiter used for the generation of the DDL scripts. The property defaults to `;`.

Resolves quarkusio#17514
  • Loading branch information
knutwannheden committed Jun 3, 2021
1 parent fd90966 commit 032f95e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ private static void injectRuntimeConfiguration(String persistenceUnitName,
runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_HALT_ON_ERROR, "true");
}

runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_DELIMITER,
persistenceUnitConfig.scripts.generation.delimiter);
runtimeSettingsBuilder.put(AvailableSettings.HBM2DDL_SCRIPTS_ACTION,
persistenceUnitConfig.scripts.generation.generation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public static class HibernateOrmConfigPersistenceUnitScriptGeneration {
@ConfigItem(name = ConfigItem.PARENT, defaultValue = "none")
public String generation = "none";

/**
* Specifies the statement delimiter to be used for the generated DDL scripts.
*/
@ConfigItem(defaultValue = ";")
public String delimiter;

/**
* Filename or URL where the database create DDL file should be generated.
*/
Expand All @@ -121,6 +127,7 @@ public static class HibernateOrmConfigPersistenceUnitScriptGeneration {

public boolean isAnyPropertySet() {
return !"none".equals(generation)
|| !";".equals(delimiter)
|| createTarget.isPresent()
|| dropTarget.isPresent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect
quarkus.hibernate-orm.database.generation=drop-and-create

quarkus.hibernate-orm.scripts.generation=drop-and-create
quarkus.hibernate-orm.scripts.generation.delimiter=\n/
quarkus.hibernate-orm.scripts.generation.create-target=create.sql
quarkus.hibernate-orm.scripts.generation.drop-target=drop.sql

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -33,11 +37,16 @@ public class DDLGenerationPMT {
private ProdModeTestResults prodModeTestResults;

@Test
public void test() {
public void test() throws IOException {
RestAssured.when().get("/no-paging-test").then().body(is("OK"));

assertThat(prodModeTestResults.getBuildDir().resolve("quarkus-app/create.sql").toFile()).exists();
assertThat(prodModeTestResults.getBuildDir().resolve("quarkus-app/drop.sql").toFile()).exists();
Path createSqlPath = prodModeTestResults.getBuildDir().resolve("quarkus-app/create.sql");
assertThat(createSqlPath.toFile()).exists();
assertThat(new String(Files.readAllBytes(createSqlPath))).contains("\n/");

Path dropSqlPath = prodModeTestResults.getBuildDir().resolve("quarkus-app/drop.sql");
assertThat(dropSqlPath.toFile()).exists();
assertThat(new String(Files.readAllBytes(dropSqlPath))).contains("\n/");
}

}

0 comments on commit 032f95e

Please sign in to comment.