From aa4506e91955e125b4c9a48fb264af4554879a88 Mon Sep 17 00:00:00 2001 From: Abhinand Jinugu Date: Mon, 16 Apr 2018 23:03:45 -0400 Subject: [PATCH 1/2] minor changes: 1. Added one more parameter in case of different paths for data and logs 2. Checking if the path is of linux machine when SQL Server installed on Linux --- SampleTests/TestDbLocationModifiers.cs | 6 ++- Samples/Contributors/DbLocationModifier.cs | 43 ++++++++++++++++------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/SampleTests/TestDbLocationModifiers.cs b/SampleTests/TestDbLocationModifiers.cs index 32871cd..2ca3c66 100644 --- a/SampleTests/TestDbLocationModifiers.cs +++ b/SampleTests/TestDbLocationModifiers.cs @@ -149,7 +149,8 @@ public void TestDbLocationModifierForImport() options.ImportContributorArguments = Utils.BuildContributorArguments(new Dictionary() { - {DbLocationModifier.DbSaveLocationArg, dataFolder}, + {DbLocationModifier.DbSaveDataLocationArg, dataFolder}, + {DbLocationModifier.DbSaveLogDataLocationArg, dataFolder}, {DbLocationModifier.DbFilePrefixArg, filePrefix}, }); @@ -184,7 +185,8 @@ private static DacDeployOptions SetLocationChangingContributorOptions(string dat options.AdditionalDeploymentContributorArguments = Utils.BuildContributorArguments(new Dictionary() { - {DbLocationModifier.DbSaveLocationArg, dataFolder}, + {DbLocationModifier.DbSaveDataLocationArg, dataFolder}, + {DbLocationModifier.DbSaveLogDataLocationArg, dataFolder}, {DbLocationModifier.DbFilePrefixArg, filePrefix}, }); return options; diff --git a/Samples/Contributors/DbLocationModifier.cs b/Samples/Contributors/DbLocationModifier.cs index b20ab1e..dfde8d3 100644 --- a/Samples/Contributors/DbLocationModifier.cs +++ b/Samples/Contributors/DbLocationModifier.cs @@ -52,9 +52,14 @@ public class DbLocationModifier : DeploymentPlanModifier public const string ContributorId = "Public.Dac.Samples.Contributors.DbLocationModifier"; /// - /// Contributor argument defining the directory to save the MDF and LDF files for the database + /// Contributor argument defining the directory to save the MDF file for the database /// - public const string DbSaveLocationArg = "DbLocationModifier.SaveLocation"; + public const string DbSaveDataLocationArg = "DbLocationModifier.SaveDataLocation"; + + /// + /// Contributor argument defining the directory to save the LDF file for the database + /// + public const string DbSaveLogDataLocationArg = "DbLocationModifier.SaveLogDataLocation"; /// /// Contributor argument defining the prefix to use for the database files @@ -72,16 +77,32 @@ public class DbLocationModifier : DeploymentPlanModifier /// /// protected override void OnExecute(DeploymentPlanContributorContext context) - { + { + + // Run only if a location is defined and we're targeting a serverless (LocalDB) instance - string location, filePrefix; - if (context.Arguments.TryGetValue(DbSaveLocationArg, out location) + string datalocation, logdatalocation, filePrefix; + if (context.Arguments.TryGetValue(DbSaveDataLocationArg, out datalocation) + && context.Arguments.TryGetValue(DbSaveLogDataLocationArg, out logdatalocation) && context.Arguments.TryGetValue(DbFilePrefixArg, out filePrefix)) { - if (TargetConnectionMatchesPattern(context)) + //Assuming the path for SQL Server on Linux starts with "/" + if (datalocation.StartsWith("/") && logdatalocation.StartsWith("/")) { - location = new DirectoryInfo(location).FullName + "\\"; - ChangeNewDatabaseLocation(context, location, filePrefix); + + if (TargetConnectionMatchesPattern(context)) + { + ChangeNewDatabaseLocation(context, datalocation, logdatalocation, filePrefix); + } + } + else + { + if (TargetConnectionMatchesPattern(context)) + { + datalocation = new DirectoryInfo(datalocation).FullName + "\\"; + logdatalocation = new DirectoryInfo(logdatalocation).FullName + "\\"; + ChangeNewDatabaseLocation(context, datalocation, logdatalocation, filePrefix); + } } } } @@ -98,7 +119,7 @@ private bool TargetConnectionMatchesPattern(DeploymentPlanContributorContext con return true; } - private void ChangeNewDatabaseLocation(DeploymentPlanContributorContext context, string location, string filePrefix) + private void ChangeNewDatabaseLocation(DeploymentPlanContributorContext context, string datalocation, string logdatalocation, string filePrefix) { DeploymentStep nextStep = context.PlanHandle.Head; @@ -129,9 +150,9 @@ private void ChangeNewDatabaseLocation(DeploymentPlanContributorContext context, // Override setvars before the deployment begins StringBuilder sb = new StringBuilder(); - sb.AppendFormat(":setvar DefaultDataPath \"{0}\"", location) + sb.AppendFormat(":setvar DefaultDataPath \"{0}\"", datalocation) .AppendLine() - .AppendFormat(":setvar DefaultLogPath \"{0}\"", location) + .AppendFormat(":setvar DefaultLogPath \"{0}\"", logdatalocation) .AppendLine() .AppendFormat(":setvar DefaultFilePrefix \"{0}\"", filePrefix) .AppendLine(); From 5c23d9b83d42893f52aea6cf6732289c3bf1f189 Mon Sep 17 00:00:00 2001 From: Abhinand Jinugu Date: Tue, 21 Jul 2020 00:21:23 -0400 Subject: [PATCH 2/2] 1. Removed check for logdatalocation 2. Corrected indentation --- Samples/Contributors/DbLocationModifier.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Samples/Contributors/DbLocationModifier.cs b/Samples/Contributors/DbLocationModifier.cs index dfde8d3..5c81cf8 100644 --- a/Samples/Contributors/DbLocationModifier.cs +++ b/Samples/Contributors/DbLocationModifier.cs @@ -77,22 +77,20 @@ public class DbLocationModifier : DeploymentPlanModifier /// /// protected override void OnExecute(DeploymentPlanContributorContext context) - { - - + { // Run only if a location is defined and we're targeting a serverless (LocalDB) instance - string datalocation, logdatalocation, filePrefix; - if (context.Arguments.TryGetValue(DbSaveDataLocationArg, out datalocation) - && context.Arguments.TryGetValue(DbSaveLogDataLocationArg, out logdatalocation) + string datalocation, logdatalocation, filePrefix; + if (context.Arguments.TryGetValue(DbSaveDataLocationArg, out datalocation) && context.Arguments.TryGetValue(DbFilePrefixArg, out filePrefix)) { + logdatalocation = context.Arguments.TryGetValue(DbSaveLogDataLocationArg, out logdatalocation) ? logdatalocation : datalocation; //Assuming the path for SQL Server on Linux starts with "/" if (datalocation.StartsWith("/") && logdatalocation.StartsWith("/")) { if (TargetConnectionMatchesPattern(context)) { - ChangeNewDatabaseLocation(context, datalocation, logdatalocation, filePrefix); + ChangeNewDatabaseLocation(context, datalocation, logdatalocation, filePrefix); } } else