Database version management tool FLYWAY_ database

Source: Internet
Author: User

Flyway is a database version management tool that is independent of database application, management, and Tracking database changes.

Flyway features automatic upgrades (Autodiscover updates): Flyway upgrades any version of the database to the latest version. Flyway can be executed from the JVM environment through the command line, executed through the ant script, executed through the Maven script (this can be done automatically in the integrated environment), and can be executed in the application (for example, when the application is started). Protocol is better than configuration: Flyway a set of default specifications, so no need to modify any configuration can be used normally. supports both SQL scripts and Java code: You can use SQL scripts to perform database updates, or you can use Java code for some advanced data upgrade operations. High reliability: Database upgrades are safe and reliable in a clustered environment. Support for clearing existing library table structures: Flyway can clear the existing library table structure, build your library table structure from scratch, and manage your database version upgrade work. Support for failed fixes. The new version 2.0 provides the repair feature that resolves the failure of database update operations. How to use Flyway

With Flyway, we need to prepare the database script that Flyway will execute (flyway support SQL scripts and Java code, where the Java code that performs the database update operation under Flyway is also a database script), and then through Flyway Provides several different ways to run these scripts. (The following configuration parameter description is based on the Flyway 1.7 version, the new 2.0 version in the configuration parameters of a lot of changes, and the following introduction will be a lot of discrepancies, the following instructions for reference only) database script

The main task of Flyway is to manage the version update of the database, which in Flyway says each time the database is updated to a migration, to make it more fluently, we call it the database script below. Flyway supports sql-based migrations and java-based migrations.

Flyway supported database scripts with SQL scripts and Java code, SQL scripts that are ordinary SQL scripts, including the creation of databases, tables, update the structure of the library table, data inserts, updates, deletes and other SQL statements, Java code is through a valid data source, using Java Language for the operation of the database, where the reader is a certain degree of familiarity with the database operation of the group, no longer detailed how to write database scripts.

Flyway SQL Scripts and Java code follow the following default specification: Flyway default protocol SQL script file the default location is the Db/migration directory under the project's source folder. Java code is located in the Db.migration package by default. SQL script files and Java code class names must follow the following naming conventions: V<version>[_<seq>][__description]. The number of the version number is a decimal point (. or underscores (_) separated by a continuous two underscore (__) between the version number and the description. such as V1_1_0__update.sql. The Java class name specification does not allow decimal points, so the number of version numbers in the Java class name can only be separated by an underscore.


Currently flyway latest version 3.2.1 Link: http://flywaydb.org/documentation/commandline/

The command information is as follows:

Emptying the database (with caution, deleting all database objects, including tables/views/stored procedures ...), you can execute the following statement:

Flyway Clean

If you want to restore the latest version of the database structure, you can first empty the database, and then execute the following statement:

Flyway Migrate

If you want to restore a specific version of the database structure, you can first empty the database and then execute the following statement:

Flyway migrate-target=1.0.1.002

If you want to view current database state information, you can execute the following statement:

Flyway Info

Flyway also has commands like Validate,baseline,repair and supports MAVEN, see Flyway's website for details

You can manipulate different databases by specifying different profiles on the command line:

[deploy@iz94y8mdqg3z ~]$ flyway info-configfile=/opt/flyway/conf/flyway_test2.conf
flyway 3.2.1 by Boxfuse

Database:jdbc:mysql://localhost:3306/test2 (MySQL 5.6)

+-----------+-----------------------+---------------- -----+---------+
| Version   | Description           | Installed on        | State   |
+-----------+-----------------------+---------------------+---------+
| 1.0.0     | << flyway Baseline >> | 2015-09-28 20:29:12 | Baselin |
| 1.0.4.001 | Test Data              | 2015-09-28 20:30:33 | Success |
+-----------+-----------------------+---------------------+---------+

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.