Menu

Flyway_Integration

Scott Forest Hull II Dasha
There is a newer version of this page. You can find it here.

Introduction

This is a work in progress. Once I figure out how to get the datasource out of the running jpa implementation, I will be able to configure these tools accordingly and get flyway working with the database.

Getting Started

Download and incorporate flyway jar into your product configuration. That's it.

Link to the website here: www.flywaydb.org

How to incorporate flyway into an existing database pt1

First step is to generate the (Data Definition Language) DDL files from the database. This is literally a dump of all the tables's schemas in the database and it's current configuration. Flyway will use this as a "starting point" for the database.

With a simple google, I found a way to generate this file with dblook:
http://db.apache.org/derby/docs/10.9/tools/ctoolsusingdblook.html

From flywaydb.org:
"This script will form your base migration. Save it on the classpath in the directory you configured with baseDir. Give it a relevant version number and description such as V1__Base_version.sql. "

Run a clean on the database (flyway:clean) and then run the following operation once the sql file is generated and ready to go.

mvn flyway:init -Dflyway.initialVersion=1 -Dflyway.initialDescription="Base version"

How to incorporate flyway into an existing database pt2

Once the external files are setup, the actual source code needs to be added to the application to handle migrations.
Here is some sample code below:

    Flyway flyway = new Flyway();
    flyway.setDataSource(/*Still need to be able to get this information somehow*/);
    flyway.migrate();

Step by Step guide to setup Flyway command line tool

In order to migrate an existing database into a new database, there are several files that need to be downloaded and configured before this will work.

You need the latest derby files. These can be downloaded here: http://db.apache.org/derby/derby_downloads.html
You will also need the latest flyway COMMAND line tool. This can be downloaded here: http://flywaydb.org/getstarted/download.html

First step: Setup Derby paths.

1.) Unzip the derby zip into a directory. This directory should be for library use, so for a local installation you should place it within ~/usr/local.
2.) Configure the DERBY_HOME and DERBY_INSTALL and JAVA_HOME directories. DERBY_INSTALL and DERBY_HOME should both point to the same directory for where the unzipped file is located. In this instance, we will use the example of /home/user/usr/local/db-derby-bin/. These should be exported as well.
3.) Export the CLASSPATH for the 4 derby*.jar files.

For help with steps 2, and 3, see below (please note user = username on OS):

#JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.19.x86_64/jre

#Derby Paths
DERBY_INSTALL=/home/user/usr/local/db-derby-bin/
DERBY_HOME=/home/user/usr/local/db-derby-bin/

#Exports
export JAVA_HOME
export DERBY_HOME
export DERBY_INSTALL
export CLASSPATH=$DERBY_INSTALL/lib/derby.jar:$DERBY_INSTALL/lib/derbytools.jar:$DERBY_INSTALL/lib/derbyclient.jar:$DERBY_INSTALL/lib/derbynet.jar

Restart your bash (. ~/.bashrc) as needed.

Second step: Setup Flyway command tool.

1.) Unzip the tool. This can also be done in usr/local as well.
2.) Configure the flyway.properties file. An example can be listed below (for derby):

flyway.url=jdbc:derby:/home/user/NiCEFiles/derby/database/datastructuresDatabase
flyway.user=APP
flyway.password=APP

References

Flyway: www.flywaydb.org


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.