protected virtual IEnumerable<SqlScript> GetScriptsToExecute(DbInstallerMode mode) { IEnumerable<SqlScript> scriptsToExecute = new List<SqlScript>(); if (mode == DbInstallerMode.Create) { scriptsToExecute = scriptsToExecute.Concat(this.GetDropScripts()); scriptsToExecute = scriptsToExecute.Concat(this.GetCreateScripts()); scriptsToExecute = scriptsToExecute.Concat(this.GetUpgradeScripts(mode)); } else if (mode == DbInstallerMode.Upgrade) { scriptsToExecute = scriptsToExecute.Concat(this.GetUpgradeScripts(mode)); } else if (mode == DbInstallerMode.Drop) { scriptsToExecute = scriptsToExecute.Concat(this.GetDropScripts()); } return scriptsToExecute; }
protected virtual IEnumerable<SqlScript> GetUpgradeScripts(DbInstallerMode mode) { IEnumerable<SqlScript> scriptsToExecute = _scriptProviders.SelectMany(scriptProvider => scriptProvider.GetScripts()); if(mode == DbInstallerMode.Upgrade) scriptsToExecute = _journal.GetScriptsToExecute(scriptsToExecute, _databaseServerAdapter.GetConnectionFactory(_connectionString)); scriptsToExecute = _journal.OrderScripts(scriptsToExecute); return scriptsToExecute; }
/// <summary> /// Performs the database upgrade. /// </summary> public DatabaseInstallationResult Execute(DbInstallerMode mode) { IEnumerable<SqlScript> scriptsToExecute = GetScriptsToExecute(mode); #region Some Logging _logger.WriteInformation("Scripts to execute"); foreach (SqlScript script in scriptsToExecute) _logger.WriteInformation("\t" + script.Name); #endregion List<SqlScript> executedScripts = new List<SqlScript>(); try { foreach (SqlScript script in scriptsToExecute) { _databaseServerAdapter.Execute(script, _connectionString, _logger, _variables, _scriptPreProcessors); Func<IDbConnection> connectionBuilder = _databaseServerAdapter.GetConnectionFactory(_connectionString); //have the journal add an entry now that we've executed the script _journal.UpdateVersion(script, connectionBuilder, _logger); executedScripts.Add(script); } } catch (Exception ex) { return new DatabaseInstallationResult(executedScripts, false, ex); } return new DatabaseInstallationResult(executedScripts, true, null); }