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))
                {
                    ExecuteMigration(migrationInfo.Migration, (m, c) => m.GetUpExpressions(c));

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

                    scope.Complete();

                    _stopWatch.Stop();

                    _announcer.Say(string.Format("{0} migrated", name));
                    _announcer.ElapsedTime(_stopWatch.ElapsedTime());
                }
            }
        }
Esempio n. 2
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;
                }
            }
        }