Helidon¶
Helidon MP¶
What you need¶
Migrax comes in two parts, and most projects use both:
| Part | What it's for | How you get it |
|---|---|---|
| A tool for your terminal | Writing migrations from your entities (generate) and looking after them: status, lint, verify, rollback and the other commands |
The Maven plugin, the Gradle plugin or the migrax command-line tool |
The startup library migrax-helidon |
Applying the pending migrations each time the application starts, before JPA | A dependency: see Migrate at startup |
The tool for your terminal, pick one:
<build>
<plugins>
<plugin>
<groupId>org.migrax</groupId>
<artifactId>migrax</artifactId>
<version>0.19.0</version>
</plugin>
</plugins>
</build>
Then run mvn migrax:generate, mvn migrax:status and so on in the project folder. See
Maven plugin.
Then run ./gradlew migraxGenerate, ./gradlew migraxStatus and so on. See
Gradle plugin.
Install migrax once per machine (Installation),
then run migrax generate, migrax status and so on in the project folder. It works with
any build, and nothing is added to the project.
Only one of the two?
- Without the startup library the application doesn't migrate by itself: run
migrateyourself or in the deployment pipeline (mvn migrax:migrate,./gradlew migraxMigrate,migrax migrateor the container image). - Without a tool for your terminal there's no
generate: write the migration files yourself, and the startup library still applies them.
Command line¶
Migrax reads META-INF/microprofile-config.properties (and the mp.config.profile) together
with META-INF/persistence.xml:
javax.sql.DataSource.shop.dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
javax.sql.DataSource.shop.dataSource.url=jdbc:postgresql://localhost:5432/shop
javax.sql.DataSource.shop.dataSource.user=shop
javax.sql.DataSource.shop.dataSource.password=secret
<persistence-unit name="shop" transaction-type="JTA">
<jta-data-source>shop</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="none"/>
</properties>
</persistence-unit>
When several data sources are configured, Migrax uses the one persistence.xml names. The
jdbcUrl, username and password keys of other connection pools work too, and so do the
MicroProfile environment variables, such as JAVAX_SQL_DATASOURCE_SHOP_DATASOURCE_URL.
hibernate.* properties from persistence.xml are passed to Hibernate.
Naming: Helidon keeps Hibernate's default naming (jpa).
Migrate at startup¶
<dependency>
<groupId>org.migrax</groupId>
<artifactId>migrax-helidon</artifactId>
<version>0.19.0</version>
</dependency>
Migrations run when the application starts, before your own beans and before JPA is first used,
so hibernate.hbm2ddl.auto=validate works. Settings go in microprofile-config.properties:
| Setting | Default | Meaning |
|---|---|---|
migrax.enabled |
true |
Apply migrations at startup |
migrax.migrate-at-startup |
true |
false: start without migrating, when a pipeline or a DBA runs the migrations; the health check and the pending gauge still report them (details) |
migrax.drift.check |
off |
warn or fail: compare the database with the schema its migrations produce when the application starts; the build must put .migrax/snapshot.json into the application (details) |
migrax.datasource |
the one persistence.xml names, or the only one |
Data source to migrate |
migrax.locations |
db/migration |
Migration folders on the classpath, comma-separated |
migrax.java-package |
db.migration |
Package of JavaMigration classes |
migrax.env |
Environment: migrations marked -- migrax:env <name> run only there |
|
migrax.resume |
false |
Re-run a failed migration marked -- migrax:resume-safe |
migrax.lock-timeout |
0 |
How long to wait while another instance migrates, for example 2m when several start together |
migrax.table-lock-timeout |
5s |
How long a migration waits for a lock another session holds (PostgreSQL) before it stops; 0 for no limit (details) |
migrax.placeholders.<name> |
Values for ${name} placeholders |
|
migrax.metrics.enabled |
true |
Micrometer metrics of the migrations, when the application has a MeterRegistry (Metrics and tracing) |
migrax.tracing.enabled |
true |
OpenTelemetry spans of the migrations, when the application has an OpenTelemetry |
migrax.schemas |
Schemas to migrate one after another |
Readiness check¶
With helidon-microprofile-health in the application, Migrax adds a migrax readiness check:
UP when every migration is applied and none failed, was edited or is missing, DOWN otherwise,
with the counts as data (/health/ready).
Helidon SE¶
Helidon SE uses its database client rather than JPA, so there are no entities to generate
migrations from. Write migrations with migrax new and apply them with migrax migrate in your
deployment (SQL migrations for any language explains
this setup). Migrax reads the connection from application.yaml: