public async Task Should_allow_catchup_of_targets()
        {
            using var l = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Trace));
            var x = XDocument.Load(File.OpenRead("local_test.xml"));
            var d = SqlDeployment.Load(x);
            var a = GetArgs();
            var r = new Random();
            var n = r.Next(0, int.MaxValue);

            a["SQL_InstanceName"] = "(localdb)\\SQL_" + n.ToString("X8");
            a["EFM_InstanceName"] = "(localdb)\\EFM_" + n.ToString("X8");
            var p = d.Compile(a);

            var e = new SqlDeploymentExecutor(p, l.CreateLogger <SqlDeploymentExecutor>());
            await e.ExecuteAsync("SQL");

            await e.ExecuteAsync("SQL_TO_EFM");

            var api = new MartinCostello.SqlLocalDb.SqlLocalDbApi();

            api.AutomaticallyDeleteInstanceFiles = true;
            api.StopInstance("SQL_" + n.ToString("X8"));
            api.StopInstance("EFM_" + n.ToString("X8"));
            api.DeleteInstance("SQL_" + n.ToString("X8"));
            api.DeleteInstance("EFM_" + n.ToString("X8"));
        }
        public async Task Can_execute_devel_test()
        {
            using var l = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Trace));
            var x = XDocument.Load(File.OpenRead("devel_test.xml"));
            var d = SqlDeployment.Load(x);
            var p = d.Compile(GetArgs());

            await new SqlDeploymentExecutor(p, l.CreateLogger <SqlDeploymentExecutor>()).ExecuteAsync();
        }
        public async Task Can_execute_local_test()
        {
            using var l = LoggerFactory.Create(builder => builder.AddConsole().SetMinimumLevel(LogLevel.Trace));
            var x = XDocument.Load(File.OpenRead("local_test.xml"));
            var d = SqlDeployment.Load(x);
            var p = d.Compile(GetArgs());

            await new SqlDeploymentExecutor(p, l.CreateLogger <SqlDeploymentExecutor>()).ExecuteAsync();

            var api = new MartinCostello.SqlLocalDb.SqlLocalDbApi();

            api.AutomaticallyDeleteInstanceFiles = true;
            api.StopInstance("SQL");
            api.StopInstance("EFM");
            api.DeleteInstance("SQL");
            api.DeleteInstance("EFM");
        }
Пример #4
0
        /// <summary>
        /// Executes the deployment.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <int> OnExecuteAsync(CancellationToken cancellationToken)
        {
            var manifest = Path.IsPathFullyQualified(Manifest) == false?Path.GetFullPath(Manifest, Environment.CurrentDirectory) : Manifest;

            if (File.Exists(manifest) == false)
            {
                logger.LogError("Could not find SQL Deployment manifest file: {Manifest}.", manifest);
                return(1);
            }

            // extract parameters
            var arguments = Arguments
                            .Select(i => i.Split(new[] { '=' }, 2))
                            .ToDictionary(i => i[0], i => i.Length > 1 ? i[1] : null);

            // load SQL deployment
            var deployment = SqlDeployment.Load(XDocument.Load(manifest, LoadOptions.SetBaseUri));

            try
            {
                // compile plan from manifest and parameters
                var plan = deployment.Compile(arguments, Path.GetDirectoryName(manifest));

                // execute plan with specified targets
                if (Targets.Count > 0)
                {
                    await new SqlDeploymentExecutor(plan, logger).ExecuteAsync(Targets.ToArray());
                }
                else
                {
                    await new SqlDeploymentExecutor(plan, logger).ExecuteAsync();
                }
            }
            catch (Exception e)
            {
                logger.LogError(e, "Unable to compile or execute SQL deployment.");
                return(1);
            }

            return(0);
        }
 public void Can_compile_local_test()
 {
     var x = XDocument.Load(File.OpenRead("local_test.xml"));
     var d = SqlDeployment.Load(x);
     var p = d.Compile(GetArgs());
 }
 public void Can_load_local_test()
 {
     var x = XDocument.Load(File.OpenRead("local_test.xml"));
     var d = SqlDeployment.Load(x);
 }