Flyway is used by this project for database migrations. Flyway is able to generate migration scripts (via JPA buddy) and Spring will automatically apply the changes to the database (if Flyway is enabled).
This project is configured to apply any pending migrations automatically when the application is started. If you want to manually apply migrations (https://flywaydb.org/documentation/getstarted/firststeps/commandline), auto-apply can be disabled in the Anchor Platform Configuration:
spring.flyway.enabled: false
We usually generate the migrations using IntelliJ IDEA's JPA Buddy plugin. If you don't have it installed yet, please go ahead and download it at https://plugins.jetbrains.com/plugin/15075-jpa-buddy.
There's also an option to generate the migration from command-line or even manually, but we won't be covering that in this tutorial.
Flyway migration generator tool will need to compare your current database state with the project database entities, in order to be able to generate a diff that can bring your database to the desired state mapped in the code.
To connect a database, go to JPA Structure -> DB connections -> right click new
-> DB connection
-
When data models or table names are changed, a new changelog can be generated. New(+) -> Diff Versioned Migration:
-
Select the DB connection to create a "diff" against
-
Review the changes and generate the migration file.
Note: The migration file format =
<Prefix><Version>__<Description>.sql
Note:
Directory
should be set toplatform/src/main/resources/db/migration/
so all the changelog files are in one place.