protected override void OnSetup()
        {
            var config = new ScriptDeployerConfig
            {
                DatabaseLookup      = "select 'model' [name]",
                ProjectsTableConfig = new ProjectsTableConfig
                {
                    Database = "master", CreateTable = "print 'done'", Insert = "print 'done'",
                    Read     = "select '14.12.01.01' -- {0}"
                },
                ValidationFilterConfig = new ValidationFilterConfig()
            };

            Given.Config = config;

            Then.Logger  = new Logger();
            Then.LogSink = new StringLogSink();
            Then.Logger.AddLogSink(Then.LogSink);
            var manager = new SqlConnectionManager(Given.Config.DatabaseLookup);

            manager.OpenConnection(".", "model");
            manager.BeginTransaction();

            Then.Manager = manager;
        }
예제 #2
0
        public RunnerResolution Go()
        {
            var commit = false;

            using (var connectionManager = new SqlConnectionManager(_config.DatabaseLookup))
            {
                RunnerResolution resolution;

                try
                {
                    LogOptions();

                    _logger.PostEntry("opening connection to server", _settings.Server);
                    connectionManager.OpenConnection(_settings.Server, "master");

                    if (_settings.UseTransaction)
                    {
                        _logger.PostEntry("BEGINNING TRANSACTION");
                        connectionManager.BeginTransaction();
                    }

                    var checker = _settings.BypassCheck ? null : CreateChecker();
                    var project = LoadProject(CreateParser(), checker);
                    if (_settings.CheckFilesOnly)
                    {
                        return(RunnerResolution.ValidationOnly);
                    }

                    DeployScripts(_config, project, connectionManager);

                    commit = _settings.ShouldRollback == false;
                }
                catch (RunnerException rex)
                {
                    _logger.PostEntryNoTimestamp(string.Empty);
                    _logger.PostEntry("<<< ERROR >>> {0}", rex.Message);
                    return(rex.RunnerResolution);
                }
                catch (Exception ex)
                {
                    _logger.PostException(ex);
                    return(RunnerResolution.ExceptionThrown);
                }
                finally
                {
                    resolution = ResolveTransaction(commit, connectionManager);
                }

                return(resolution);
            }
        }