Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed to accept a url to a jar file which will contain the migratio…
…n scripts
- Loading branch information
Showing
8 changed files
with
84 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<project name="MigrationTool" default="jar-migration"> | ||
|
||
|
||
<target name="init"> | ||
<property name="deploy.folder" value="deploy"/> | ||
<mkdir dir="${deploy.folder}"/> | ||
</target> | ||
|
||
<target name="jar-migration" depends="init"> | ||
<jar basedir="./bin" destfile="${deploy.folder}/migration.jar"/> | ||
</target> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package migrations; | ||
|
||
import static com.jmigration.Migration.column; | ||
import static com.jmigration.Migration.createTable; | ||
import static com.jmigration.Migration.primaryKeyColumn; | ||
|
||
import java.sql.Types; | ||
|
||
import com.jmigration.Migration; | ||
import com.jmigration.MigrationUnit; | ||
|
||
public class Sample02 implements MigrationUnit { | ||
|
||
@Override | ||
public String version() { | ||
return "10.1 005"; | ||
} | ||
|
||
public Migration createTablePessoa() { | ||
return createTable("PESSOAS_X") | ||
.add(primaryKeyColumn("ID_PESSOA").as(Types.NUMERIC).size(6).notNull().autoIncrement("SQ_PESSOA_X")) | ||
.add(column("NM_PESSOA").as(Types.VARCHAR).size(40).notNull()) | ||
.add(column("DT_NASCIMENTO").as(Types.DATE).notNull()); | ||
} | ||
|
||
|
||
|
||
@Override | ||
public String name() { | ||
return "sample02"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
package com.jmigration; | ||
|
||
import java.io.IOException; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
|
||
import org.reflections.Reflections; | ||
import org.reflections.scanners.ResourcesScanner; | ||
import org.reflections.util.ClasspathHelper; | ||
import org.reflections.util.ConfigurationBuilder; | ||
|
||
import com.jmigration.core.MigrationConfiguration; | ||
|
||
public class RunMigration { | ||
|
||
public static void main(String[] args) throws IOException { | ||
String currentVersion = null; | ||
public static void main(String[] args) throws Exception { | ||
String migrationClass = null; | ||
if (args.length > 0) { | ||
currentVersion = args[0]; | ||
migrationClass = args[0]; | ||
} | ||
Set<String> resources = new Reflections(new ConfigurationBuilder() | ||
.addUrls(ClasspathHelper.forClassLoader()) | ||
.setScanners(new ResourcesScanner())).getResources(Pattern.compile("migration.properties")); | ||
if (resources.isEmpty()) throw new RuntimeException("The file 'migration.properties' was not found in the classpath."); | ||
Properties p = new Properties(); | ||
p.load(RunMigration.class.getResourceAsStream("/migration.properties")); | ||
p.load(RunMigration.class.getResourceAsStream(resources.iterator().next())); | ||
MigrationConfiguration config = new MigrationConfiguration(p); | ||
|
||
config.createRunner().run(currentVersion); | ||
Class<?> migrationUnitClass = Class.forName(migrationClass); | ||
MigrationUnit migrationUnit = (MigrationUnit) migrationUnitClass.newInstance(); | ||
config.createRunner().run(migrationUnit); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters