Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        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");
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
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");
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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;
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
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");
        }
Ejemplo n.º 15
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");
        }
Ejemplo n.º 16
0
        public NAntTask()
        {
            this.dbDeploy = new DbDeployer();

            this.dbDeploy.InfoWriter = Console.Out;
        }
Ejemplo n.º 17
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);
            }
        }
Ejemplo n.º 18
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;
        }
Ejemplo n.º 19
0
        public NAntTask()
        {
            this.dbDeploy = new DbDeployer();

            this.dbDeploy.InfoWriter = Console.Out;
        }
Ejemplo n.º 20
0
        public Dbdeploy()
        {
            this.dbDeploy = new DbDeployer();

            this.dbDeploy.InfoWriter = Console.Out;
        }