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..5c81cf8 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,30 @@ 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(DbFilePrefixArg, out filePrefix)) { - if (TargetConnectionMatchesPattern(context)) + 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); + } + } + else { - location = new DirectoryInfo(location).FullName + "\\"; - ChangeNewDatabaseLocation(context, location, filePrefix); + if (TargetConnectionMatchesPattern(context)) + { + datalocation = new DirectoryInfo(datalocation).FullName + "\\"; + logdatalocation = new DirectoryInfo(logdatalocation).FullName + "\\"; + ChangeNewDatabaseLocation(context, datalocation, logdatalocation, filePrefix); + } } } } @@ -98,7 +117,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 +148,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();