Ruby on Rails has a DB migration function by default, but Spring Boot has no choice but to install it yourself. I had a hard time introducing Flyway, a migration tool, so I'll try to put it all together.
pom.xml
<dependency>
	<groupId>org.flywaydb</groupId>
	<artifactId>flyway-core</artifactId>
</dependency>
I will write it like this in the dependency hierarchy. Since I want to use the mvn command together, I also specify the following in the plugin.
pom.xml
<build>
         <plugins>
           <plugin>
               <groupId>org.flywaydb</groupId>
               <artifactId>flyway-maven-plugin</artifactId>
               <version>6.0.8</version>
               <configuration>
                   <url>Please specify the URL of the DB?currentSchema=If the schema is specified on the DB side, specify it.</url>
                 <user>Please specify USER of DB.</user>
                 <password></password>
                 <schemas>
                     <schema>ssp_engine</schema>
                 </schemas>
                 <baselineOnMigrate>true</baselineOnMigrate>
                 <baselineVersion>1.0</baselineVersion>
                     <baselineDescription>Initial</baselineDescription>
                 <locations>classpath:/db/migration</locations>
             </configuration>
           </plugin>
         </plugins>
</build>
After that, update the project with Maven and import the jar file.
The file name is strictly determined, so please refer to this. ・ Flyway usage memo
In my case, it looks like this. The hierarchy is
-src/
  -main/
    |-java/
    |  -com/
    |    -example/
    |      -main.java
    -resources/
      -db/
        -migration/
          -V1_0__create_sequence.sql
          -V1_1__create_table.sql
          -V1_2__create_data.sql
For the contents of the file, create a sequence object, create a table, and write the contents.
In your terminal, go to the hierarchy where the target file is located and execute the following command to execute it.
mvn flyway:migrate
mvn flyway:clean
mvn flyway:info
mvn flyway:validate
mvn flyway:init
mvn flyway:repair
During development in local, after confirming CRUD with a form etc.,  mvn flyway: clean and  mvn flyway: migrate can only be used for reset purposes.
I would like to ask if there is a more effective way to use it. ..
Recommended Posts