diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DBMigrationEngine.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DBMigrationEngine.java index ea6f81ef78642e86980079c278682d6b6fe77c44..381f9e93d7f33126244469b33b9d9998b1b97816 100644 --- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DBMigrationEngine.java +++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/DBMigrationEngine.java @@ -215,6 +215,14 @@ public final class DBMigrationEngine private final void executeSchemaScript(final String version) { + final Script domainsScript = scriptProvider.tryGetDomainsScript(version); + if (domainsScript == null) + { + operationLog.debug("No domains script found for version " + version); + } else + { + scriptExecutor.execute(domainsScript, true, logDAO); + } final Script schemaScript = scriptProvider.tryGetSchemaScript(version); if (schemaScript == null) { @@ -231,6 +239,14 @@ public final class DBMigrationEngine { scriptExecutor.execute(functionScript, false, logDAO); } + final Script grantsScript = scriptProvider.tryGetGrantsScript(version); + if (grantsScript == null) + { + operationLog.debug("No grants script found for version " + version); + } else + { + scriptExecutor.execute(grantsScript, true, logDAO); + } } private final void fillWithInitialData(final String version) diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/ISqlScriptProvider.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/ISqlScriptProvider.java index c4eaac17c381d130b00fcf1f60168e25731e3984..44b071ee8d922abd2858cd122977162f4bfdce3f 100644 --- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/ISqlScriptProvider.java +++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/ISqlScriptProvider.java @@ -58,6 +58,26 @@ public interface ISqlScriptProvider */ public Script tryGetFunctionScript(String version); + /** + * Returns the script containing all domain definitions for the specified version. The name of + * the script is expected to be + * + * <pre> + * <schema script folder>/<version>/domains-<version>.sql + * </pre> + */ + public Script tryGetDomainsScript(final String version); + + /** + * Returns the script containing all grant declarations for the specified version. The name of + * the script is expected to be + * + * <pre> + * <schema script folder>/<version>/grants-<version>.sql + * </pre> + */ + public Script tryGetGrantsScript(final String version); + /** * Returns the script to create initial data. * diff --git a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/SqlScriptProvider.java b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/SqlScriptProvider.java index 988fca287aac1d91b48660ebf5689d88f24333b2..363dae5510a118ccf309a5045df31a70548247af 100644 --- a/dbmigration/source/java/ch/systemsx/cisd/dbmigration/SqlScriptProvider.java +++ b/dbmigration/source/java/ch/systemsx/cisd/dbmigration/SqlScriptProvider.java @@ -120,6 +120,32 @@ public class SqlScriptProvider implements ISqlScriptProvider return tryLoadScript("function-" + version + SQL_FILE_TYPE, version); } + /** + * Returns the script containing all domain definitions for the specified version. The name of + * the script is expected to be + * + * <pre> + * <schema script folder>/<version>/domains-<version>.sql + * </pre> + */ + public Script tryGetDomainsScript(final String version) + { + return tryLoadScript("domains-" + version + SQL_FILE_TYPE, version); + } + + /** + * Returns the script containing all grant declarations for the specified version. The name of + * the script is expected to be + * + * <pre> + * <schema script folder>/<version>/grants-<version>.sql + * </pre> + */ + public Script tryGetGrantsScript(final String version) + { + return tryLoadScript("grants-" + version + SQL_FILE_TYPE, version); + } + /** * Returns the data script for the specified version. The name of the script is expected to be * @@ -151,7 +177,8 @@ public class SqlScriptProvider implements ISqlScriptProvider return tryLoadScript(scriptName, scriptVersion, scriptVersion); } - private Script tryLoadScript(final String scriptName, final String scriptVersion, final String prefix) + private Script tryLoadScript(final String scriptName, final String scriptVersion, + final String prefix) { Script script = tryPrimLoadScript(specificScriptFolder + "/" + prefix, scriptName, scriptVersion); @@ -163,7 +190,8 @@ public class SqlScriptProvider implements ISqlScriptProvider return script; } - private Script tryPrimLoadScript(final String scriptFolder, final String scriptName, final String scriptVersion) + private Script tryPrimLoadScript(final String scriptFolder, final String scriptName, + final String scriptVersion) { final String scriptPath = scriptFolder + "/" + scriptName; final String resource = "/" + scriptPath; diff --git a/dbmigration/sourceTest/java/ch/systemsx/cisd/dbmigration/DBMigrationEngineTest.java b/dbmigration/sourceTest/java/ch/systemsx/cisd/dbmigration/DBMigrationEngineTest.java index 4acf1ab5f778ed403bb663b2197c413d2cfd2fcc..19c1aad3fb52f49fcc6ab447036846b8779c14df 100644 --- a/dbmigration/sourceTest/java/ch/systemsx/cisd/dbmigration/DBMigrationEngineTest.java +++ b/dbmigration/sourceTest/java/ch/systemsx/cisd/dbmigration/DBMigrationEngineTest.java @@ -106,7 +106,8 @@ public class DBMigrationEngineTest logDAO = context.mock(IDatabaseVersionLogDAO.class); scriptExecutor = context.mock(ISqlScriptExecutor.class); migrationStepExecutor = context.mock(IMigrationStepExecutor.class, "migrationStepExecutor"); - migrationStepExecutorAdmin = context.mock(IMigrationStepExecutor.class, "migrationStepExecutorAdmin"); + migrationStepExecutorAdmin = + context.mock(IMigrationStepExecutor.class, "migrationStepExecutorAdmin"); logRecorder = new BufferedAppender("%-5p %c - %m%n", Level.DEBUG); } @@ -157,8 +158,12 @@ public class DBMigrationEngineTest will(returnValue(false)); one(adminDAO).createDatabase(); + one(scriptProvider).tryGetDomainsScript(version); + expectSuccessfulExecution(new Script("domains", "domains code", version), true); one(scriptProvider).tryGetSchemaScript(version); expectSuccessfulExecution(new Script("schema", "schema code", version), true); + one(scriptProvider).tryGetGrantsScript(version); + expectSuccessfulExecution(new Script("grants", "grants code", version), true); one(scriptProvider).tryGetFunctionScript(version); expectSuccessfulExecution(new Script("function", "db function code", version), false); @@ -304,10 +309,14 @@ public class DBMigrationEngineTest one(scriptProvider).isDumpRestore(version); will(returnValue(false)); one(adminDAO).createDatabase(); + one(scriptProvider).tryGetDomainsScript(version); + expectSuccessfulExecution(new Script("domains", "domains code"), true); one(scriptProvider).tryGetSchemaScript(version); expectSuccessfulExecution(new Script("schema", "schema code"), true); one(scriptProvider).tryGetFunctionScript(version); expectSuccessfulExecution(new Script("function", "db function code"), false); + one(scriptProvider).tryGetGrantsScript(version); + expectSuccessfulExecution(new Script("grants", "grants code"), true); one(scriptProvider).tryGetDataScript(version); expectSuccessfulExecution(new Script("data", "data code"), true); one(adminDAO).getDatabaseName(); @@ -355,8 +364,11 @@ public class DBMigrationEngineTest will(returnValue(false)); one(adminDAO).createDatabase(); + one(scriptProvider).tryGetDomainsScript(version); one(scriptProvider).tryGetSchemaScript(version); expectSuccessfulExecution(new Script("schema", "schema code", version), true); + one(scriptProvider).tryGetGrantsScript(version); + expectSuccessfulExecution(new Script("domains", "domains code", version), true); one(scriptProvider).tryGetFunctionScript(version); expectSuccessfulExecution(new Script("function", "db function code", version), false); @@ -371,7 +383,8 @@ public class DBMigrationEngineTest migrationEngine.migrateTo(version); assertEquals("INFO OPERATION.DBMigrationEngine - " + "Database 'my 1. database' does not exist." + OSUtilities.LINE_SEPARATOR - + "INFO OPERATION.DBMigrationEngine - " + + "DEBUG OPERATION.DBMigrationEngine - No domains script found for version 042" + + OSUtilities.LINE_SEPARATOR + "INFO OPERATION.DBMigrationEngine - " + "Database 'my 2. database' version 042 has been successfully created.", logRecorder.getLogContent()); @@ -406,6 +419,8 @@ public class DBMigrationEngineTest one(scriptProvider).isDumpRestore(version); will(returnValue(false)); one(adminDAO).createDatabase(); + one(scriptProvider).tryGetDomainsScript(version); + expectSuccessfulExecution(new Script("domains", "domains code", version), true); one(scriptProvider).tryGetSchemaScript(version); will(returnValue(null)); } @@ -925,7 +940,7 @@ public class DBMigrationEngineTest will(returnValue(migrationStepExecutor)); one(daoFactory).getMigrationStepExecutorAdmin(); will(returnValue(migrationStepExecutorAdmin)); - + one(adminDAO).createGroups(); one(logDAO).canConnectToDatabase(); @@ -948,7 +963,7 @@ public class DBMigrationEngineTest one(migrationStepExecutorAdmin).init(script); one(migrationStepExecutorAdmin).performPreMigration(); -} + } }); final DBMigrationEngine migrationEngine = new DBMigrationEngine(daoFactory, scriptProvider, false);