[Java] DB migration (Flyway)

Use Flyway, a DB migration (schema management) library. It is used for the following purposes. -Manage information about DB definitions and their changes in one place. -Automatically reproduce the latest DB status based on that information.

Settings for using Flyway in Maven project

pom.xml


<dependency>
  <groupId>org.flywaydb</groupId>
  <artifactId>flyway-core</artifactId>
</dependency>

Modify SpringBoot configuration file (application.yml)

By default, Spring Boot runs automatically when the flyway starts.

python


flyway:
  baseline-on-migrate: true
  baselineVersionAsString: 0.0.0
  baseline-description: Initial

Added table definition file

Add the sql file to the following folder. src/main/resources/db/migration/

・ Migration file SQL file that describes the changes to be applied to the managed schema Create according to the following rules. V{version}__{description}.sql

Example) V0_0_1__createTable.sql

・ Repeatable migration file Used when you want to migrate objects such as views, procedures, and functions. Create according to the following rules. R__{description}.sql

Example) R__createView.sql

Official site

https://flywaydb.org/

Recommended Posts

[Java] DB migration (Flyway)
Migration from Cobol to JAVA
Try DB connection with Java
Write flyway callbacks in Java
Connect to DB with Java
Spring with Kotorin --9 Database migration --Flyway
Java
Java
ERRORCODE = -4471 occurs in Java application using Db2.
[Java] Connection with local DB (IntelliJ + SpringBoot)
[Note] Cooperation between Java and DB (basic)
[Java] Let's make a DB access library!
Memo for migration from java to kotlin