Flyway Database Version Control

Source: Internet
Author: User

Foreword: Recently encountered a problem in the work, the project development process, the development code can be version control through SVN, but how to manage the database? Multi-personal contact with the database, when the table, field or data modified, and how to synchronize it? After the bitter find, found a call Flyway open-source project: Http://flywaydb.org/,java Writing, the official introduction is my original intention, how not to heart?

The official website is in English, looked down incredibly does not have the Chinese document, does not have the Chinese use?

Slowly read the official documents, try to do the next, a success! (Leave the computer, jump up a few, continue to sit back to the computer)

Write a little tutorial yourself.

1, put the Flyway-core-2.3.jar into the project Lib,: http://flywaydb.org/getstarted/download.html

2, in the SRC directory to establish the path to save the SQL version file: Src/db/migration,flyway default lookup path, can be changed, but not necessary.



3, add SQL file in SQL version file path, naming rules, such as: V1__2014_4_13.sql, v start + version number + Double underscore + description, the description can be underlined, suffix SQL. Don't ask if you can change this rule, or I'll bite you.

4, add Flyway Java class, has the command line tool, but still Java class to use up convenient, as follows:

Package Com.cms.flyway;import Java.io.ioexception;import Java.util.properties;import Com.googlecode.flyway.core.flyway;public class Flywayapp {//Read database configuration parameters private static Properties config = new properties ( ), static {try {Config.load (Thread.CurrentThread (). Getcontextclassloader (). getResourceAsStream (" Activerecord.properties "));} catch (IOException e) {e.printstacktrace ();}} Perform a database version upgrade public static void migration () {//Create the flyway instanceflyway flyway = new Flyway ();//point it to the D Atabaseflyway.setdatasource (Config.getproperty ("Com.et.ar.ActiveRecordBase.url"), Config.getproperty (" Com.et.ar.ActiveRecordBase.username "), Config.getproperty (" Com.et.ar.ActiveRecordBase.password ")); Flyway.setinitonmigrate (TRUE);//Start the Migrationflyway.migrate ();}}

5, when the server starts or the timer executes the migration () method of the class.

6. The first execution will generate a table dedicated to the database schema_version



7, after the new database changes, export the new version of the SQL file (such as: Mysqldump-u-P Databasename>/xx.sql) to the new version of the name of the file db.migration path, Flyway will automatically help you update the database version.

over!

Flyway Database Version Control

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.