diff --git a/DbUp.Support.SqlServer.Scripting.Console/App.config b/DbUp.Support.SqlServer.Scripting.Console/App.config
deleted file mode 100644
index 1c6ee83..0000000
--- a/DbUp.Support.SqlServer.Scripting.Console/App.config
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
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 498a1df..9904fd9 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
@@ -1,76 +1,22 @@
-
-
-
+
+
- Debug
- AnyCPU
- {80136911-3220-460B-867D-E1C94E241248}
Exe
- Properties
- DbUp.Support.SqlServer.Scripting.Console
- DbUp.Support.SqlServer.Scripting.Console
- v4.5
- 512
+ net9.0
+ enable
+ enable
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ../packages/dbup-core.4.1.0/lib/net45/dbup-core.dll
- True
-
-
- ../packages/dbup-sqlserver.4.1.0/lib/net35/dbup-sqlserver.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
- {a1ec7074-3c1d-4424-bc80-8bf770758774}
- DbUp.Support.SqlServer.Scripting
-
+
+
-
-
-
\ No newline at end of file
+
+
diff --git a/DbUp.Support.SqlServer.Scripting.Console/Program.cs b/DbUp.Support.SqlServer.Scripting.Console/Program.cs
index fba4423..ae47e5a 100644
--- a/DbUp.Support.SqlServer.Scripting.Console/Program.cs
+++ b/DbUp.Support.SqlServer.Scripting.Console/Program.cs
@@ -1,38 +1,30 @@
-using DbUp;
-using System;
-using System.Collections.Generic;
-using System.Linq;
+// See https://aka.ms/new-console-template for more information
+
using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
+using DbUp;
-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=(localdb)\\v11.0;Integrated Security=true;AttachDbFileName=C:\\Users\\bholt\\DbUpTest.mdf;";
- var engine =
- DeployChanges.To
- .SqlDatabase(connectionString)
- .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
- .LogToConsole()
- .Build();
+var engine =
+ DeployChanges.To
+ .SqlDatabase(connectionString)
+ .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
+ .LogToConsole()
+ .Build();
- ScriptingUpgrader upgradeScriptingEngine = new ScriptingUpgrader(connectionString, engine);
- var result = upgradeScriptingEngine.Run(args);
+ScriptingUpgrader upgradeScriptingEngine = new ScriptingUpgrader(connectionString, engine);
+var result = upgradeScriptingEngine.Run(args);
- if (!result.Successful)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(result.Error);
- Console.ResetColor();
- return -1;
- }
+if (!result.Successful)
+{
+ Console.ForegroundColor = ConsoleColor.Red;
+ Console.WriteLine(result.Error);
+ Console.ResetColor();
+ return -1;
+}
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Success!");
- Console.ResetColor();
- return 0;
- }
-}
\ No newline at end of file
+Console.ForegroundColor = ConsoleColor.Green;
+Console.WriteLine("Success!");
+Console.ResetColor();
+return 0;
\ No newline at end of file
diff --git a/DbUp.Support.SqlServer.Scripting.Console/Properties/AssemblyInfo.cs b/DbUp.Support.SqlServer.Scripting.Console/Properties/AssemblyInfo.cs
deleted file mode 100644
index 9ee54c7..0000000
--- a/DbUp.Support.SqlServer.Scripting.Console/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("DbUp.Support.SqlServer.Scripting.Console")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
-[assembly: AssemblyProduct("DbUp.Support.SqlServer.Scripting.Console")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("417fce9f-c246-4230-991d-77a46d7a634f")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/DbUp.Support.SqlServer.Scripting.Console/packages.config b/DbUp.Support.SqlServer.Scripting.Console/packages.config
deleted file mode 100644
index ee0b66c..0000000
--- a/DbUp.Support.SqlServer.Scripting.Console/packages.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/DbUp.Support.SqlServer.Scripting.sln b/DbUp.Support.SqlServer.Scripting.sln
index d4edfca..83a2d67 100644
--- a/DbUp.Support.SqlServer.Scripting.sln
+++ b/DbUp.Support.SqlServer.Scripting.sln
@@ -1,12 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
+# Visual Studio Version 17
+VisualStudioVersion = 17.13.35931.197 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbUp.Support.SqlServer.Scripting", "DbUp.Support.SqlServer.Scripting\DbUp.Support.SqlServer.Scripting.csproj", "{A1EC7074-3C1D-4424-BC80-8BF770758774}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbUp.Support.SqlServer.Scripting.Console", "DbUp.Support.SqlServer.Scripting.Console\DbUp.Support.SqlServer.Scripting.Console.csproj", "{80136911-3220-460B-867D-E1C94E241248}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{36C31DC9-4037-4B0B-B205-F9B9655C9232}"
ProjectSection(SolutionItems) = preProject
build\tools\dbup-sqlserver-scripting.psm1 = build\tools\dbup-sqlserver-scripting.psm1
@@ -22,22 +18,29 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{41BE4E
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbUp.Support.SqlServer.Scripting", "DbUp.Support.SqlServer.Scripting\DbUp.Support.SqlServer.Scripting.csproj", "{1D0FA2E6-BE06-44E9-A0DB-A625EC86FF72}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbUp.Support.SqlServer.Scripting.Console", "DbUp.Support.SqlServer.Scripting.Console\DbUp.Support.SqlServer.Scripting.Console.csproj", "{25A768D1-EA1B-4FA4-8E5A-A10DA90C8859}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {A1EC7074-3C1D-4424-BC80-8BF770758774}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A1EC7074-3C1D-4424-BC80-8BF770758774}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A1EC7074-3C1D-4424-BC80-8BF770758774}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A1EC7074-3C1D-4424-BC80-8BF770758774}.Release|Any CPU.Build.0 = Release|Any CPU
- {80136911-3220-460B-867D-E1C94E241248}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {80136911-3220-460B-867D-E1C94E241248}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {80136911-3220-460B-867D-E1C94E241248}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {80136911-3220-460B-867D-E1C94E241248}.Release|Any CPU.Build.0 = Release|Any CPU
+ {1D0FA2E6-BE06-44E9-A0DB-A625EC86FF72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {1D0FA2E6-BE06-44E9-A0DB-A625EC86FF72}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {1D0FA2E6-BE06-44E9-A0DB-A625EC86FF72}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {1D0FA2E6-BE06-44E9-A0DB-A625EC86FF72}.Release|Any CPU.Build.0 = Release|Any CPU
+ {25A768D1-EA1B-4FA4-8E5A-A10DA90C8859}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {25A768D1-EA1B-4FA4-8E5A-A10DA90C8859}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {25A768D1-EA1B-4FA4-8E5A-A10DA90C8859}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {25A768D1-EA1B-4FA4-8E5A-A10DA90C8859}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {45B4DB37-C09B-4085-9F47-7BB05CCC22C2}
+ EndGlobalSection
EndGlobal
diff --git a/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs b/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs
index 29e3d2b..50297ad 100644
--- a/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs
+++ b/DbUp.Support.SqlServer.Scripting/DbObjectScripter.cs
@@ -2,684 +2,803 @@
using DbUp.Engine.Output;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
-using System;
-using System.Collections.Generic;
using System.Collections.Specialized;
-using System.Configuration;
-using System.Data.SqlClient;
-using System.IO;
-using System.Linq;
using System.Reflection;
-using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Text.RegularExpressions;
-using System.Threading.Tasks;
+using Microsoft.Data.SqlClient;
-namespace DbUp.Support.SqlServer.Scripting
+namespace DbUp.Support.SqlServer.Scripting;
+
+public class DbObjectScripter
{
- public class DbObjectScripter
+ private const string SCRIPTING_OBJECT_REGEX =
+ @"((CREATE|ALTER|DROP|CREATE\s*OR\s*ALTER)\s*(TABLE|VIEW|PROCEDURE|PROC|FUNCTION|SYNONYM|TYPE|TRIGGER|)\s*(IF?\s*EXISTS? | \s*)\s*([\w\[\]\-]+)?\.?([\w\[\]\-]*))|(sp_rename{1,1}\s*'([\w\[\]\-]+)?\.?([\w\[\]\-]*)'\s*,\s*'([\w\[\]\-]*)')";
+
+ private const int REGEX_INDEX_ACTION_TYPE = 2;
+ private const int REGEX_INDEX_OBJECT_TYPE = 3;
+ private const int REGEX_INDEX_SCHEMA_NAME = 5;
+ private const int REGEX_INDEX_OBJECT_NAME = 6;
+ private const int REGEX_INDEX_OBJECT_RENAME_SCHEMA = 8;
+ private const int REGEX_INDEX_OBJECT_RENAME_OLD_NAME = 9;
+ private const int REGEX_INDEX_OBJECT_RENAME_NEW_NAME = 10;
+
+ private readonly Regex m_targetDbObjectRegex = new Regex(SCRIPTING_OBJECT_REGEX,
+ RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
+
+ private Options m_options;
+ private string m_definitionDirectory;
+ private SqlConnectionStringBuilder m_connectionBuilder;
+ private IUpgradeLog m_log;
+
+ public DbObjectScripter(
+ string connectionString,
+ Options options,
+ IUpgradeLog log
+ )
{
- private const string SCRIPTING_OBJECT_REGEX = @"((CREATE|ALTER|DROP|CREATE\s*OR\s*ALTER)\s*(TABLE|VIEW|PROCEDURE|PROC|FUNCTION|SYNONYM|TYPE|TRIGGER|)\s*(IF?\s*EXISTS? | \s*)\s*([\w\[\]\-]+)?\.?([\w\[\]\-]*))|(sp_rename{1,1}\s*'([\w\[\]\-]+)?\.?([\w\[\]\-]*)'\s*,\s*'([\w\[\]\-]*)')";
- private const int REGEX_INDEX_ACTION_TYPE = 2;
- private const int REGEX_INDEX_OBJECT_TYPE = 3;
- private const int REGEX_INDEX_SCHEMA_NAME = 5;
- private const int REGEX_INDEX_OBJECT_NAME = 6;
- private const int REGEX_INDEX_OBJECT_RENAME_SCHEMA = 8;
- private const int REGEX_INDEX_OBJECT_RENAME_OLD_NAME = 9;
- private const int REGEX_INDEX_OBJECT_RENAME_NEW_NAME = 10;
- private readonly Regex m_targetDbObjectRegex = new Regex(SCRIPTING_OBJECT_REGEX, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
-
- private Options m_options;
- private string m_definitionDirectory;
- private SqlConnectionStringBuilder m_connectionBuilder;
- private IUpgradeLog m_log;
-
- public DbObjectScripter(string connectionString, Options options, IUpgradeLog log)
- {
- m_connectionBuilder = new SqlConnectionStringBuilder(connectionString);
- m_options = options;
- m_log = log;
+ m_connectionBuilder = new SqlConnectionStringBuilder(connectionString);
+ m_options = options;
+ m_log = log;
+
+ var exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
+ m_definitionDirectory =
+ Path.GetFullPath(Path.Combine(exePath, m_options.BaseFolderNameDefinitions)).Normalize();
+ EnsureDirectoryExists(m_definitionDirectory);
+ }
- var exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- m_definitionDirectory = Path.GetFullPath(Path.Combine(exePath, m_options.BaseFolderNameDefinitions)).Normalize();
- EnsureDirectoryExists(m_definitionDirectory);
- }
+ public ScripterResult ScriptAll()
+ {
+ ScripterResult result = new ScripterResult();
- public ScripterResult ScriptAll()
+ try
{
- ScripterResult result = new ScripterResult();
+ //When scripting all object, do scripting in parallel so it will go faster.
+ //We need a DbServerContext for each scripting task since SMO is not thread safe.
- try
+ var tablesScriptTask = Task.Run(() =>
{
- //When scripting all object, do scripting in parallel so it will go faster.
- //We need a DbServerContext for each scripting task since SMO is not thread safe.
-
- var tablesScriptTask = Task.Run(() =>
- {
- var context = GetDatabaseContext(true);
- ScriptAllTables(context);
- });
-
- var viewsScriptTask = Task.Run(() =>
- {
- var context = GetDatabaseContext(true);
- ScriptAllViews(context);
- });
-
- var storedProceduresScriptTask = Task.Run(() =>
- {
- var context = GetDatabaseContext(true);
- ScriptAllStoredProcedures(context);
- });
+ var context = GetDatabaseContext(true);
+ ScriptAllTables(context);
+ });
- var synonymsScriptTask = Task.Run(() =>
- {
- var context = GetDatabaseContext(true);
- ScriptAllSynonyms(context);
- });
+ var viewsScriptTask = Task.Run(() =>
+ {
+ var context = GetDatabaseContext(true);
+ ScriptAllViews(context);
+ });
- var udtScriptTask = Task.Run(() =>
- {
- var context = GetDatabaseContext(true);
- ScriptAllUserDefinedTypes(context);
- });
+ var storedProceduresScriptTask = Task.Run(() =>
+ {
+ var context = GetDatabaseContext(true);
+ ScriptAllStoredProcedures(context);
+ });
- var functionsScriptTask = Task.Run(() =>
- {
- var context = GetDatabaseContext(true);
- this.ScriptAllFunctions(context);
- });
+ var synonymsScriptTask = Task.Run(() =>
+ {
+ var context = GetDatabaseContext(true);
+ ScriptAllSynonyms(context);
+ });
- Task.WaitAll(
- tablesScriptTask,
- viewsScriptTask,
- storedProceduresScriptTask,
- synonymsScriptTask,
- udtScriptTask,
- functionsScriptTask
- );
- }
- catch (Exception ex)
+ var udtScriptTask = Task.Run(() =>
{
- result.Successful = false;
- result.Error = ex;
- }
+ var context = GetDatabaseContext(true);
+ ScriptAllUserDefinedTypes(context);
+ });
- return result;
+ var functionsScriptTask = Task.Run(() =>
+ {
+ var context = GetDatabaseContext(true);
+ this.ScriptAllFunctions(context);
+ });
+
+ Task.WaitAll(
+ tablesScriptTask,
+ viewsScriptTask,
+ storedProceduresScriptTask,
+ synonymsScriptTask,
+ udtScriptTask,
+ functionsScriptTask
+ );
}
-
- public ScripterResult ScriptMigrationTargets(IEnumerable migrationScripts)
+ catch (Exception ex)
{
- List scriptObjects = new List(migrationScripts.SelectMany(this.GetObjectsFromMigrationScripts));
- scriptObjects = CleanupScriptObjects(scriptObjects);
-
- return ScriptObjects(scriptObjects);
+ result.Successful = false;
+ result.Error = ex;
}
- private IEnumerable GetObjectsFromMigrationScripts(SqlScript script)
+ return result;
+ }
+
+ public ScripterResult ScriptMigrationTargets(
+ IEnumerable migrationScripts
+ )
+ {
+ List scriptObjects =
+ new List(migrationScripts.SelectMany(this.GetObjectsFromMigrationScripts));
+ scriptObjects = CleanupScriptObjects(scriptObjects);
+
+ return ScriptObjects(scriptObjects);
+ }
+
+ private IEnumerable GetObjectsFromMigrationScripts(
+ SqlScript script
+ )
+ {
+ //extract db object target(s) from scripts
+ MatchCollection matches = this.m_targetDbObjectRegex.Matches(script.Contents);
+ foreach (Match m in matches)
{
- //extract db object target(s) from scripts
- MatchCollection matches = this.m_targetDbObjectRegex.Matches(script.Contents);
- foreach (Match m in matches)
+ //if this group is empty, it means the second part of the regex matched (sp_rename)
+ if (!string.IsNullOrEmpty(m.Groups[REGEX_INDEX_ACTION_TYPE].Value))
{
- //if this group is empty, it means the second part of the regex matched (sp_rename)
- if (!string.IsNullOrEmpty(m.Groups[REGEX_INDEX_ACTION_TYPE].Value))
+ if (!Enum.TryParse(m.Groups[REGEX_INDEX_OBJECT_TYPE].Value, true, out var type))
{
- if (!Enum.TryParse(m.Groups[REGEX_INDEX_OBJECT_TYPE].Value, true, out var type))
+ //We're adjusting for "PROC" vs "PROCEDURE" since we're checking for it in m_targetDbObjectRegex but it's not an enum member ( "PROCEDURE|PROC" )
+ if (m.Groups[REGEX_INDEX_OBJECT_TYPE].Value.Equals("PROC", StringComparison.OrdinalIgnoreCase))
{
- //We're adjusting for "PROC" vs "PROCEDURE" since we're checking for it in m_targetDbObjectRegex but it's not an enum member ( "PROCEDURE|PROC" )
- if (m.Groups[REGEX_INDEX_OBJECT_TYPE].Value.Equals("PROC", StringComparison.OrdinalIgnoreCase))
- {
- type = ObjectTypeEnum.Procedure;
- }
- //else it's ObjectTypeEnum.Undefined
+ type = ObjectTypeEnum.Procedure;
}
- if (type != ObjectTypeEnum.Undefined)
- {
- //replace CREATE OR ALTER by CREATE
- var actionString = m.Groups[REGEX_INDEX_ACTION_TYPE].Value.StartsWith(ObjectActionEnum.Create.ToString(), StringComparison.OrdinalIgnoreCase)
- ? ObjectActionEnum.Create.ToString()
- : m.Groups[REGEX_INDEX_ACTION_TYPE].Value;
-
- ObjectActionEnum action = (ObjectActionEnum)Enum.Parse(typeof(ObjectActionEnum), actionString, true);
- var scriptObject = new ScriptObject(type, action);
-
- if (string.IsNullOrEmpty(m.Groups[REGEX_INDEX_OBJECT_NAME].Value) && !string.IsNullOrEmpty(m.Groups[REGEX_INDEX_SCHEMA_NAME].Value))
- {
- //no schema specified. in that case, object name is in the schema group
- scriptObject.ObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_SCHEMA_NAME].Value);
- }
- else
- {
- scriptObject.ObjectSchema = RemoveBrackets(m.Groups[REGEX_INDEX_SCHEMA_NAME].Value);
- scriptObject.ObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_NAME].Value);
- }
-
- yield return scriptObject;
- }
- }
- else
+ //else it's ObjectTypeEnum.Undefined
+ }
+
+ if (type != ObjectTypeEnum.Undefined)
{
- string schemaName;
- string oldObjectName;
- string newObjectName;
- if (string.IsNullOrEmpty(m.Groups[REGEX_INDEX_OBJECT_RENAME_OLD_NAME].Value) && !string.IsNullOrEmpty(m.Groups[REGEX_INDEX_OBJECT_RENAME_SCHEMA].Value))
+ //replace CREATE OR ALTER by CREATE
+ var actionString = m.Groups[REGEX_INDEX_ACTION_TYPE].Value
+ .StartsWith(ObjectActionEnum.Create.ToString(), StringComparison.OrdinalIgnoreCase)
+ ? ObjectActionEnum.Create.ToString()
+ : m.Groups[REGEX_INDEX_ACTION_TYPE].Value;
+
+ ObjectActionEnum action =
+ (ObjectActionEnum)Enum.Parse(typeof(ObjectActionEnum), actionString, true);
+ var scriptObject = new ScriptObject(type, action);
+
+ if (string.IsNullOrEmpty(m.Groups[REGEX_INDEX_OBJECT_NAME].Value) &&
+ !string.IsNullOrEmpty(m.Groups[REGEX_INDEX_SCHEMA_NAME].Value))
{
//no schema specified. in that case, object name is in the schema group
- schemaName = "dbo";
- oldObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_RENAME_SCHEMA].Value);
- newObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_RENAME_OLD_NAME].Value);
+ scriptObject.ObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_SCHEMA_NAME].Value);
}
else
{
- schemaName = m.Groups[REGEX_INDEX_OBJECT_RENAME_SCHEMA].Value;
- oldObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_RENAME_OLD_NAME].Value);
- newObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_RENAME_NEW_NAME].Value);
+ scriptObject.ObjectSchema = RemoveBrackets(m.Groups[REGEX_INDEX_SCHEMA_NAME].Value);
+ scriptObject.ObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_NAME].Value);
}
-
- var type = GetObjectTypeFromDb(schemaName, newObjectName);
- var scriptObjectDrop = new ScriptObject(type, ObjectActionEnum.Drop);
- scriptObjectDrop.ObjectSchema = schemaName;
- scriptObjectDrop.ObjectName = oldObjectName;
+ yield return scriptObject;
+ }
+ }
+ else
+ {
+ string schemaName;
+ string oldObjectName;
+ string newObjectName;
+ if (string.IsNullOrEmpty(m.Groups[REGEX_INDEX_OBJECT_RENAME_OLD_NAME].Value) &&
+ !string.IsNullOrEmpty(m.Groups[REGEX_INDEX_OBJECT_RENAME_SCHEMA].Value))
+ {
+ //no schema specified. in that case, object name is in the schema group
+ schemaName = "dbo";
+ oldObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_RENAME_SCHEMA].Value);
+ newObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_RENAME_OLD_NAME].Value);
+ }
+ else
+ {
+ schemaName = m.Groups[REGEX_INDEX_OBJECT_RENAME_SCHEMA].Value;
+ oldObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_RENAME_OLD_NAME].Value);
+ newObjectName = RemoveBrackets(m.Groups[REGEX_INDEX_OBJECT_RENAME_NEW_NAME].Value);
+ }
- yield return scriptObjectDrop;
+ var type = GetObjectTypeFromDb(schemaName, newObjectName);
- var scriptObjectCreate = new ScriptObject(type, ObjectActionEnum.Create);
- scriptObjectCreate.ObjectSchema = schemaName;
- scriptObjectCreate.ObjectName = newObjectName;
-
- yield return scriptObjectCreate;
- }
+ var scriptObjectDrop = new ScriptObject(type, ObjectActionEnum.Drop);
+ scriptObjectDrop.ObjectSchema = schemaName;
+ scriptObjectDrop.ObjectName = oldObjectName;
+
+ yield return scriptObjectDrop;
+
+ var scriptObjectCreate = new ScriptObject(type, ObjectActionEnum.Create);
+ scriptObjectCreate.ObjectSchema = schemaName;
+ scriptObjectCreate.ObjectName = newObjectName;
+
+ yield return scriptObjectCreate;
}
}
+ }
- private static string RemoveBrackets(string @string)
+ private static string RemoveBrackets(
+ string @string
+ )
+ {
+ char[] removeCharacters = { '[', ']' };
+ return removeCharacters.Aggregate(@string, (
+ c1,
+ c2
+ ) => c1.Replace(c2.ToString(), ""));
+ }
+
+ private ObjectTypeEnum GetObjectTypeFromDb(
+ string schemaName,
+ string objectName
+ )
+ {
+ var context = this.GetDatabaseContext(false);
+ if (context.Database.Tables[objectName, schemaName] != null)
{
- char[] removeCharacters = { '[', ']' };
- return removeCharacters.Aggregate(@string, (c1, c2) => c1.Replace(c2.ToString(), ""));
+ return ObjectTypeEnum.Table;
}
- private ObjectTypeEnum GetObjectTypeFromDb(string schemaName, string objectName)
+ if (context.Database.Views[objectName, schemaName] != null)
{
- var context = this.GetDatabaseContext(false);
- if (context.Database.Tables[objectName, schemaName] != null)
- {
- return ObjectTypeEnum.Table;
- }
- if (context.Database.Views[objectName, schemaName] != null)
- {
- return ObjectTypeEnum.View;
- }
- if (context.Database.Synonyms[objectName, schemaName] != null)
- {
- return ObjectTypeEnum.Synonym;
- }
- if (context.Database.StoredProcedures[objectName, schemaName] != null || context.Database.ExtendedStoredProcedures[objectName, schemaName] != null)
- {
- return ObjectTypeEnum.Procedure;
- }
- if (context.Database.UserDefinedFunctions[objectName, schemaName] != null)
- {
- return ObjectTypeEnum.Function;
- }
- if (context.Database.UserDefinedDataTypes[objectName, schemaName] != null || context.Database.UserDefinedTableTypes[objectName, schemaName] != null|| context.Database.UserDefinedTypes[objectName, schemaName] != null)
- {
- return ObjectTypeEnum.Type;
- }
+ return ObjectTypeEnum.View;
+ }
+
+ if (context.Database.Synonyms[objectName, schemaName] != null)
+ {
+ return ObjectTypeEnum.Synonym;
+ }
- return ObjectTypeEnum.Undefined;
+ if (context.Database.StoredProcedures[objectName, schemaName] != null ||
+ context.Database.ExtendedStoredProcedures[objectName, schemaName] != null)
+ {
+ return ObjectTypeEnum.Procedure;
+ }
+
+ if (context.Database.UserDefinedFunctions[objectName, schemaName] != null)
+ {
+ return ObjectTypeEnum.Function;
}
- ///
- /// Remove duplicates from a list of ScriptObjects to avoid double sripting of files and not run into errors with later droped objects
- ///
- ///
- ///
- private static List CleanupScriptObjects(List scriptObjects)
+ if (context.Database.UserDefinedDataTypes[objectName, schemaName] != null ||
+ context.Database.UserDefinedTableTypes[objectName, schemaName] != null ||
+ context.Database.UserDefinedTypes[objectName, schemaName] != null)
{
- var preCleanUpScripts = new List(scriptObjects);
- preCleanUpScripts.Reverse();
+ return ObjectTypeEnum.Type;
+ }
+
+ return ObjectTypeEnum.Undefined;
+ }
+
+ ///
+ /// Remove duplicates from a list of ScriptObjects to avoid double sripting of files and not run into errors with later droped objects
+ ///
+ ///
+ ///
+ private static List CleanupScriptObjects(
+ List scriptObjects
+ )
+ {
+ var preCleanUpScripts = new List(scriptObjects);
+ preCleanUpScripts.Reverse();
- var cleanedUpScripts = new List();
- foreach (var script in preCleanUpScripts)
+ var cleanedUpScripts = new List();
+ foreach (var script in preCleanUpScripts)
+ {
+ if (!cleanedUpScripts.Any(s => s.FullName.Equals(script.FullName, StringComparison.OrdinalIgnoreCase)))
{
- if (!cleanedUpScripts.Any(s => s.FullName.Equals(script.FullName, StringComparison.OrdinalIgnoreCase)))
- {
- cleanedUpScripts.Add(script);
- }
+ cleanedUpScripts.Add(script);
}
-
- return cleanedUpScripts;
}
- public ScripterResult ScriptObjects(IEnumerable objects)
+ return cleanedUpScripts;
+ }
+
+ public ScripterResult ScriptObjects(
+ IEnumerable objects
+ )
+ {
+ ScripterResult result = new ScripterResult();
+
+ try
{
- ScripterResult result = new ScripterResult();
+ var context = GetDatabaseContext(false);
- try
- {
- var context = GetDatabaseContext(false);
+ ScriptTables(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Table));
+ ScriptViews(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.View));
+ ScriptStoredProcedures(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Procedure));
+ ScriptFunctions(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Function));
+ ScriptSynonyms(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Synonym));
+ ScriptUserDefinedTypes(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Type));
- ScriptTables(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Table));
- ScriptViews(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.View));
- ScriptStoredProcedures(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Procedure));
- ScriptFunctions(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Function));
- ScriptSynonyms(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Synonym));
- ScriptUserDefinedTypes(context, objects.Where(o => o.ObjectType == ObjectTypeEnum.Type));
+ WarnUndefinedObjects(objects.Where(o => o.ObjectType == ObjectTypeEnum.Undefined));
+ }
+ catch (Exception ex)
+ {
+ result.Successful = false;
+ result.Error = ex;
+ }
- WarnUndefinedObjects(objects.Where(o => o.ObjectType == ObjectTypeEnum.Undefined));
- }
- catch (Exception ex)
+ return result;
+ }
+
+ protected void ScriptAllTables(
+ DbServerContext context
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
+ {
+ List tables = new List();
+ foreach (Table table in context.Database.Tables)
{
- result.Successful = false;
- result.Error = ex;
+ if (!table.IsSystemObject)
+ {
+ tables.Add(new ScriptObject(ObjectTypeEnum.Table, ObjectActionEnum.Create)
+ {
+ ObjectName = table.Name,
+ ObjectSchema = table.Schema
+ });
+ }
}
- return result;
+ ScriptTables(context, tables);
}
+ }
- protected void ScriptAllTables(DbServerContext context)
+ protected void ScriptTables(
+ DbServerContext context,
+ IEnumerable tables
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
+ string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameTables);
+
+ foreach (ScriptObject tableObject in tables)
{
- List tables = new List();
- foreach (Table table in context.Database.Tables)
+ if (tableObject.ObjectAction == ObjectActionEnum.Drop)
{
- if (!table.IsSystemObject)
- {
- tables.Add(new ScriptObject(ObjectTypeEnum.Table, ObjectActionEnum.Create)
- {
- ObjectName = table.Name,
- ObjectSchema = table.Schema
- });
- }
+ DeleteScript(tableObject, outputDirectory);
}
+ else
+ {
+ Table currentTable = context.Database.Tables[tableObject.ObjectName, tableObject.ObjectSchema];
- ScriptTables(context, tables);
+ ScriptDefinition(tableObject, outputDirectory,
+ new Func(() => { return currentTable.Script(m_options.ScriptingOptions); }));
+ }
}
}
+ }
- protected void ScriptTables(DbServerContext context, IEnumerable tables)
+ protected void ScriptAllUserDefinedTypes(
+ DbServerContext context
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Type) == ObjectTypeEnum.Type)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Table) == ObjectTypeEnum.Table)
+ List types = new List();
+ foreach (UserDefinedType udt in context.Database.UserDefinedTypes)
{
- string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameTables);
+ types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create)
+ {
+ ObjectName = udt.Name,
+ ObjectSchema = udt.Schema
+ });
+ }
- foreach (ScriptObject tableObject in tables)
+ foreach (UserDefinedDataType udt in context.Database.UserDefinedDataTypes)
+ {
+ types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create)
{
- if (tableObject.ObjectAction == ObjectActionEnum.Drop)
- {
- DeleteScript(tableObject, outputDirectory);
- }
- else
- {
- Table currentTable = context.Database.Tables[tableObject.ObjectName, tableObject.ObjectSchema];
+ ObjectName = udt.Name,
+ ObjectSchema = udt.Schema
+ });
+ }
- ScriptDefinition(tableObject, outputDirectory, new Func(() =>
- {
- return currentTable.Script(m_options.ScriptingOptions);
- }));
- }
+ foreach (UserDefinedFunction udt in context.Database.UserDefinedFunctions)
+ {
+ if (!udt.IsSystemObject)
+ {
+ types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create)
+ {
+ ObjectName = udt.Name,
+ ObjectSchema = udt.Schema
+ });
}
}
- }
- protected void ScriptAllUserDefinedTypes(DbServerContext context) {
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Type) == ObjectTypeEnum.Type) {
- List types = new List();
- foreach (UserDefinedType udt in context.Database.UserDefinedTypes) {
- types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create) {
- ObjectName = udt.Name,
- ObjectSchema = udt.Schema
- });
- }
- foreach (UserDefinedDataType udt in context.Database.UserDefinedDataTypes) {
- types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create) {
- ObjectName = udt.Name,
- ObjectSchema = udt.Schema
- });
- }
- foreach (UserDefinedFunction udt in context.Database.UserDefinedFunctions) {
- if (!udt.IsSystemObject) {
- types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create) {
- ObjectName = udt.Name,
- ObjectSchema = udt.Schema
- });
- }
- }
- foreach (UserDefinedTableType udt in context.Database.UserDefinedTableTypes) {
- if (udt.IsUserDefined) {
- types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create) {
- ObjectName = udt.Name,
- ObjectSchema = udt.Schema
- });
- }
- }
-
- ScriptUserDefinedTypes(context, types);
- }
- }
-
- protected void ScriptUserDefinedTypes(DbServerContext context, IEnumerable udts) {
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Type) == ObjectTypeEnum.Type) {
- string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameUserDefinedTypes);
-
- foreach (ScriptObject udtObject in udts) {
- if (udtObject.ObjectAction == ObjectActionEnum.Drop) {
- DeleteScript(udtObject, outputDirectory);
- } else {
- if (context.Database.UserDefinedTypes.Contains(udtObject.ObjectName, udtObject.ObjectSchema)) {
- var currentType = context.Database.UserDefinedTypes[udtObject.ObjectName, udtObject.ObjectSchema];
- ScriptDefinition(udtObject, outputDirectory, new Func(() => {
- return currentType.Script(m_options.ScriptingOptions);
- }));
- } else if (context.Database.UserDefinedDataTypes.Contains(udtObject.ObjectName, udtObject.ObjectSchema)) {
- var currentType = context.Database.UserDefinedDataTypes[udtObject.ObjectName, udtObject.ObjectSchema];
- ScriptDefinition(udtObject, outputDirectory, new Func(() => {
- return currentType.Script(m_options.ScriptingOptions);
- }));
- } else if (context.Database.UserDefinedFunctions.Contains(udtObject.ObjectName, udtObject.ObjectSchema)) {
- var currentType = context.Database.UserDefinedFunctions[udtObject.ObjectName, udtObject.ObjectSchema];
- ScriptDefinition(udtObject, outputDirectory, new Func(() => {
- return currentType.Script(m_options.ScriptingOptions);
- }));
- } else {
- var currentType = context.Database.UserDefinedTableTypes[udtObject.ObjectName, udtObject.ObjectSchema];
- ScriptDefinition(udtObject, outputDirectory, new Func(() => {
- return currentType.Script(m_options.ScriptingOptions);
- }));
-
- }
- }
- }
- }
- }
-
- protected void ScriptAllViews(DbServerContext context)
- {
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
+ foreach (UserDefinedTableType udt in context.Database.UserDefinedTableTypes)
{
- List views = new List();
- foreach (View view in context.Database.Views)
+ if (udt.IsUserDefined)
{
- if (!view.IsSystemObject)
+ types.Add(new ScriptObject(ObjectTypeEnum.Type, ObjectActionEnum.Create)
{
- views.Add(new ScriptObject(ObjectTypeEnum.View, ObjectActionEnum.Create)
- {
- ObjectName = view.Name,
- ObjectSchema = view.Schema
- });
- }
+ ObjectName = udt.Name,
+ ObjectSchema = udt.Schema
+ });
}
-
- ScriptViews(context, views);
}
+
+ ScriptUserDefinedTypes(context, types);
}
+ }
- protected void ScriptViews(DbServerContext context, IEnumerable views)
+ protected void ScriptUserDefinedTypes(
+ DbServerContext context,
+ IEnumerable udts
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Type) == ObjectTypeEnum.Type)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
- {
- string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameViews);
+ string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameUserDefinedTypes);
- foreach (ScriptObject viewObject in views)
+ foreach (ScriptObject udtObject in udts)
+ {
+ if (udtObject.ObjectAction == ObjectActionEnum.Drop)
+ {
+ DeleteScript(udtObject, outputDirectory);
+ }
+ else
{
- if (viewObject.ObjectAction == ObjectActionEnum.Drop)
+ if (context.Database.UserDefinedTypes.Contains(udtObject.ObjectName, udtObject.ObjectSchema))
+ {
+ var currentType =
+ context.Database.UserDefinedTypes[udtObject.ObjectName, udtObject.ObjectSchema];
+ ScriptDefinition(udtObject, outputDirectory,
+ new Func(() =>
+ {
+ return currentType.Script(m_options.ScriptingOptions);
+ }));
+ }
+ else if (context.Database.UserDefinedDataTypes.Contains(udtObject.ObjectName,
+ udtObject.ObjectSchema))
+ {
+ var currentType =
+ context.Database.UserDefinedDataTypes[udtObject.ObjectName, udtObject.ObjectSchema];
+ ScriptDefinition(udtObject, outputDirectory,
+ new Func(() =>
+ {
+ return currentType.Script(m_options.ScriptingOptions);
+ }));
+ }
+ else if (context.Database.UserDefinedFunctions.Contains(udtObject.ObjectName,
+ udtObject.ObjectSchema))
{
- DeleteScript(viewObject, outputDirectory);
+ var currentType =
+ context.Database.UserDefinedFunctions[udtObject.ObjectName, udtObject.ObjectSchema];
+ ScriptDefinition(udtObject, outputDirectory,
+ new Func(() =>
+ {
+ return currentType.Script(m_options.ScriptingOptions);
+ }));
}
else
{
- View currentView = context.Database.Views[viewObject.ObjectName, viewObject.ObjectSchema];
- ScriptDefinition(viewObject, outputDirectory, new Func(() =>
- {
- return currentView.Script(m_options.ScriptingOptions);
- }));
+ var currentType =
+ context.Database.UserDefinedTableTypes[udtObject.ObjectName, udtObject.ObjectSchema];
+ ScriptDefinition(udtObject, outputDirectory,
+ new Func(() =>
+ {
+ return currentType.Script(m_options.ScriptingOptions);
+ }));
}
}
}
}
+ }
- protected void ScriptAllStoredProcedures(DbServerContext context)
+ protected void ScriptAllViews(
+ DbServerContext context
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
+ List views = new List();
+ foreach (View view in context.Database.Views)
{
- List sprocs = new List();
- foreach (StoredProcedure sproc in context.Database.StoredProcedures)
+ if (!view.IsSystemObject)
{
- if (!sproc.IsSystemObject)
+ views.Add(new ScriptObject(ObjectTypeEnum.View, ObjectActionEnum.Create)
{
- sprocs.Add(new ScriptObject(ObjectTypeEnum.Procedure, ObjectActionEnum.Create)
- {
- ObjectName = sproc.Name,
- ObjectSchema = sproc.Schema
- });
- }
+ ObjectName = view.Name,
+ ObjectSchema = view.Schema
+ });
}
-
- ScriptStoredProcedures(context, sprocs);
}
+
+ ScriptViews(context, views);
}
+ }
- protected void ScriptStoredProcedures(DbServerContext context, IEnumerable sprocs)
+ protected void ScriptViews(
+ DbServerContext context,
+ IEnumerable views
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.View) == ObjectTypeEnum.View)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
- {
- string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameProcedures);
+ string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameViews);
- foreach (ScriptObject sprocObject in sprocs)
+ foreach (ScriptObject viewObject in views)
+ {
+ if (viewObject.ObjectAction == ObjectActionEnum.Drop)
{
- if (sprocObject.ObjectAction == ObjectActionEnum.Drop)
- {
- DeleteScript(sprocObject, outputDirectory);
- }
- else
- {
- StoredProcedure currentSproc = context.Database.StoredProcedures[sprocObject.ObjectName, sprocObject.ObjectSchema];
- ScriptDefinition(sprocObject, outputDirectory, new Func(() =>
- {
- return currentSproc.Script(m_options.ScriptingOptions);
- }));
- }
+ DeleteScript(viewObject, outputDirectory);
+ }
+ else
+ {
+ View currentView = context.Database.Views[viewObject.ObjectName, viewObject.ObjectSchema];
+ ScriptDefinition(viewObject, outputDirectory,
+ new Func(() => { return currentView.Script(m_options.ScriptingOptions); }));
}
}
}
+ }
- protected void ScriptAllFunctions(DbServerContext context)
+ protected void ScriptAllStoredProcedures(
+ DbServerContext context
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Function) == ObjectTypeEnum.Function)
+ List sprocs = new List();
+ foreach (StoredProcedure sproc in context.Database.StoredProcedures)
{
- List tables = new List();
- foreach (UserDefinedFunction udf in context.Database.UserDefinedFunctions)
+ if (!sproc.IsSystemObject)
{
- if (!udf.IsSystemObject)
+ sprocs.Add(new ScriptObject(ObjectTypeEnum.Procedure, ObjectActionEnum.Create)
{
- tables.Add(new ScriptObject(ObjectTypeEnum.Function, ObjectActionEnum.Create)
- {
- ObjectName = udf.Name,
- ObjectSchema = udf.Schema
- });
- }
+ ObjectName = sproc.Name,
+ ObjectSchema = sproc.Schema
+ });
}
-
- ScriptFunctions(context, tables);
}
+
+ ScriptStoredProcedures(context, sprocs);
}
+ }
- protected void ScriptFunctions(DbServerContext context, IEnumerable udfs)
+ protected void ScriptStoredProcedures(
+ DbServerContext context,
+ IEnumerable sprocs
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Procedure) == ObjectTypeEnum.Procedure)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Function) == ObjectTypeEnum.Function)
- {
- string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameFunctions);
+ string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameProcedures);
- foreach (ScriptObject udfObject in udfs)
+ foreach (ScriptObject sprocObject in sprocs)
+ {
+ if (sprocObject.ObjectAction == ObjectActionEnum.Drop)
{
- if (udfObject.ObjectAction == ObjectActionEnum.Drop)
- {
- DeleteScript(udfObject, outputDirectory);
- }
- else
- {
- UserDefinedFunction currentUdf = context.Database.UserDefinedFunctions[udfObject.ObjectName, udfObject.ObjectSchema];
- ScriptDefinition(udfObject, outputDirectory, new Func(() =>
- {
- return currentUdf.Script(m_options.ScriptingOptions);
- }));
- }
+ DeleteScript(sprocObject, outputDirectory);
+ }
+ else
+ {
+ StoredProcedure currentSproc =
+ context.Database.StoredProcedures[sprocObject.ObjectName, sprocObject.ObjectSchema];
+ ScriptDefinition(sprocObject, outputDirectory,
+ new Func(() => { return currentSproc.Script(m_options.ScriptingOptions); }));
}
}
}
+ }
- protected void ScriptAllSynonyms(DbServerContext context)
+ protected void ScriptAllFunctions(
+ DbServerContext context
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Function) == ObjectTypeEnum.Function)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
+ List tables = new List();
+ foreach (UserDefinedFunction udf in context.Database.UserDefinedFunctions)
{
- List synonyms = new List();
- foreach (Synonym synonym in context.Database.Synonyms)
+ if (!udf.IsSystemObject)
{
- synonyms.Add(new ScriptObject(ObjectTypeEnum.Synonym, ObjectActionEnum.Create)
- {
- ObjectName = synonym.Name,
- ObjectSchema = synonym.Schema
- });
+ tables.Add(new ScriptObject(ObjectTypeEnum.Function, ObjectActionEnum.Create)
+ {
+ ObjectName = udf.Name,
+ ObjectSchema = udf.Schema
+ });
}
-
- ScriptSynonyms(context, synonyms);
}
+
+ ScriptFunctions(context, tables);
}
+ }
- protected void ScriptSynonyms(DbServerContext context, IEnumerable synonyms)
+ protected void ScriptFunctions(
+ DbServerContext context,
+ IEnumerable udfs
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Function) == ObjectTypeEnum.Function)
{
- if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
- {
- string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameSynonyms);
+ string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameFunctions);
- foreach (ScriptObject synonymObject in synonyms)
+ foreach (ScriptObject udfObject in udfs)
+ {
+ if (udfObject.ObjectAction == ObjectActionEnum.Drop)
{
- Synonym curentSynonym = context.Database.Synonyms[synonymObject.ObjectName, synonymObject.ObjectSchema];
- ScriptDefinition(synonymObject, outputDirectory, new Func(() =>
- {
- return curentSynonym.Script(m_options.ScriptingOptions);
- }));
+ DeleteScript(udfObject, outputDirectory);
+ }
+ else
+ {
+ UserDefinedFunction currentUdf =
+ context.Database.UserDefinedFunctions[udfObject.ObjectName, udfObject.ObjectSchema];
+ ScriptDefinition(udfObject, outputDirectory,
+ new Func(() => { return currentUdf.Script(m_options.ScriptingOptions); }));
}
}
}
+ }
- private DbServerContext GetDatabaseContext(bool loadAllFields = false)
+ protected void ScriptAllSynonyms(
+ DbServerContext context
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
{
- DbServerContext context = new DbServerContext();
- SqlConnection connection = new SqlConnection(m_connectionBuilder.ConnectionString);
- ServerConnection serverConnection = new ServerConnection(connection);
- context.Server = new Server(serverConnection);
- context.Database = context.Server.Databases[this.DatabaseName];
-
- context.Server.SetDefaultInitFields(loadAllFields);
+ List synonyms = new List();
+ foreach (Synonym synonym in context.Database.Synonyms)
+ {
+ synonyms.Add(new ScriptObject(ObjectTypeEnum.Synonym, ObjectActionEnum.Create)
+ {
+ ObjectName = synonym.Name,
+ ObjectSchema = synonym.Schema
+ });
+ }
- return context;
+ ScriptSynonyms(context, synonyms);
}
+ }
- private void ScriptDefinition(ScriptObject dbObject, string outputDirectory, Func scripter)
+ protected void ScriptSynonyms(
+ DbServerContext context,
+ IEnumerable synonyms
+ )
+ {
+ if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
{
- try
- {
- StringCollection script = scripter();
- SaveScript(dbObject, script, outputDirectory);
- }
- catch (Exception ex)
+ string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameSynonyms);
+
+ foreach (ScriptObject synonymObject in synonyms)
{
- m_log.WriteError(string.Format("Error when scripting definition for {0}.{1}: {2}", dbObject.ObjectSchema, dbObject.ObjectName, ex.Message));
+ Synonym curentSynonym = context.Database.Synonyms[synonymObject.ObjectName, synonymObject.ObjectSchema];
+ ScriptDefinition(synonymObject, outputDirectory,
+ new Func(() => { return curentSynonym.Script(m_options.ScriptingOptions); }));
}
}
+ }
- private void WarnUndefinedObjects(IEnumerable dbObjects)
+ private DbServerContext GetDatabaseContext(
+ bool loadAllFields = false
+ )
+ {
+ DbServerContext context = new DbServerContext();
+ SqlConnection connection = new SqlConnection(m_connectionBuilder.ConnectionString);
+ ServerConnection serverConnection = new ServerConnection(connection);
+ context.Server = new Server(serverConnection);
+ context.Database = context.Server.Databases[this.DatabaseName];
+
+ context.Server.SetDefaultInitFields(loadAllFields);
+
+ return context;
+ }
+
+ private void ScriptDefinition(
+ ScriptObject dbObject,
+ string outputDirectory,
+ Func scripter
+ )
+ {
+ try
{
- foreach (var dbObject in dbObjects)
- {
- m_log.WriteWarning(string.Format("The object {0}.{1} could not be scripted, since the object type was not identifyable. Normally this means, that the object has been dropped in the meantime. If necessary delete the file manually.", dbObject.ObjectSchema, dbObject.ObjectName));
- }
+ StringCollection script = scripter();
+ SaveScript(dbObject, script, outputDirectory);
}
+ catch (Exception ex)
+ {
+ m_log.LogError(string.Format("Error when scripting definition for {0}.{1}: {2}", dbObject.ObjectSchema,
+ dbObject.ObjectName, ex.Message));
+ }
+ }
- private void SaveScript(ScriptObject scriptObject, StringCollection script, string outputDirectory)
+ private void WarnUndefinedObjects(
+ IEnumerable dbObjects
+ )
+ {
+ foreach (var dbObject in dbObjects)
{
- try
+ m_log.LogWarning(string.Format(
+ "The object {0}.{1} could not be scripted, since the object type was not identifyable. Normally this means, that the object has been dropped in the meantime. If necessary delete the file manually.",
+ dbObject.ObjectSchema, dbObject.ObjectName));
+ }
+ }
+
+ private void SaveScript(
+ ScriptObject scriptObject,
+ StringCollection script,
+ string outputDirectory
+ )
+ {
+ try
+ {
+ EnsureDirectoryExists(outputDirectory);
+
+ StringBuilder sb = new StringBuilder();
+ foreach (string str in script)
{
- EnsureDirectoryExists(outputDirectory);
+ sb.Append(str);
+ sb.Append(Environment.NewLine);
- StringBuilder sb = new StringBuilder();
- foreach (string str in script)
+ if (this.m_options.ScriptBatchTerminator)
{
- sb.Append(str);
+ sb.Append("GO");
+ sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
-
- if (this.m_options.ScriptBatchTerminator)
- {
- sb.Append("GO");
- sb.Append(Environment.NewLine);
- sb.Append(Environment.NewLine);
- }
}
-
- m_log.WriteInformation(string.Format("Saving object definition: {0}", Path.Combine(outputDirectory, scriptObject.FileName)));
- File.WriteAllText(Path.Combine(outputDirectory, scriptObject.FileName), sb.ToString());
- }
- catch (Exception ex)
- {
- m_log.WriteError(string.Format("Error when saving script file {0}: {1}", scriptObject.FullName, ex.Message));
}
+
+ m_log.LogInformation(string.Format("Saving object definition: {0}",
+ Path.Combine(outputDirectory, scriptObject.FileName)));
+ File.WriteAllText(Path.Combine(outputDirectory, scriptObject.FileName), sb.ToString());
+ }
+ catch (Exception ex)
+ {
+ m_log.LogError(string.Format("Error when saving script file {0}: {1}", scriptObject.FullName,
+ ex.Message));
}
+ }
- private void DeleteScript(ScriptObject scriptObject, string outputDirectory)
+ private void DeleteScript(
+ ScriptObject scriptObject,
+ string outputDirectory
+ )
+ {
+ try
{
- try
- {
- string filePath = Path.Combine(outputDirectory, scriptObject.FileName);
- if (File.Exists(filePath))
- {
- m_log.WriteInformation(string.Format("Deleting object definition: {0}", filePath));
- File.Delete(filePath);
- }
- }
- catch (Exception ex)
+ string filePath = Path.Combine(outputDirectory, scriptObject.FileName);
+ if (File.Exists(filePath))
{
- m_log.WriteError(string.Format("Error when deleting script file {0}: {1}", scriptObject.FullName, ex.Message));
+ m_log.LogInformation(string.Format("Deleting object definition: {0}", filePath));
+ File.Delete(filePath);
}
}
+ catch (Exception ex)
+ {
+ m_log.LogError(string.Format("Error when deleting script file {0}: {1}", scriptObject.FullName,
+ ex.Message));
+ }
+ }
- private void EnsureDirectoryExists(string directoryPath)
+ private void EnsureDirectoryExists(
+ string directoryPath
+ )
+ {
+ if (!Directory.Exists(directoryPath))
{
- if (!Directory.Exists(directoryPath))
- {
- Directory.CreateDirectory(directoryPath);
- }
+ Directory.CreateDirectory(directoryPath);
}
+ }
+
+ private string m_databaseName;
- private string m_databaseName;
- protected string DatabaseName
+ protected string DatabaseName
+ {
+ get
{
- get
+ if (m_databaseName == null)
{
- if (m_databaseName == null)
+ if (!string.IsNullOrEmpty(m_connectionBuilder.InitialCatalog))
{
- if (!string.IsNullOrEmpty(m_connectionBuilder.InitialCatalog))
- {
- m_databaseName = m_connectionBuilder.InitialCatalog;
- }
- else if (!string.IsNullOrEmpty(m_connectionBuilder.AttachDBFilename))
- {
- var fileInfo = new FileInfo(m_connectionBuilder.AttachDBFilename);
- m_databaseName = Path.GetFileNameWithoutExtension(fileInfo.Name);
- }
-
- if (string.IsNullOrEmpty(m_databaseName))
- {
- throw new InvalidArgumentException("connectionString must include 'Initial Catalog', 'Database', or 'AttachDBFilename' value!");
- }
+ m_databaseName = m_connectionBuilder.InitialCatalog;
+ }
+ else if (!string.IsNullOrEmpty(m_connectionBuilder.AttachDBFilename))
+ {
+ var fileInfo = new FileInfo(m_connectionBuilder.AttachDBFilename);
+ m_databaseName = Path.GetFileNameWithoutExtension(fileInfo.Name);
}
- return m_databaseName;
+ if (string.IsNullOrEmpty(m_databaseName))
+ {
+ throw new InvalidArgumentException(
+ "connectionString must include 'Initial Catalog', 'Database', or 'AttachDBFilename' value!");
+ }
}
+
+ return m_databaseName;
}
}
-}
+}
\ No newline at end of file
diff --git a/DbUp.Support.SqlServer.Scripting/DbUp.Support.SqlServer.Scripting.csproj b/DbUp.Support.SqlServer.Scripting/DbUp.Support.SqlServer.Scripting.csproj
index 03d7169..1690aff 100644
--- a/DbUp.Support.SqlServer.Scripting/DbUp.Support.SqlServer.Scripting.csproj
+++ b/DbUp.Support.SqlServer.Scripting/DbUp.Support.SqlServer.Scripting.csproj
@@ -1,202 +1,14 @@
-
-
-
+
+
- Debug
- AnyCPU
- {A1EC7074-3C1D-4424-BC80-8BF770758774}
- Library
- Properties
- DbUp.Support.SqlServer.Scripting
- DbUp.Support.SqlServer.Scripting
- v4.5
- 512
-
-
-
+ net9.0
+ enable
+ enable
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- false
-
-
-
- ../packages/dbup-core.4.1.0/lib/net45/dbup-core.dll
- True
-
-
- ../packages/dbup-sqlserver.4.1.0/lib/net35/dbup-sqlserver.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.AzureStorageEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.BatchParserClient.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.ConnectionInfo.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.ConnectionInfoExtended.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Diagnostics.Strace.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Dmf.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Dmf.Common.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.Collector.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.CollectorEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.RegisteredServers.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.Sdk.Sfc.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.Utility.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.UtilityEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.XEvent.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.XEventDbScoped.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.XEventDbScopedEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Management.XEventEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.PolicyEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.RegSvrEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.ServiceBrokerEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Smo.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.SmoExtended.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.SqlClrProvider.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.SqlEnum.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.SqlTDiagm.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.SqlWmiManagement.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.SString.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.Types.dll
- True
-
-
- ../packages/Microsoft.SqlServer.SqlManagementObjects.140.17235.0/lib/net40/Microsoft.SqlServer.WmiEnum.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.
-
-
-
-
-
\ No newline at end of file
+
+
diff --git a/DbUp.Support.SqlServer.Scripting/DefinitionScriptProvider.cs b/DbUp.Support.SqlServer.Scripting/DefinitionScriptProvider.cs
index 28fe475..fc27856 100644
--- a/DbUp.Support.SqlServer.Scripting/DefinitionScriptProvider.cs
+++ b/DbUp.Support.SqlServer.Scripting/DefinitionScriptProvider.cs
@@ -1,149 +1,173 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Reflection;
+using System.Reflection;
using System.Text.RegularExpressions;
using DbUp.Engine;
using DbUp.Engine.Transactions;
-namespace DbUp.Support.SqlServer.Scripting
+namespace DbUp.Support.SqlServer.Scripting;
+
+///
+/// This script provider will collect all the scripts in the generated Definitions folder and attempt to order
+/// them in order of dependency, the dependency searching is quite basic, as it only looks for
+/// references of named entries, however this could be easily extended
+///
+public class DefinitionScriptProvider : IScriptProvider
{
- ///
- /// This script provider will collect all the scripts in the generated Definitions folder and attempt to order
- /// them in order of dependency, the dependency searching is quite basic, as it only looks for
- /// references of named entries, however this could be easily extended
- ///
- public class DefinitionScriptProvider : IScriptProvider
+ private readonly string _defintionFolderPath;
+ private readonly Regex _contentReplaceRegex;
+
+ public DefinitionScriptProvider() : this("..\\..\\Definitions",
+ "(SET ANSI_NULLS ON)|(SET ANSI_NULLS OFF)|(SET QUOTED_IDENTIFIER OFF)|(SET QUOTED_IDENTIFIER ON)")
{
- private readonly string _defintionFolderPath;
- private readonly Regex _contentReplaceRegex;
+ }
- public DefinitionScriptProvider(): this("..\\..\\Definitions", "(SET ANSI_NULLS ON)|(SET ANSI_NULLS OFF)|(SET QUOTED_IDENTIFIER OFF)|(SET QUOTED_IDENTIFIER ON)")
+ public DefinitionScriptProvider(
+ string defintionFolderPath = "..\\..\\Definitions",
+ string contentReplaceRegex =
+ "(SET ANSI_NULLS ON)|(SET ANSI_NULLS OFF)|(SET QUOTED_IDENTIFIER OFF)|(SET QUOTED_IDENTIFIER ON)"
+ )
+ {
+ if (Directory.Exists(defintionFolderPath))
{
-
+ _defintionFolderPath = new DirectoryInfo(defintionFolderPath).FullName;
}
- public DefinitionScriptProvider(string defintionFolderPath = "..\\..\\Definitions",
- string contentReplaceRegex = "(SET ANSI_NULLS ON)|(SET ANSI_NULLS OFF)|(SET QUOTED_IDENTIFIER OFF)|(SET QUOTED_IDENTIFIER ON)")
+ if (_defintionFolderPath == null)
{
- if (Directory.Exists(defintionFolderPath))
- {
- _defintionFolderPath = new DirectoryInfo(defintionFolderPath).FullName;
- }
- if (_defintionFolderPath == null)
- {
- var possible = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), defintionFolderPath);
- if (Directory.Exists(possible))
- {
- _defintionFolderPath = new DirectoryInfo(possible).FullName;
- }
- }
-
- if (_defintionFolderPath == null)
+ var possible = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
+ defintionFolderPath);
+ if (Directory.Exists(possible))
{
- throw new DirectoryNotFoundException("Path: " + defintionFolderPath + " not found");
+ _defintionFolderPath = new DirectoryInfo(possible).FullName;
}
-
- _contentReplaceRegex = new Regex(contentReplaceRegex, RegexOptions.Multiline);
}
- public IEnumerable GetScripts(IConnectionManager connectionManager)
+ if (_defintionFolderPath == null)
{
- return GatherScriptsWithDependencies();
+ throw new DirectoryNotFoundException("Path: " + defintionFolderPath + " not found");
}
- public string GetScriptContent()
- {
- var scripts = GatherScriptsWithDependencies();
- return string.Join($"{Environment.NewLine} GO {Environment.NewLine}", scripts.Select(x => x.Contents));
- }
+ _contentReplaceRegex = new Regex(contentReplaceRegex, RegexOptions.Multiline);
+ }
- private string GetFileContent(string path)
- {
- var text = File.ReadAllText(path);
- return _contentReplaceRegex.Replace(text, string.Empty);
- }
+ public IEnumerable GetScripts(
+ IConnectionManager connectionManager
+ )
+ {
+ return GatherScriptsWithDependencies();
+ }
- private IEnumerable