-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate flyway migrations from hibernate update scripts
- Loading branch information
Showing
9 changed files
with
193 additions
and
5 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...sions/agroal/spi/src/main/java/io/quarkus/agroal/spi/JdbcUpdateSQLGeneratorBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.agroal.spi; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
public final class JdbcUpdateSQLGeneratorBuildItem extends MultiBuildItem { | ||
|
||
final String databaseName; | ||
final Supplier<String> sqlSupplier; | ||
|
||
public JdbcUpdateSQLGeneratorBuildItem(String databaseName, Supplier<String> sqlSupplier) { | ||
this.databaseName = databaseName; | ||
this.sqlSupplier = sqlSupplier; | ||
} | ||
|
||
public String getDatabaseName() { | ||
return databaseName; | ||
} | ||
|
||
public Supplier<String> getSqlSupplier() { | ||
return sqlSupplier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...deployment/src/test/java/io/quarkus/flyway/test/FlywayDevModeUpdateFromHibernateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.quarkus.flyway.test; | ||
|
||
import java.util.Map; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import io.quarkus.devui.tests.DevUIJsonRPCTest; | ||
import io.quarkus.test.QuarkusDevModeTest; | ||
|
||
public class FlywayDevModeUpdateFromHibernateTest extends DevUIJsonRPCTest { | ||
|
||
public FlywayDevModeUpdateFromHibernateTest() { | ||
super("io.quarkus.quarkus-flyway"); | ||
} | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest config = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(FlywayDevModeUpdateFromHibernateTest.class, Fruit.class) | ||
.addAsResource(new StringAsset( | ||
"quarkus.flyway.migrate-at-start=true\nquarkus.flyway.locations=db/update"), "application.properties")); | ||
|
||
@Test | ||
public void testGenerateMigrationFromHibernate() throws Exception { | ||
|
||
Map<String, Object> params = Map.of("ds", "<default>"); | ||
JsonNode devuiresponse = super.executeJsonRPCMethod("update", params); | ||
|
||
Assertions.assertNotNull(devuiresponse); | ||
String type = devuiresponse.get("type").asText(); | ||
Assertions.assertNotNull(type); | ||
Assertions.assertEquals("success", type); | ||
|
||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
extensions/flyway/deployment/src/test/resources/db/update/V2.0.0__Quarkus.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CREATE TABLE fruit | ||
( | ||
id INT | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../main/java/io/quarkus/hibernate/orm/runtime/dev/HibernateOrmDevInfoUpdateDDLSupplier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.quarkus.hibernate.orm.runtime.dev; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
import io.quarkus.runtime.annotations.RecordableConstructor; | ||
|
||
public class HibernateOrmDevInfoUpdateDDLSupplier implements Supplier<String> { | ||
|
||
private final String puName; | ||
|
||
@RecordableConstructor | ||
public HibernateOrmDevInfoUpdateDDLSupplier(String puName) { | ||
this.puName = puName; | ||
} | ||
|
||
@Override | ||
public String get() { | ||
Collection<HibernateOrmDevInfo.PersistenceUnit> persistenceUnits = HibernateOrmDevController.get() | ||
.getInfo().getPersistenceUnits(); | ||
for (var p : persistenceUnits) { | ||
if (Objects.equals(puName, p.getName())) { | ||
return p.getCreateDDL(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public String getPuName() { | ||
return puName; | ||
} | ||
} |