Пример #1
0
        private void RunScript(ChangeScript script, SqlCmdExecutor sqlCmdExecutor)
        {
            this.schemaVersionManager.RecordScriptStatus(script, ScriptStatus.Started);

            this.infoTextWriter.WriteLine(script);
            this.infoTextWriter.WriteLine("----------------------------------------------------------");
            var output = new StringBuilder();

            var success = false;

            try
            {
                success = sqlCmdExecutor.ExecuteFile(script.FileInfo, output);
                if (!success)
                {
                    throw new DbDeployException(string.Format(CultureInfo.InvariantCulture, "Script '{0}' failed.", script));
                }
            }
            finally
            {
                this.infoTextWriter.WriteLine(output);
                this.schemaVersionManager.RecordScriptStatus(script, success ? ScriptStatus.Success : ScriptStatus.Failure,
                                                             output.ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Applies the specified change scripts.
        /// </summary>
        /// <param name="changeScripts">The change scripts.</param>
        public void Apply(IEnumerable <ChangeScript> changeScripts)
        {
            this.infoTextWriter.WriteLine(changeScripts.Any() ? "Applying change scripts...\n" : "No changes to apply.\n");

            using (var sqlCmdExecutor = new SqlCmdExecutor(this.connectionString))
            {
                foreach (var script in changeScripts)
                {
                    this.schemaVersionManager.RecordScriptStatus(script, ScriptStatus.Started);

                    this.infoTextWriter.WriteLine(script);
                    this.infoTextWriter.WriteLine("----------------------------------------------------------");
                    var output = new StringBuilder();

                    var success = false;
                    try
                    {
                        success = sqlCmdExecutor.ExecuteFile(script.FileInfo, output);
                        if (!success)
                        {
                            throw new DbDeployException(string.Format(CultureInfo.InvariantCulture, "Script '{0}' failed.", script));
                        }
                    }
                    finally
                    {
                        this.infoTextWriter.WriteLine(output);
                        this.schemaVersionManager.RecordScriptStatus(script, success ? ScriptStatus.Success : ScriptStatus.Failure, output.ToString());
                    }
                }
            }
        }