public void Execute(string fullFilename, ConnectionSettings settings, ITaskObserver taskObserver, bool logOnly = false) { string scriptFilename = getFilename(fullFilename); if (_executionTracker.ScriptAlreadyExecuted(settings, scriptFilename)) { taskObserver.Log(string.Format("Skipping (already executed): {0}{1}", getLastFolderName(fullFilename), scriptFilename)); } else { if (!logOnly) { string sql = _fileSystem.ReadTextFile(fullFilename); if (!_executor.ScriptSupportsTransactions(sql)) { taskObserver.Log(string.Format("Executing: {0}{1}", getLastFolderName(fullFilename), scriptFilename)); _executor.ExecuteNonQuery(settings, sql, true); } else { taskObserver.Log(string.Format("Executing: {0}{1} in a transaction", getLastFolderName(fullFilename), scriptFilename)); _executor.ExecuteNonQueryTransactional(settings, sql); } } else { taskObserver.Log(string.Format("Executing: {0}{1} in log only mode", getLastFolderName(fullFilename), scriptFilename)); } _executionTracker.MarkScriptAsExecuted(settings, scriptFilename, taskObserver); } }
public void CorrectlyExecutesScriptIfItHasntAlreadyBeenExecuted() { ConnectionSettings settings = getConnectionSettings(); string scriptFile = @"c:\scripts\Update\01_Test.sql"; string fileContents = "file contents..."; MockRepository mocks = new MockRepository(); IScriptExecutionTracker executionTracker = mocks.CreateMock <IScriptExecutionTracker>(); IFileSystem fileSystem = mocks.CreateMock <IFileSystem>(); IQueryExecutor queryExecutor = mocks.CreateMock <IQueryExecutor>(); ITaskObserver taskObserver = mocks.CreateMock <ITaskObserver>(); Expect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql")).Return(false); taskObserver.Log("Executing: 01_Test.sql"); Expect.Call(fileSystem.ReadTextFile(scriptFile)).Return(fileContents); queryExecutor.ExecuteNonQuery(settings, fileContents, true); executionTracker.MarkScriptAsExecuted(settings, "01_Test.sql", taskObserver); mocks.ReplayAll(); IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, queryExecutor, fileSystem); executor.Execute(scriptFile, settings, taskObserver); mocks.VerifyAll(); }
public void RunsScriptsWithTransactionalStopWordsNonTransactional() { ConnectionSettings settings = getConnectionSettings(); string scriptFile = @"c:\scripts\Update\01_Test.sql"; string fileContents = "CREATE DATABASE ..."; MockRepository mocks = new MockRepository(); IScriptExecutionTracker executionTracker = mocks.StrictMock <IScriptExecutionTracker>(); IFileSystem fileSystem = mocks.StrictMock <IFileSystem>(); IQueryExecutor queryExecutor = mocks.StrictMock <IQueryExecutor>(); ITaskObserver taskObserver = mocks.StrictMock <ITaskObserver>(); Expect.Call(executionTracker.ScriptAlreadyExecuted(settings, "01_Test.sql")).Return(false); taskObserver.Log("Executing: 01_Test.sql"); Expect.Call(fileSystem.ReadTextFile(scriptFile)).Return(fileContents); Expect.Call(queryExecutor.ScriptSupportsTransactions(fileContents)).Return(false); queryExecutor.ExecuteNonQuery(settings, fileContents, true); executionTracker.MarkScriptAsExecuted(settings, "01_Test.sql", taskObserver); mocks.ReplayAll(); IChangeScriptExecutor executor = new ChangeScriptExecutor(executionTracker, queryExecutor, fileSystem); executor.Execute(scriptFile, settings, taskObserver); mocks.VerifyAll(); }
public void Execute(string fullFilename, ConnectionSettings settings, ITaskObserver taskObserver) { string scriptFilename = getFilename(fullFilename); if (_executionTracker.ScriptAlreadyExecuted(settings, scriptFilename)) { taskObserver.Log(string.Format("Skipping (already executed): {0}", scriptFilename)); } else { taskObserver.Log(string.Format("Executing: {0}", scriptFilename)); string sql = _fileSystem.ReadTextFile(fullFilename); _executor.ExecuteNonQuery(settings, sql, true); _executionTracker.MarkScriptAsExecuted(settings, scriptFilename, taskObserver); } }