protected override void Execute(UpdateStepContextWithPreconditions <UpdateDbStepType> context)
        {
            foreach (var statement in context.Step.AlternativeStatement)
            {
                _logger.LogInformation("Going to check whether statement for DbType={0} can be handled by this database", statement.DbType);

                if (!_databaseService.CanHandle(statement.DbType) && statement.DbType != "all")
                {
                    _logger.LogInformation("{0} for DbType={1} cannot be handled by this database", context, statement.DbType);

                    continue;
                }

                _transactionProvider.BeginTransaction();

                try
                {
                    foreach (var subStep in _scriptSplitter.SplitScript(statement.Value))
                    {
                        // TODO: add subcontext on script split?
                        _commandHandler.Execute(subStep);
                    }
                    _transactionProvider.CommitTransaction();
                }
                catch (Exception ex)
                {
                    // let's assume that the rollback is low chance to fail so we will not log the
                    // previous error first
                    _transactionProvider.RollbackTransaction();

                    throw new InvalidOperationException($"{context} failed with exception", ex);
                }
            }
        }
        public void ExecutedShouldReturnFalseIfStepWasNotExecutedYet(string assembly, string version, int step)
        {
            _transactionService.BeginTransaction();
            var checker = DefaultScope.ServiceProvider.GetService <IUpdateStepExecutedChecker>();

            _transactionService.CommitTransaction();

            Assert.That(checker.IsExecuted(assembly, version, step), Is.False);
        }
        public override void Setup()
        {
            base.Setup();

            Cleanup();

            // Setup DB
            var upgrader = DefaultScope.ServiceProvider.GetService <IDatabaseUpdater>();

            upgrader.ExecuteUpgrade();

            _transactionService = DefaultScope.ServiceProvider.GetService <IDatabaseServiceTransactionProvider>();

            _transactionService.BeginTransaction();
            var updateStepMarker = DefaultScope.ServiceProvider.GetService <IUpdateStepExecutedMarker>();

            updateStepMarker.MarkAsExecuted(ExistingAssembly, ExistingVersion, ExistingStep);
            _transactionService.CommitTransaction();
        }
        public void Execute(UpdateStepContextWithPreconditions context)
        {
            foreach (var updateStepHandler in _updateStepHandlers)
            {
                if (!updateStepHandler.CanHandle(context))
                {
                    continue;
                }

                _logger.LogInformation($"Going to execute {context}");

                updateStepHandler.Execute(context);

                _logger.LogInformation($"{context} was executed");

                if (context.Step.MarkAsExecuted)
                {
                    try
                    {
                        _transactionProvider.BeginTransaction();

                        _updateStepExecutedMarker.MarkAsExecuted(context.AssemblyName, context.UpdateVersion,
                                                                 context.StepNumber);

                        _logger.LogInformation($"{context} was marked as executed");

                        _transactionProvider.CommitTransaction();
                    }
                    catch (Exception ex)
                    {
                        _transactionProvider.RollbackTransaction();

                        throw new InvalidOperationException($"{context} couldn't be marked as executed", ex);
                    }
                }
            }
        }