Execute() public method

Executes the a database deployment with the specified config.
SQLCMD mode can only be applied against an mssql database.
public Execute ( DbDeployConfig config, TextWriter infoWriter ) : void
config DbDeployConfig The config.
infoWriter System.IO.TextWriter The info writer.
return void
示例#1
0
        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");
        }
        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));
        }
示例#3
0
        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 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");
        }
示例#5
0
        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 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);
        }
        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));
        }
示例#8
0
        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");
        }
示例#9
0
        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 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");
        }
示例#11
0
        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);
            }
        }