public void Parse(string[] args, DbDeployer dbDeploy) { try { dbDeploy.ScriptDirectory = new DirectoryInfo("."); OptionSet options = this.Initialize(dbDeploy); List <string> unknown = options.Parse(args); if (unknown != null && unknown.Count != 0) { foreach (var s in unknown) { // empty "unkown" parameters are allowed if (s != null && !string.IsNullOrEmpty(s.Trim())) { throw new UsageException("Unkown parameter(s): " + string.Join(", ", unknown.ToArray())); } } } } catch (OptionException e) { throw new UsageException(e.Message, e); } }
public static void Main(string[] args) { var exitCode = 0; try { // Read arguments from command line var deploymentsConfig = OptionsManager.ParseOptions(args); var deployer = new DbDeployer(); foreach (var config in deploymentsConfig.Deployments) { deployer.Execute(config, Console.Out); } } catch (UsageException ex) { Console.Error.WriteLine("ERROR: " + ex.Message); OptionsManager.PrintUsage(); } catch (DbDeployException ex) { Console.Error.WriteLine(ex.Message); exitCode = 1; } catch (Exception ex) { Console.Error.WriteLine("Failed to apply changes: " + ex.Message); Console.Error.WriteLine(ex.StackTrace); exitCode = 2; } Environment.Exit(exitCode); }
public void DbDebployCanExecuteBothEmbeddedScriptsAndScriptsInDirectories() { var assembly = Assembly.LoadFrom("Test.Net.Sf.DbDeploy.EmbeddedScripts.dll"); using (var tw = File.CreateText("database_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + ".txt")) { var dbDeployer = new DbDeployer(); var config = new DbDeployConfig { ConnectionString = ConnectionString, Dbms = SupportedDbms.MSSQL, Delimiter = "GO", ScriptDirectory = new List<DirectoryInfo> { new DirectoryInfo(@"Mocks\Versioned\2.0.0.0") }, ScriptAssemblies = new List<Assembly> {assembly}, DelimiterType = Parser.ParseDelimiterType("row"), UseSqlCmd = false, AssemblyResourceNameFilter = resourceName => resourceName.Contains("db.MsSql.") }; dbDeployer.Execute(config, tw); } AssertTableExists(ChangeLogTableName); AssertTableExists("Product"); AssertTableExists("Customer"); }
protected override void ProcessRecord() { base.ProcessRecord(); if (string.IsNullOrEmpty(this.OutputFile)) { this.WriteError(new ErrorRecord(new PSInvalidOperationException( "Missing a file for output"), "NoOutputFile", ErrorCategory.MetadataError, null)); return; } var dbDeploy = new DbDeployer { InfoWriter = new LambdaTextWriter(WriteVerbose), Dbms = this.DatabaseType, ConnectionString = this.ConnectionString, ChangeLogTableName = this.TableName, ScriptDirectory = new DirectoryInfo(this.deltasDirectory), }; dbDeploy.OutputFile = new FileInfo(this.ToAbsolutePath(OutputFile)); if (!string.IsNullOrEmpty(this.UndoOutputFile)) { dbDeploy.OutputFile = new FileInfo(this.ToAbsolutePath(UndoOutputFile)); } dbDeploy.Go(); }
protected override void ExecuteTask() { try { var deployer = new DbDeployer(); deployer.Execute(this.config, Console.Out); } catch (UsageException ex) { Console.Error.WriteLine(ex.Message); this.PrintUsage(); } catch (DbDeployException ex) { Console.Error.WriteLine(ex.Message); throw new BuildException(ex.Message); } catch (Exception ex) { Console.Error.WriteLine("Failed to apply changes: " + ex); Console.Error.WriteLine("Stack Trace:"); Console.Error.Write(ex.StackTrace); throw new BuildException(ex.Message); } }
public void Parse(string[] args, DbDeployer dbDeploy) { try { dbDeploy.ScriptDirectory = new DirectoryInfo("."); OptionSet options = this.Initialize(dbDeploy); List<string> unknown = options.Parse(args); if (unknown != null && unknown.Count != 0) { foreach (var s in unknown) { // empty "unkown" parameters are allowed if (s != null && !string.IsNullOrEmpty(s.Trim())) throw new UsageException("Unkown parameter(s): " + string.Join(", ", unknown.ToArray())); } } } catch (OptionException e) { throw new UsageException(e.Message, e); } }
protected override void ProcessRecord() { base.ProcessRecord(); if (string.IsNullOrEmpty(this.OutputFile)) { this.WriteError(new ErrorRecord(new PSInvalidOperationException( "Missing a file for output"), "NoOutputFile", ErrorCategory.MetadataError, null)); return; } var config = new DbDeployConfig { Dbms = this.DatabaseType, ConnectionString = this.ConnectionString, ChangeLogTableName = this.TableName, ScriptDirectory = Parser.ParseDirectory(this.deltasDirectory), AutoCreateChangeLogTable = this.AutoCreateChangeLogTable, ForceUpdate = this.ForceUpdate, UseSqlCmd = this.UseSqlCmd, OutputFile = new FileInfo(this.ToAbsolutePath(this.OutputFile)) }; if (!string.IsNullOrEmpty(this.UndoOutputFile)) { config.OutputFile = new FileInfo(this.ToAbsolutePath(UndoOutputFile)); } var deployer = new DbDeployer(); deployer.Execute(config, new LambdaTextWriter(WriteVerbose)); }
public void DbDebployCanExecuteEmbeddedScripts() { var assembly = Assembly.LoadFrom("Test.Net.Sf.DbDeploy.EmbeddedScripts.dll"); using (var tw = File.CreateText("database_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + ".txt")) { var dbDeployer = new DbDeployer(); var config = new DbDeployConfig { ConnectionString = ConnectionString, Dbms = SupportedDbms.MSSQL, Delimiter = "GO", ScriptDirectory = null, ScriptAssemblies = new List <Assembly> { assembly }, DelimiterType = Parser.ParseDelimiterType("row"), UseSqlCmd = false, AssemblyResourceNameFilter = resourceName => resourceName.Contains("db.MsSql.") }; dbDeployer.Execute(config, tw); } AssertTableExists(ChangeLogTableName); AssertTableExists("Customer"); }
private OptionSet Initialize(DbDeployer dbDeploy) { OptionSet options = new OptionSet(); options .Add( "d|dbms=", "DBMS type ('mssql', 'mysql' or 'ora')", (string s) => dbDeploy.Dbms = s) .Add( "c|connectionstring=", "connection string for database", (string s) => dbDeploy.ConnectionString = StripQuotes(s)) .Add( "s|scriptdirectory=", "directory containing change scripts (default: .)", (string s) => dbDeploy.ScriptDirectory = new DirectoryInfo(StripQuotes(s))) .Add( "e|encoding=", "encoding for input and output files (default: UTF-8)", (string s) => dbDeploy.Encoding = new OutputFileEncoding(StripQuotes(s)).AsEncoding()) .Add( "o|outputfile=", "output file", (string s) => dbDeploy.OutputFile = new FileInfo(StripQuotes(s))) .Add( "templatedir=", "template directory", (string s) => dbDeploy.TemplateDir = new DirectoryInfo(StripQuotes(s))) .Add( "t|changeLogTableName=", "name of change log table to use (default: changelog)", (string s) => dbDeploy.ChangeLogTableName = StripQuotes(s)) .Add( "delimiter=", "delimiter to separate sql statements", (string s) => dbDeploy.Delimiter = s) .Add( "delimitertype=", "delimiter type to separate sql statements (row or normal)", (string s) => dbDeploy.DelimiterType = ParseDelimiterType(s)) .Add( "lineending=", "line ending to use when applying scripts direct to db (platform, cr, crlf, lf)", (string s) => dbDeploy.LineEnding = ParseLineEnding(s)); return(options); }
private OptionSet Initialize(DbDeployer dbDeploy) { OptionSet options = new OptionSet(); options .Add( "d|dbms=", "DBMS type ('mssql', 'mysql' or 'ora')", (string s) => dbDeploy.Dbms = s) .Add( "c|connectionstring=", "connection string for database", (string s) => dbDeploy.ConnectionString = StripQuotes(s)) .Add( "s|scriptdirectory=", "directory containing change scripts (default: .)", (string s) => dbDeploy.ScriptDirectory = new DirectoryInfo(StripQuotes(s))) .Add( "e|encoding=", "encoding for input and output files (default: UTF-8)", (string s) => dbDeploy.Encoding = new OutputFileEncoding(StripQuotes(s)).AsEncoding()) .Add( "o|outputfile=", "output file", (string s) => dbDeploy.OutputFile = new FileInfo(StripQuotes(s))) .Add( "templatedir=", "template directory", (string s) => dbDeploy.TemplateDir = new DirectoryInfo(StripQuotes(s))) .Add( "t|changeLogTableName=", "name of change log table to use (default: changelog)", (string s) => dbDeploy.ChangeLogTableName = StripQuotes(s)) .Add( "delimiter=", "delimiter to separate sql statements", (string s) => dbDeploy.Delimiter = s) .Add( "delimitertype=", "delimiter type to separate sql statements (row or normal)", (string s) => dbDeploy.DelimiterType = ParseDelimiterType(s)) .Add( "lineending=", "line ending to use when applying scripts direct to db (platform, cr, crlf, lf)", (string s) => dbDeploy.LineEnding = ParseLineEnding(s)); return options; }
protected override void ProcessRecord() { base.ProcessRecord(); var config = new DbDeployConfig { Dbms = DatabaseType, ConnectionString = ConnectionString, ChangeLogTableName = TableName, ScriptDirectory = Parser.ParseDirectory(deltasDirectory), }; var deployer = new DbDeployer(); deployer.Execute(config, new LambdaTextWriter(WriteVerbose)); }
protected override void ProcessRecord() { base.ProcessRecord(); var dbDeploy = new DbDeployer { InfoWriter = new LambdaTextWriter(WriteVerbose), Dbms = DatabaseType, ConnectionString = ConnectionString, ChangeLogTableName = TableName, ScriptDirectory = new DirectoryInfo(deltasDirectory), }; dbDeploy.Go(); }
public void DbDebployCanExecuteDirectoryScripts() { using (var tw = File.CreateText("database_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + ".txt")) { var dbDeployer = new DbDeployer(); var config = new DbDeployConfig { ConnectionString = ConnectionString, Dbms = SupportedDbms.MSSQL, Delimiter = "GO", ScriptDirectory = new List<DirectoryInfo> { new DirectoryInfo(@"Mocks\Versioned\2.0.0.0") }, DelimiterType = Parser.ParseDelimiterType("row"), UseSqlCmd = false }; dbDeployer.Execute(config, tw); } AssertTableExists(ChangeLogTableName); AssertTableExists("Product"); }
public void DbDebployCanExecuteDirectoryScripts() { using (var tw = File.CreateText("database_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss") + ".txt")) { var dbDeployer = new DbDeployer(); var config = new DbDeployConfig { ConnectionString = ConnectionString, Dbms = SupportedDbms.MSSQL, Delimiter = "GO", ScriptDirectory = new List <DirectoryInfo> { new DirectoryInfo(@"Mocks\Versioned\2.0.0.0") }, DelimiterType = Parser.ParseDelimiterType("row"), UseSqlCmd = false }; dbDeployer.Execute(config, tw); } AssertTableExists(ChangeLogTableName); AssertTableExists("Product"); }
public NAntTask() { this.dbDeploy = new DbDeployer(); this.dbDeploy.InfoWriter = Console.Out; }
public bool Execute() { try { var deployer = new DbDeployer(); deployer.Execute(this.config, Console.Out); return true; } catch (UsageException ex) { Console.Error.WriteLine(ex.Message); this.PrintUsage(); } catch (DbDeployException ex) { Console.Error.WriteLine(ex.Message); } catch (Exception ex) { Console.Error.WriteLine("Failed to apply changes: " + ex.Message); Console.Error.WriteLine("Stack Trace:"); Console.Error.Write(ex.StackTrace); } return false; }
public Dbdeploy() { this.dbDeploy = new DbDeployer(); this.dbDeploy.InfoWriter = Console.Out; }