From 663d05534eae4840a6aede5f6fb101af66d88725 Mon Sep 17 00:00:00 2001 From: Gyanendra Rijal Date: Sun, 29 Apr 2018 22:37:09 +0200 Subject: [PATCH 1/4] Added optiont on include batch terminator ("GO" statements) after script batches --- ...Up.Support.SqlServer.Scripting.Console.csproj | 1 + .../Program.cs | 16 ++++++++++++++-- .../DbObjectScripter.cs | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/DbUp.Support.SqlServer.Scripting.Console/DbUp.Support.SqlServer.Scripting.Console.csproj b/DbUp.Support.SqlServer.Scripting.Console/DbUp.Support.SqlServer.Scripting.Console.csproj index 6f3d75f..e965440 100644 --- a/DbUp.Support.SqlServer.Scripting.Console/DbUp.Support.SqlServer.Scripting.Console.csproj +++ b/DbUp.Support.SqlServer.Scripting.Console/DbUp.Support.SqlServer.Scripting.Console.csproj @@ -35,6 +35,7 @@ ..\packages\dbup.3.3.5\lib\net35\DbUp.dll + diff --git a/DbUp.Support.SqlServer.Scripting.Console/Program.cs b/DbUp.Support.SqlServer.Scripting.Console/Program.cs index fba4423..caf4ace 100644 --- a/DbUp.Support.SqlServer.Scripting.Console/Program.cs +++ b/DbUp.Support.SqlServer.Scripting.Console/Program.cs @@ -5,12 +5,14 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; +using DbUp.Support.SqlServer.Scripting; +using Microsoft.SqlServer.Management.Smo; class Program { static int Main(string[] args) { - var connectionString = "Server=(localdb)\\v11.0;Integrated Security=true;AttachDbFileName=C:\\Users\\bholt\\DbUpTest.mdf;"; + var connectionString = "Server=DESKTOP-GRIJAL\\SQLDEVELOPER2017;Trusted_Connection=True;Database=DWQueue;"; var engine = DeployChanges.To @@ -19,7 +21,17 @@ static int Main(string[] args) .LogToConsole() .Build(); - ScriptingUpgrader upgradeScriptingEngine = new ScriptingUpgrader(connectionString, engine); + Options options = new Options() + { + ScriptingOptions = new ScriptingOptions() + { + ScriptBatchTerminator = true, //include 'GO' statements at the end of script batches + } + }; + + // args = new string[] { "--scriptAllDefinitions" }; + + ScriptingUpgrader upgradeScriptingEngine = new ScriptingUpgrader(connectionString, engine, options); var result = upgradeScriptingEngine.Run(args); if (!result.Successful) diff --git a/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs b/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs index e10c832..daba742 100644 --- a/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs +++ b/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs @@ -482,6 +482,11 @@ private void SaveScript(ScriptObject scriptObject, StringCollection script, stri { sb.Append(str); sb.Append(Environment.NewLine); + if (m_options.ScriptingOptions.ScriptBatchTerminator) + { + sb.Append("GO"); + sb.Append(Environment.NewLine); + } } m_log.WriteInformation(string.Format("Saving object definition: {0}", Path.Combine(outputDirectory, scriptObject.FileName))); From e1ec674ccf5a471cbf51f6eca593b2736d64891f Mon Sep 17 00:00:00 2001 From: grijal Date: Sun, 29 Apr 2018 23:04:27 +0200 Subject: [PATCH 2/4] Fork changes added --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index ba5067e..9624498 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ +# Changes in this fork: +1. Added support to follow **ScriptBatchTerminator** option so that "Go" statements are added at the end of script batches + +For example +
+ Options options = new Options()
+        {
+            ScriptingOptions = new ScriptingOptions()
+            {
+                ScriptBatchTerminator = true, //include 'GO' statements at the end of script batches
+            }
+        };
+
+        ScriptingUpgrader upgradeScriptingEngine = new ScriptingUpgrader(connectionString, engine, options);
+        var result = upgradeScriptingEngine.Run(args);
+
+ # DbUp SQL Server Object Scripting [![NuGet version](https://badge.fury.io/nu/dbup-sqlserver-scripting.svg)](https://badge.fury.io/nu/dbup-sqlserver-scripting) From 1919adad869498e0e88fe1dabaa6296d599e02de Mon Sep 17 00:00:00 2001 From: Gyanendra Date: Wed, 13 Jun 2018 09:33:41 +0200 Subject: [PATCH 3/4] include GO script batch separator in sql scripts --- DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs b/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs index e10c832..43d93d6 100644 --- a/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs +++ b/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs @@ -482,6 +482,8 @@ private void SaveScript(ScriptObject scriptObject, StringCollection script, stri { sb.Append(str); sb.Append(Environment.NewLine); + if (m_options.ScriptingOptions.ScriptBatchTerminator) + sb.Append("GO" + Environment.NewLine + Environment.NewLine); } m_log.WriteInformation(string.Format("Saving object definition: {0}", Path.Combine(outputDirectory, scriptObject.FileName))); From efe11602182b84e2f2d0f9f5b4f203b97cb8bd28 Mon Sep 17 00:00:00 2001 From: Gyanendra Date: Wed, 13 Jun 2018 15:20:55 +0200 Subject: [PATCH 4/4] Added braces for if statement --- DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs b/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs index dcb53a0..7bc90e5 100644 --- a/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs +++ b/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs @@ -484,8 +484,7 @@ private void SaveScript(ScriptObject scriptObject, StringCollection script, stri sb.Append(Environment.NewLine); if (m_options.ScriptingOptions.ScriptBatchTerminator) { - sb.Append("GO"); - sb.Append(Environment.NewLine); + sb.Append("GO" + Environment.NewLine + Environment.NewLine); } }