package org.cru.godtools.domain;

import com.googlecode.flyway.core.Flyway;
import com.googlecode.flyway.core.api.MigrationVersion;
import org.cru.godtools.domain.properties.GodToolsProperties;
import org.cru.godtools.domain.properties.GodToolsPropertiesFactory;

/**
 * Created by ryancarlson on 7/18/14.
 */
public class DatabaseMigration
{
	static GodToolsProperties properties = new GodToolsPropertiesFactory().get();

	public static void main(String[] args)
	{
		new DatabaseMigration().build();
	}

	public void build()
	{
		Flyway flyway = new Flyway();
		flyway.setDataSource(properties.getProperty("databaseUrl"), properties.getProperty("databaseUsername") ,properties.getProperty("databasePassword"));
		flyway.setInitVersion("0");
		flyway.migrate();
	}
}

@@ -465,64 +465,389 @@
 %7B%0A%09%09
-new DatabaseMigration().build();%0A%09%7D%0A%0A%09public void build(
+// i chose an OR here to allow for the process to be invoked from the IDE w/o having to set CLI args.  Jenkins will always pass true or false%0A%09%09if(args.length == 0 %7C%7C doDeploy(args%5B0%5D))%0A%09%09%7B%0A%09%09%09String environmentPrefix = args.length %3E 1 ? (getEnvironmentPrefix(args%5B1%5D)) : %22%22;%0A%0A%09%09%09new DatabaseMigration().build(environmentPrefix);%0A%09%09%7D%0A%09%7D%0A%0A%09public void build(String environmentPrefix
 )%0A%09%7B
@@ -917,32 +917,52 @@
 ies.getProperty(
+environmentPrefix + 
 %22databaseUrl%22), 
@@ -960,17 +960,21 @@
 seUrl%22),
- 
+%0A%09%09%09%09
 properti
@@ -980,32 +980,52 @@
 ies.getProperty(
+environmentPrefix + 
 %22databaseUsernam
@@ -1031,10 +1031,14 @@
 me%22)
- 
 ,
+%0A%09%09%09%09
 prop
@@ -1056,16 +1056,36 @@
 roperty(
+environmentPrefix + 
 %22databas
@@ -1150,11 +1150,211 @@
 te();%0A%09%7D
+%0A%0A%09static boolean doDeploy(String commandLineArg)%0A%09%7B%0A%09%09return Boolean.parseBoolean(commandLineArg);%0A%09%7D%0A%0A%09static String getEnvironmentPrefix(String commandLineArg)%0A%09%7B%0A%09%09return  commandLineArg + %22_%22;%0A%09%7D
 %0A%7D%0A

Add logic to accept command line args to enable migration and set environment prefix