public ProcessChangeScripts ( UniqueChange lastChangeToApply, bool forceUpdate = false ) : void | ||
lastChangeToApply | UniqueChange | The last change to apply. |
forceUpdate | bool | if set to |
return | void |
/// <summary> /// Executes the a database deployment with the specified config. /// </summary> /// <param name="config">The config.</param> /// <param name="infoWriter">The info writer.</param> /// <exception cref="System.InvalidOperationException">SQLCMD mode can only be applied against an mssql database.</exception> public void Execute(DbDeployConfig config, TextWriter infoWriter) { this.Validate(config, infoWriter); infoWriter.WriteLine(); infoWriter.WriteLine("=========================================================="); infoWriter.WriteLine(this.GenerateWelcomeString()); var factory = new DbmsFactory(config.Dbms, config.ConnectionString); var dbmsSyntax = factory.CreateDbmsSyntax(); var queryExecuter = new QueryExecuter(factory); var databaseSchemaVersionManager = new DatabaseSchemaVersionManager(queryExecuter, dbmsSyntax, config.ChangeLogTableName, config.AutoCreateChangeLogTable); var scanner = new DirectoryScanner(infoWriter, config.Encoding); var changeScriptRepository = new ChangeScriptRepository(scanner.GetChangeScriptsForDirectory(config.ScriptDirectory)); IChangeScriptApplier doScriptApplier; TextWriter doWriter = null; QueryExecuter applierExecutor = null; if (config.OutputFile != null) { doWriter = new StreamWriter(config.OutputFile.OpenWrite(), config.Encoding); doScriptApplier = new TemplateBasedApplier( doWriter, config.Dbms, config.ChangeLogTableName, config.Delimiter, config.DelimiterType, config.TemplateDirectory); } else if (config.UseSqlCmd) { // Verify database is MSSQL. if (!string.Equals(config.Dbms, "mssql", StringComparison.InvariantCultureIgnoreCase)) { throw new InvalidOperationException("SQLCMD mode can only be applied against an mssql database."); } doScriptApplier = new SqlCmdApplier(config.ConnectionString, databaseSchemaVersionManager, infoWriter); } else { var splitter = new QueryStatementSplitter { Delimiter = config.Delimiter, DelimiterType = config.DelimiterType, LineEnding = config.LineEnding, }; // Do not share query executor between schema manager and applier, since a failure in one will effect the other. applierExecutor = new QueryExecuter(factory); doScriptApplier = new DirectToDbApplier( applierExecutor, databaseSchemaVersionManager, splitter, infoWriter); } IChangeScriptApplier undoScriptApplier = null; TextWriter undoWriter = null; if (config.UndoOutputFile != null) { undoWriter = new StreamWriter(config.UndoOutputFile.OpenWrite(), config.Encoding); undoScriptApplier = new UndoTemplateBasedApplier( undoWriter, config.Dbms, config.ChangeLogTableName, config.Delimiter, config.DelimiterType, config.TemplateDirectory); } try { var controller = new Controller( changeScriptRepository, databaseSchemaVersionManager, doScriptApplier, undoScriptApplier, infoWriter); controller.ProcessChangeScripts(config.LastChangeToApply, config.ForceUpdate); queryExecuter.Close(); if (applierExecutor != null) { applierExecutor.Close(); } } finally { if (doWriter != null) { doWriter.Dispose(); } if (undoWriter != null) { undoWriter.Dispose(); } } }
/// <summary> /// Executes the a database deployment with the specified config. /// </summary> /// <param name="config">The config.</param> /// <param name="infoWriter">The info writer.</param> /// <exception cref="System.InvalidOperationException">SQLCMD mode can only be applied against an mssql database.</exception> public void Execute(DbDeployConfig config, TextWriter infoWriter) { this.Validate(config, infoWriter); infoWriter.WriteLine(); infoWriter.WriteLine("=========================================================="); infoWriter.WriteLine(this.GenerateWelcomeString()); var factory = new DbmsFactory(config.Dbms, config.ConnectionString, config.DllPathConnector); var dbmsSyntax = factory.CreateDbmsSyntax(); var queryExecuter = new QueryExecuter(factory); var databaseSchemaVersionManager = new DatabaseSchemaVersionManager(queryExecuter, dbmsSyntax, config.ChangeLogTableName); IChangeScriptApplier doScriptApplier; TextWriter doWriter = null; QueryExecuter applierExecutor = null; if (config.OutputFile != null) { doWriter = new StreamWriter(config.OutputFile.OpenWrite(), config.Encoding); doScriptApplier = new TemplateBasedApplier( doWriter, dbmsSyntax, config.ChangeLogTableName, config.Delimiter, config.DelimiterType, config.TemplateDirectory); } else if (config.UseSqlCmd) { // Verify database is MSSQL. if (!string.Equals(config.Dbms, SupportedDbms.MSSQL, StringComparison.InvariantCultureIgnoreCase)) { throw new InvalidOperationException("SQLCMD mode can only be applied against an mssql database."); } doScriptApplier = new SqlCmdApplier( config.ConnectionString, databaseSchemaVersionManager, dbmsSyntax, config.ChangeLogTableName, infoWriter); } else { var splitter = new QueryStatementSplitter { Delimiter = config.Delimiter, DelimiterType = config.DelimiterType, LineEnding = config.LineEnding, }; // Do not share query executor between schema manager and applier, since a failure in one will effect the other. applierExecutor = new QueryExecuter(factory); doScriptApplier = new DirectToDbApplier( applierExecutor, databaseSchemaVersionManager, splitter, dbmsSyntax, config.ChangeLogTableName, infoWriter); } IChangeScriptApplier undoScriptApplier = null; TextWriter undoWriter = null; if (config.UndoOutputFile != null) { undoWriter = new StreamWriter(config.UndoOutputFile.OpenWrite(), config.Encoding); undoScriptApplier = new UndoTemplateBasedApplier( undoWriter, dbmsSyntax, config.ChangeLogTableName, config.Delimiter, config.DelimiterType, config.TemplateDirectory); } try { var changeScriptRepositoryFactory = new ChangeScriptRepositoryFactory(config, infoWriter); var changeScriptRepository = changeScriptRepositoryFactory.Obter(); var repositorioScripts = new RepositorioScripts(databaseSchemaVersionManager, changeScriptRepository); var controller = new Controller( repositorioScripts, databaseSchemaVersionManager, doScriptApplier, undoScriptApplier, config.AutoCreateChangeLogTable, infoWriter); controller.ProcessChangeScripts(config.LastChangeToApply, config.ForceUpdate); queryExecuter.Close(); if (applierExecutor != null) { applierExecutor.Close(); } } finally { if (doWriter != null) { doWriter.Dispose(); } if (undoWriter != null) { undoWriter.Dispose(); } } }
public void Go() { this.Validate(); this.InfoWriter.WriteLine(this.GenerateWelcomeString()); var factory = new DbmsFactory(this.Dbms, this.ConnectionString); var dbmsSyntax = factory.CreateDbmsSyntax(); QueryExecuter queryExecuter = new QueryExecuter(factory); var databaseSchemaVersionManager = new DatabaseSchemaVersionManager(queryExecuter, dbmsSyntax, this.ChangeLogTableName); var scanner = new DirectoryScanner(this.InfoWriter, this.Encoding); var changeScriptRepository = new ChangeScriptRepository(scanner.GetChangeScriptsForDirectory(this.ScriptDirectory)); IChangeScriptApplier doScriptApplier; TextWriter doWriter = null; if (this.OutputFile != null) { doWriter = new StreamWriter(this.OutputFile.OpenWrite(), this.Encoding); doScriptApplier = new TemplateBasedApplier( doWriter, this.Dbms, this.ChangeLogTableName, this.Delimiter, this.DelimiterType, this.TemplateDir); } else { QueryStatementSplitter splitter = new QueryStatementSplitter { Delimiter = this.Delimiter, DelimiterType = this.DelimiterType, LineEnding = this.LineEnding, }; doScriptApplier = new DirectToDbApplier( queryExecuter, databaseSchemaVersionManager, splitter, this.InfoWriter); } IChangeScriptApplier undoScriptApplier = null; TextWriter undoWriter = null; if (this.UndoOutputFile != null) { undoWriter = new StreamWriter(this.UndoOutputFile.OpenWrite(), this.Encoding); undoScriptApplier = new UndoTemplateBasedApplier( undoWriter, this.Dbms, this.ChangeLogTableName, this.Delimiter, this.DelimiterType, this.TemplateDir); } try { Controller controller = new Controller( changeScriptRepository, databaseSchemaVersionManager, doScriptApplier, undoScriptApplier, this.InfoWriter); controller.ProcessChangeScripts(this.LastChangeToApply); queryExecuter.Close(); } finally { if (doWriter != null) { doWriter.Dispose(); } if (undoWriter != null) { undoWriter.Dispose(); } } }
public void Go() { this.Validate(); this.InfoWriter.WriteLine(this.GenerateWelcomeString()); var factory = new DbmsFactory(this.Dbms, this.ConnectionString); var dbmsSyntax = factory.CreateDbmsSyntax(); QueryExecuter queryExecuter = new QueryExecuter(factory); var databaseSchemaVersionManager = new DatabaseSchemaVersionManager(queryExecuter, dbmsSyntax, this.ChangeLogTableName); var scanner = new DirectoryScanner(this.InfoWriter, this.Encoding); var changeScriptRepository = new ChangeScriptRepository(scanner.GetChangeScriptsForDirectory(this.ScriptDirectory)); IChangeScriptApplier doScriptApplier; TextWriter doWriter = null; if (this.OutputFile != null) { doWriter = new StreamWriter(this.OutputFile.OpenWrite(), this.Encoding); doScriptApplier = new TemplateBasedApplier( doWriter, this.Dbms, this.ChangeLogTableName, this.Delimiter, this.DelimiterType, this.TemplateDir); } else { QueryStatementSplitter splitter = new QueryStatementSplitter { Delimiter = this.Delimiter, DelimiterType = this.DelimiterType, LineEnding = this.LineEnding, }; doScriptApplier = new DirectToDbApplier( queryExecuter, databaseSchemaVersionManager, splitter, this.InfoWriter); } IChangeScriptApplier undoScriptApplier = null; TextWriter undoWriter = null; if (this.UndoOutputFile != null) { undoWriter = new StreamWriter(this.UndoOutputFile.OpenWrite(), this.Encoding); undoScriptApplier = new UndoTemplateBasedApplier( undoWriter, this.Dbms, this.ChangeLogTableName, this.Delimiter, this.DelimiterType, this.TemplateDir); } try { Controller controller = new Controller( changeScriptRepository, databaseSchemaVersionManager, doScriptApplier, undoScriptApplier, this.InfoWriter); controller.ProcessChangeScripts(this.LastChangeToApply); queryExecuter.Close(); } finally { if (doWriter != null) doWriter.Dispose(); if (undoWriter != null) undoWriter.Dispose(); } }