Skip to content
Snippets Groups Projects
Commit a17d7259 authored by brinn's avatar brinn
Browse files

add: support for function_migration scripts

SVN: 13459
parent 7c7370e8
No related branches found
No related tags found
No related merge requests found
......@@ -264,6 +264,8 @@ public final class DBMigrationEngine
do
{
final String nextVersion = increment(version);
final Script functionMigrationScriptOrNull =
scriptProvider.tryGetFunctionMigrationScript(version, nextVersion);
final Script migrationScript =
scriptProvider.tryGetMigrationScript(version, nextVersion);
if (migrationScript == null)
......@@ -281,6 +283,10 @@ public final class DBMigrationEngine
migrationStepExecutorAdmin.performPreMigration();
migrationStepExecutor.performPreMigration();
scriptExecutor.execute(migrationScript, true, logDAO);
if (functionMigrationScriptOrNull != null)
{
scriptExecutor.execute(functionMigrationScriptOrNull, false, logDAO);
}
migrationStepExecutor.performPostMigration();
migrationStepExecutorAdmin.performPostMigration();
migrationStepExecutor.finish();
......
......@@ -28,9 +28,9 @@ import ch.systemsx.cisd.common.Script;
public interface ISqlScriptProvider
{
/**
* Returns <code>true</code> if this script provider is suitable for a dump restore of the
* given <var>version</var> of the database, and <code>false</code>, if it is suitable for a
* regular setup.
* Returns <code>true</code> if this script provider is suitable for a dump restore of the given
* <var>version</var> of the database, and <code>false</code>, if it is suitable for a regular
* setup.
*/
public boolean isDumpRestore(String version);
......@@ -77,7 +77,7 @@ public interface ISqlScriptProvider
* </pre>
*/
public Script tryGetGrantsScript(final String version);
/**
* Returns the script to create initial data.
*
......@@ -95,4 +95,14 @@ public interface ISqlScriptProvider
*/
public Script tryGetMigrationScript(String fromVersion, String toVersion);
/**
* Returns the function migration script for migrating a database. The function migration will
* always be called <i>after</i> the regular migration script.
*
* @param fromVersion The version of the current database.
* @param toVersion The version of the database after migration.
* @return <code>null</code> if there isn't such a migration script.
*/
public Script tryGetFunctionMigrationScript(String fromVersion, String toVersion);
}
......@@ -172,6 +172,23 @@ public class SqlScriptProvider implements ISqlScriptProvider
return tryLoadScript(scriptName, toVersion, "migration");
}
/**
* Returns the function migration script for the specified versions. The name of the script is
* expected to be
*
* <pre>
* &lt;schema script folder&gt;/migration/function_migration-&lt;fromVersion&gt;-&lt;toVersion&gt;.sql
* </pre>
*
* The function migration will always be called <i>after</i> the regular migration script.
*/
public Script tryGetFunctionMigrationScript(final String fromVersion, final String toVersion)
{
final String scriptName =
"function_migration-" + fromVersion + "-" + toVersion + SQL_FILE_TYPE;
return tryLoadScript(scriptName, toVersion, "migration");
}
private Script tryLoadScript(final String scriptName, final String scriptVersion)
{
return tryLoadScript(scriptName, scriptVersion, scriptVersion);
......
......@@ -521,10 +521,12 @@ public class DBMigrationEngineTest
one(scriptProvider).tryGetMigrationScript(fromVersion, "100");
final Script script = new Script("m-099-100", "code 099 100", toVersion);
expectSuccessfulScriptExecutionWithMigrationSteps(script, true);
one(scriptProvider).tryGetFunctionMigrationScript(fromVersion, "100");
one(scriptProvider).tryGetMigrationScript("100", toVersion);
expectSuccessfulScriptExecutionWithMigrationSteps(new Script("m-100-101",
"code 100 101", toVersion), true);
one(scriptProvider).tryGetFunctionMigrationScript("100", toVersion);
one(adminDAO).getDatabaseName();
will(returnValue("my 2. database"));
......@@ -582,8 +584,8 @@ public class DBMigrationEngineTest
will(returnValue("my 1. database"));
one(scriptProvider).tryGetMigrationScript(fromVersion, "100");
final Script script = new Script("m-099-100", "code 099 100", toVersion);
will(returnValue(script));
one(scriptProvider).tryGetFunctionMigrationScript(fromVersion, "100");
one(migrationStepExecutorAdmin).init(script);
one(migrationStepExecutorAdmin).performPreMigration();
......@@ -645,6 +647,7 @@ public class DBMigrationEngineTest
one(scriptProvider).tryGetMigrationScript(fromVersion, "100");
final Script script = new Script("m-099-100", "code 099 100", toVersion);
will(returnValue(script));
one(scriptProvider).tryGetFunctionMigrationScript(fromVersion, "100");
one(migrationStepExecutorAdmin).init(script);
one(migrationStepExecutorAdmin).performPreMigration();
......@@ -703,6 +706,7 @@ public class DBMigrationEngineTest
one(adminDAO).getDatabaseName();
will(returnValue("my 1. database"));
one(scriptProvider).tryGetMigrationScript(fromVersion, "100");
one(scriptProvider).tryGetFunctionMigrationScript(fromVersion, "100");
one(adminDAO).getDatabaseName();
will(returnValue("my 2. database"));
}
......@@ -955,6 +959,7 @@ public class DBMigrationEngineTest
one(scriptProvider).tryGetMigrationScript(fromVersion, toVersion);
final Script script = new Script("m-1-2", "code", toVersion);
will(returnValue(script));
one(scriptProvider).tryGetFunctionMigrationScript(fromVersion, toVersion);
one(migrationStepExecutor).init(script);
one(migrationStepExecutor).performPreMigration();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment