public DirectToDbApplier( QueryExecuter queryExecuter, DatabaseSchemaVersionManager schemaVersionManager, QueryStatementSplitter splitter, IDbmsSyntax dbmsSyntax, string changeLogTableName, TextWriter infoTextWriter) { if (queryExecuter == null) throw new ArgumentNullException("queryExecuter"); if (schemaVersionManager == null) throw new ArgumentNullException("schemaVersionManager"); if (splitter == null) throw new ArgumentNullException("splitter"); if (infoTextWriter == null) throw new ArgumentNullException("infoTextWriter"); this.queryExecuter = queryExecuter; this.schemaVersionManager = schemaVersionManager; this.splitter = splitter; this.dbmsSyntax = dbmsSyntax; this.changeLogTableName = changeLogTableName; this.infoTextWriter = infoTextWriter; }
public DirectToDbApplierAccessor( QueryExecuter queryExecuter, DatabaseSchemaVersionManager schemaVersionManager, QueryStatementSplitter splitter, TextWriter infoTextWriter) : base(queryExecuter, schemaVersionManager, splitter, infoTextWriter) { }
public DirectToDbApplierAccessor( QueryExecuter queryExecuter, DatabaseSchemaVersionManager schemaVersionManager, QueryStatementSplitter splitter, IDbmsSyntax dbmsSyntax, string changeLogTableName, TextWriter infoTextWriter) : base(queryExecuter, schemaVersionManager, splitter, dbmsSyntax, changeLogTableName, infoTextWriter) { }
public DirectToDbApplier( QueryExecuter queryExecuter, DatabaseSchemaVersionManager schemaVersionManager, QueryStatementSplitter splitter, TextWriter infoTextWriter) { if (queryExecuter == null) throw new ArgumentNullException("queryExecuter"); if (schemaVersionManager == null) throw new ArgumentNullException("schemaVersionManager"); if (splitter == null) throw new ArgumentNullException("splitter"); if (infoTextWriter == null) throw new ArgumentNullException("infoTextWriter"); this.queryExecuter = queryExecuter; this.schemaVersionManager = schemaVersionManager; this.splitter = splitter; this.infoTextWriter = infoTextWriter; }
public void SetUp() { this.splitter = new QueryStatementSplitter(); }
/// <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); 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, dbmsSyntax, 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, 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 controller = new Controller( changeScriptRepository, 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(); } }