introduce

Flyway is an open source database migration tool. It advocates simplicity and contract over configuration.

It is based on just seven basic commands: migration, cleanup, information, validation, Undo, baseline, and repair.

Migrations can be written using SQL (which supports database-specific syntax (such as PL/SQL, T-SQL, etc.) or Java (for advanced data transformation or processing LOBS).

It has a command line client. If you are using a JVM, it is recommended that you migrate the database using the Java API (also for Android) at application startup. Alternatively, you can use the Maven plugin or Gradle plugin.

If that’s not enough, you can use Spring Boot, Dropwizard, Grails, Play, SBT, Ant, Griffon, Grunt, Ninja and more!

Supported databases include Oracle, SQL Server (including Amazon RDS and Azure SQL Databases), Azure Synapse (formerly known as Data Warehouse), DB2, MySQL (including Amazon RDS, Azure database and Google Cloud SQL), Aurora MySQL, MariaDB, Percona XtraDB Cluster, TestContainers, PostgreSQL (including Amazon RDS, Azure Database, Google Cloud SQL and Heroku), Aurora PostgreSQL, Redshift, CockroachDB, SAP HANA, Sybase ASE, Informix, H2, HSQLDB, Derby, Snowflake, SQLite and Firebird.

coding

Project depend on

dependencies {
    // https://mvnrepository.com/artifact/org.flywaydb/flyway-core
    implementation group: 'org.flywaydb', name: 'flyway-core', version: '7.7.0'
}
Copy the code

Project configuration

  1. Create /db/migration folder in classpath and create SQL script file: