コード例 #1
0
        private static void RunScriptGroup(ScriptRunningGroup @group, Assembly migrationAssembly, IMigrationProcessor processor)
        {
            if (migrationAssembly == null)
            {
                migrationAssembly = typeof(MigrationManager).Assembly;
            }
            else
            {
                RunScriptGroup(@group, null, processor);
            }

            var           scriptGroups = GetEmbeddedScriptGroups(migrationAssembly);
            List <string> value;

            if (!scriptGroups.TryGetValue(@group, out value))
            {
                return;
            }

            foreach (
                var embeddedScript in
                value.Select(
                    script =>
                    new ExecuteEmbeddedSqlScriptExpression
            {
                SqlScript = script,
                MigrationAssemblies = new AssemblyCollection(new[] { migrationAssembly })
            }))
            {
                Announcer.Say(string.Format("Running {0}: {1}", @group, embeddedScript.SqlScript));
                embeddedScript.ExecuteWith(processor);
            }
        }
コード例 #2
0
        public void Up(IMigration migration)
        {
            var name = GetMigrationName(migration);

            _announcer.Heading(string.Format("{0} migrating", name));

            CaughtExceptions = new List <Exception>();

            var context = new MigrationContext(Conventions, Processor, MigrationAssembly, ApplicationContext);

            migration.GetUpExpressions(context);

            _stopWatch.Start();
            ExecuteExpressions(context.Expressions);
            _stopWatch.Stop();

            _announcer.Say(string.Format("{0} migrated", name));
            _announcer.ElapsedTime(_stopWatch.ElapsedTime());
        }
コード例 #3
0
        public void Up(IMigration migration)
        {
            var name = migration.GetType().Name;

            _announcer.Heading(name + ": migrating");

            CaughtExceptions = new List <Exception>();

            var context = new MigrationContext(Conventions, Processor, MigrationAssembly);

            migration.GetUpExpressions(context);

            _stopWatch.Start();
            ExecuteExpressions(context.Expressions);
            _stopWatch.Stop();

            _announcer.Say(name + ": migrated");
            _announcer.ElapsedTime(_stopWatch.ElapsedTime());
        }
コード例 #4
0
        private void OutputResults()
        {
            if (string.IsNullOrEmpty(ConnectionString))
            {
                throw new UndeterminableConnectionException("Unable to resolve any connectionstring using parameters \"/connection\" and \"/configPath\"");
            }

            announcer.Say(notUsingConfig
                              ? string.Format("Using Database {0} and Connection String {1}", database, matchPwd.Replace(ConnectionString, "$1********;"))
                              : string.Format("Using Connection {0} from Configuration file {1}", connection, configFile));
        }
コード例 #5
0
        public virtual void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction)
        {
            if (migrationInfo == null)
            {
                throw new ArgumentNullException("migrationInfo");
            }

            if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly)
            {
                _announcer.Heading("PREVIEW-ONLY MODE");
                _alreadyOutputPreviewOnlyModeWarning = true;
            }

            if (!migrationInfo.IsAttributed() || !VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version))
            {
                var name = migrationInfo.GetName();
                _announcer.Heading(string.Format("{0} migrating", name));

                _stopWatch.Start();

                using (IMigrationScope scope = _migrationScopeHandler.CreateOrWrapMigrationScope(useTransaction))
                {
                    try
                    {
                        if (migrationInfo.IsAttributed() && migrationInfo.IsBreakingChange &&
                            !RunnerContext.PreviewOnly && !RunnerContext.AllowBreakingChange)
                        {
                            throw new InvalidOperationException(
                                      string.Format(
                                          "The migration {0} is identified as a breaking change, and will not be executed unless the necessary flag (allow-breaking-changes|abc) is passed to the runner.",
                                          migrationInfo.GetName()));
                        }

                        ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c));

                        if (migrationInfo.IsAttributed())
                        {
                            VersionLoader.UpdateVersionInfo(migrationInfo.Version, migrationInfo.Description ?? migrationInfo.Migration.GetType().Name);
                        }

                        scope.Complete();
                    }
                    catch
                    {
                        if (useTransaction && scope.IsActive)
                        {
                            scope.Cancel();  // SQLAnywhere needs explicit call to rollback transaction
                        }
                        throw;
                    }

                    _stopWatch.Stop();

                    _announcer.Say(string.Format("{0} migrated", name));
                    _announcer.ElapsedTime(_stopWatch.ElapsedTime());
                }
            }
        }
コード例 #6
0
        private void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction)
        {
            if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly)
            {
                _announcer.Heading("PREVIEW-ONLY MODE");
                _alreadyOutputPreviewOnlyModeWarning = true;
            }

            if (!VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version))
            {
                var name = GetMigrationName(migrationInfo);
                _announcer.Heading(string.Format("{0} migrating", name));

                try
                {
                    _stopWatch.Start();

                    if (useTransaction)
                    {
                        Processor.BeginTransaction();
                    }

                    ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c));
                    VersionLoader.UpdateVersionInfo(migrationInfo.Version);

                    if (useTransaction)
                    {
                        Processor.CommitTransaction();
                    }

                    _stopWatch.Stop();

                    _announcer.Say(string.Format("{0} migrated", name));
                    _announcer.ElapsedTime(_stopWatch.ElapsedTime());
                }
                catch (Exception)
                {
                    if (useTransaction)
                    {
                        Processor.RollbackTransaction();
                    }
                    throw;
                }
            }
        }
コード例 #7
0
        public virtual void ApplyMigrationUp(IMigrationInfo migrationInfo, bool useTransaction)
        {
            if (migrationInfo == null)
            {
                throw new ArgumentNullException("migrationInfo");
            }

            if (!_alreadyOutputPreviewOnlyModeWarning && Processor.Options.PreviewOnly)
            {
                _announcer.Heading("PREVIEW-ONLY MODE");
                _alreadyOutputPreviewOnlyModeWarning = true;
            }

            if (!migrationInfo.IsAttributed() || !VersionLoader.VersionInfo.HasAppliedMigration(migrationInfo.Version))
            {
                var name = migrationInfo.GetName();
                _announcer.Heading(string.Format("{0} migrating", name));

                _stopWatch.Start();

                using (IMigrationScope scope = _migrationScopeHandler.CreateOrWrapMigrationScope(useTransaction))
                {
                    try
                    {
                        ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c));

                        if (migrationInfo.IsAttributed())
                        {
                            VersionLoader.UpdateVersionInfo(migrationInfo.Version, migrationInfo.Description ?? migrationInfo.Migration.GetType().Name);
                        }

                        scope.Complete();
                    }
                    catch
                    {
                        if (useTransaction && scope.IsActive)
                        {
                            scope.Cancel();  // SQLAnywhere needs explicit call to rollback transaction
                        }
                        throw;
                    }

                    _stopWatch.Stop();

                    _announcer.Say(string.Format("{0} migrated", name));
                    _announcer.ElapsedTime(_stopWatch.ElapsedTime());
                }
            }
        }
コード例 #8
0
 public static void Say(this IAnnouncer announcer, string message, params object[] args)
 {
     announcer.Say(string.Format(message, args));
 }
コード例 #9
0
        public void Say_Should_Say_string_formatted_message()
        {
            Mock.Get(announcer).Setup(a => a.Say("Hello Say"));

            announcer.Say("Hello {0}", "Say");
        }
コード例 #10
0
 /// <inheritdoc />
 protected override void WriteSay(string message)
 {
     _announcer.Say(message);
 }
コード例 #11
0
        public void SayShouldSayStringFormattedMessage()
        {
            Mock.Get(_announcer).Setup(a => a.Say("Hello Say"));

            _announcer.Say("Hello {0}", "Say");
        }