Skip to content

Commit

Permalink
doc: Use configuration macro for docs. (#435)
Browse files Browse the repository at this point in the history
closes #434
  • Loading branch information
wetted authored Aug 1, 2023
1 parent a21893f commit 5ceb559
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
48 changes: 32 additions & 16 deletions src/main/docs/guide/configuration/jpa.adoc
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
You can define Flyway configuration for each datasource. The following example demonstrates using it:

[source, yaml]
.src/main/resources/application.yml
[configuration]
----
include::{flywaytests}/groovy/io/micronaut/flyway/docs/FlywaySpec.groovy[tag=yamlconfig,indent=0]
datasources:
default:
url: 'jdbc:h2:mem:flywayDb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE'
username: 'sa'
password: ''
driverClassName: 'org.h2.Driver'
jpa:
default:
packages-to-scan:
- 'example.micronaut'
properties:
hibernate:
hbm2ddl:
auto: none
show_sql: true
flyway:
datasources:
default:
enabled: true
----

<1> Disable schema DDL creation.
<2> Define flyway configuration under `flyway.datasources` key.
<3> Configure flyway configuration for `default` datasource.
<4> Enable the flyway migrations for the `default` datasource.
- Disable schema DDL creation with `jpa.default.properties.hibernate.hbm2ddl.auto` set to 'none'
- Define flyway configuration under `flyway.datasources` key.
- Configure flyway configuration for `default` datasource under `datasources.default` and `jpa.default`
- Enable the flyway migrations for the `default` datasource under `flyway.datasources.default`
NOTE: You need to put the migrations in Flyway default directory `src/main/resources/db/migration`. If you want to
modify the default directory or add more, you need to set the property `flyway.datasources.default.locations`.
For example:

[source,yaml]
[configuration]
----
flyway:
datasources:
default:
enabled: true
locations:
- classpath:databasemigrations # <1>
- classpath:other # <1>
- classpath:databasemigrations
- classpath:other
----
<1> This will configure Flyway to look for migrations in the directories `src/main/resources/databasemigrations` and
`src/main/resources/other`.
- The `locations` properties configure Flyway to look for migrations in the directories `src/main/resources/databasemigrations` and `src/main/resources/other`.
Now, in the migration directory you can include your migrations:
Expand All @@ -43,15 +60,14 @@ NOTE: Starting with Micronaut `1.1.3` it is not necessary to define the `jpa` co

If you need more control to decide when the migrations are executed it is possible to configure the application like this:

[source,yaml]
[configuration]
----
flyway:
enabled: true # <1>
enabled: true
datasources:
default:
enabled: false # <2>
enabled: false
----
<1> Flyway needs to be enabled
<2> Disable flyway migrations for your specific datasource
- Enable Flyway and disable flyway migrations for your specific datasource

Now you can inject the `FlywayMigrator` bean and call manually the method `run` to execute the migrations when you want.
9 changes: 4 additions & 5 deletions src/main/docs/guide/endpoint.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ This configuration also provides a built-in endpoint to expose all the applied m

To enable the endpoint add the following to the configuration:

[source,yaml]
.resources/application.yml
[configuration]
----
endpoints:
flyway:
enabled: true # <1>
sensitive: false # <2>
enabled: true
sensitive: false
----
<1> `/flyway` endpoint is enabled (this is the default).
<2> `/flyway` endpoint is open for unauthenticated access.
- `/flyway` endpoint is enabled (this is the default) and open for unauthenticated access.
[source,bash]
----
Expand Down
8 changes: 4 additions & 4 deletions src/main/docs/guide/graalvm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ to look for migrations you need to add an additional parameter to `native-image`

For example, if you have the following configuration:

[source,yaml]
[configuration]
----
flyway:
datasources:
default:
locations:
- classpath:databasemigrations # <1>
- classpath:other # <1>
- classpath:databasemigrations
- classpath:other
----
<1> Flyway will look for migrations in `src/main/resources/databasemigrations` and `src/main/resources/other`.
- The `locations` properties configure Flyway to look for migrations in the directories `src/main/resources/databasemigrations` and `src/main/resources/other`.
You need to use the parameter `flyway.locations` with a comma separated list of directories to look for:

Expand Down

0 comments on commit 5ceb559

Please sign in to comment.