예제 #1
0
        public MigrationRunner(IAssemblyCollection assemblies, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssemblies = assemblies;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;
            RunnerContext = runnerContext;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;

            _migrationScopeHandler = new MigrationScopeHandler(Processor);
            _migrationValidator = new MigrationValidator(_announcer, Conventions);
            MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
            MaintenanceLoader = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions);

            if (runnerContext.NoConnection){
                VersionLoader = new ConnectionlessVersionLoader(this, _migrationAssemblies, Conventions, runnerContext.StartVersion, runnerContext.Version);
            }
            else{
                VersionLoader = new VersionLoader(this, _migrationAssemblies, Conventions);
            }
        }
예제 #2
0
        private MigrationRunner CreateRunner(MigrationDb db, out StringBuilder output)
        {
            var sb = output = new StringBuilder();

            var announcer = new TextWriterAnnouncer(s =>
            {
                if (sb.Length == 0)
                {
                    sb.AppendLine();
                }

                sb.Append(s);
            });

            IMigrationProcessorFactory factory   = CreateFactory(db.DatabaseServer);
            IMigrationProcessor        processor = factory.Create(db.ConnectionString, announcer, new MigrationOptions(db));

            var context = new RunnerContext(announcer)
            {
                Namespace          = db.NamespaceContainingMigrations,
                ApplicationContext = _kernel
            };

            return(new MigrationRunner(db.Assembly, context, processor));
        }
 public override void ExecuteWith(IMigrationProcessor processor)
 {
     // since all the Processors are using String.Format() in their Execute method
     //  we need to escape the brackets with double brackets or else it throws an incorrect format error on the String.Format call
     var sqlText = SqlStatement.Replace("{", "{{").Replace("}", "}}");
     processor.Execute(sqlText);
 }
        private void ExecuteProcessor(IMigrationProcessor migrationProcessor, CancellationToken cancellationToken)
        {
            _logService.Info($"Executing {migrationProcessor}");

            try
            {
                var lastSyncVersion = _syncRepository.GetSyncParams().LastSyncVersion;
                if (lastSyncVersion.HasValue && lastSyncVersion > 0)
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        migrationProcessor.Process(cancellationToken);
                    }
                }
            }
            catch (FatalException)
            {
                throw;
            }
            catch (Exception ex)
            {
                _logService.Error("Error occurred. Sleeping before trying again", ex);
            }

            _logService.Info($"{migrationProcessor} executed");
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            var exp = new PerformDBOperationExpression()
            {
                Operation = (connection, transaction) =>
                {
                    var helper = new ReferenceListDbHelper(connection, transaction);
                    var id     = helper.GetReferenceListId(Namespace, Name);
                    if (id == null)
                    {
                        return;
                    }

                    if (Description.IsSet)
                    {
                        helper.UpdateReferenceListDescription(id, Description.Value);
                    }
                    if (NoSelectionValue.IsSet)
                    {
                        helper.UpdateReferenceListNoSelectionValue(id, NoSelectionValue.Value);
                    }
                }
            };

            processor.Process(exp);
        }
예제 #6
0
        public MigrationRunner(IAssemblyCollection assemblies, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssemblies  = assemblies;
            _announcer            = runnerContext.Announcer;
            Processor             = processor;
            _stopWatch            = runnerContext.StopWatch;
            ApplicationContext    = runnerContext.ApplicationContext;
            TransactionPerSession = runnerContext.TransactionPerSession;

            SilentlyFail     = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
            {
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;
            }

            _migrationScopeHandler = new MigrationScopeHandler(Processor);
            _migrationValidator    = new MigrationValidator(_announcer, Conventions);
            MigrationLoader        = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader          = new ProfileLoader(runnerContext, this, Conventions);
            MaintenanceLoader      = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions);

            if (runnerContext.NoConnection)
            {
                VersionLoader = new ConnectionlessVersionLoader(this, _migrationAssemblies, Conventions, runnerContext.StartVersion, runnerContext.Version);
            }
            else
            {
                VersionLoader = new VersionLoader(this, _migrationAssemblies, Conventions);
            }
        }
예제 #7
0
        internal FxVersionLoader(IMigrationRunner runner, IAssemblyCollection assemblies,
                                 IConventionSet conventionSet,
                                 IMigrationRunnerConventions conventions,
                                 IRunnerContext runnerContext,
                                 IVersionTableMetaData versionTableMetaData = null,
                                 string resource = "")
        {
            _conventionSet = conventionSet;
            _processor     = runner.Processor;

            Runner     = runner;
            Assemblies = assemblies;

            Conventions                 = conventions;
            VersionTableMetaData        = versionTableMetaData ?? CreateVersionTableMetaData(runnerContext);
            VersionMigration            = new VersionMigration(VersionTableMetaData);
            VersionSchemaMigration      = new VersionSchemaMigration(VersionTableMetaData);
            VersionUniqueMigration      = new VersionUniqueMigration(VersionTableMetaData);
            VersionDescriptionMigration = new VersionDescriptionMigration(VersionTableMetaData);
            VersionResourceMigration    = new VersionResourceMigration(VersionTableMetaData);

            VersionTableMetaData.ApplicationContext = runnerContext.ApplicationContext;

            Resource = resource;

            LoadVersionInfo();
        }
예제 #8
0
        internal ConnectionlessVersionLoader(
            IMigrationRunner runner,
            IAssemblyCollection assemblies,
            IConventionSet conventionSet,
            IMigrationRunnerConventions conventions,
            IRunnerContext runnerContext,
            IVersionTableMetaData versionTableMetaData = null)
        {
            _migrationInformationLoader = runner.MigrationLoader;
            _processor = runner.Processor;

            Runner        = runner;
            Assemblies    = assemblies;
            Conventions   = conventions;
            StartVersion  = runnerContext.StartVersion;
            TargetVersion = runnerContext.Version;

            VersionInfo          = new VersionInfo();
            VersionTableMetaData = versionTableMetaData ??
                                   (IVersionTableMetaData)Activator.CreateInstance(assemblies.Assemblies.GetVersionTableMetaDataType(
                                                                                       Conventions, runnerContext));
            VersionMigration            = new VersionMigration(VersionTableMetaData);
            VersionSchemaMigration      = new VersionSchemaMigration(VersionTableMetaData);
            VersionUniqueMigration      = new VersionUniqueMigration(VersionTableMetaData);
            VersionDescriptionMigration = new VersionDescriptionMigration(VersionTableMetaData);

            if (VersionTableMetaData is DefaultVersionTableMetaData defaultMetaData)
            {
                conventionSet.SchemaConvention?.Apply(defaultMetaData);
            }

            LoadVersionInfo();
        }
예제 #9
0
 public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
     : this(new List<MigrationAssemblyInfo>() { new MigrationAssemblyInfo() { Assembly = assembly , Namespace = runnerContext.Namespace} }, 
         runnerContext, 
         processor,
         false)
 {
 }
예제 #10
0
        public FxVersionLoader(
            IProcessorAccessor processorAccessor,
            IConventionSet conventionSet,
            IMigrationRunnerConventions conventions,
            IVersionTableMetaData versionTableMetaData,
            IMigrationRunner runner,
            string resource = "")
        {
            _conventionSet = conventionSet;
            _processor     = processorAccessor.Processor;

            Runner = runner;

            Conventions                 = conventions;
            VersionTableMetaData        = versionTableMetaData;
            VersionMigration            = new VersionMigration(VersionTableMetaData);
            VersionSchemaMigration      = new VersionSchemaMigration(VersionTableMetaData);
            VersionUniqueMigration      = new VersionUniqueMigration(VersionTableMetaData);
            VersionDescriptionMigration = new VersionDescriptionMigration(VersionTableMetaData);
            VersionResourceMigration    = new VersionResourceMigration(VersionTableMetaData);

            Resource = resource;

            LoadVersionInfo();
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            var exp = new PerformDBOperationExpression()
            {
                Operation = (connection, transaction) =>
                {
                    var helper = new NotificationDbHelper(connection, transaction);

                    if (TemplateId.HasValue)
                    {
                        helper.DeleteNotificationTemplate(TemplateId.Value);
                    }
                    else if (DeleteAll)
                    {
                        var templateId = helper.GetNotificationId(Namespace, Name);
                        if (templateId == null)
                        {
                            throw new Exception($"Reference list '{Namespace}.{Name}' not found");
                        }

                        // delete all if filter is not specified
                        helper.DeleteNotificationTemplates(Namespace, Name);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
            };

            processor.Process(exp);
        }
 public TransactionalMigrationScope(IMigrationProcessor migrationProcessor, Action disposalAction)
     : base(disposalAction)
 {
     if (migrationProcessor == null) throw new ArgumentNullException("migrationProcessor");
     _migrationProcessor = migrationProcessor;
     _migrationProcessor.BeginTransaction();
 }
예제 #13
0
 public MigrationRunner(
     IAssemblyCollection assemblies, IRunnerContext runnerContext,
     IMigrationProcessor processor, IVersionTableMetaData versionTableMetaData = null,
     IMigrationRunnerConventions migrationRunnerConventions = null)
     : this(assemblies, runnerContext, processor, versionTableMetaData, migrationRunnerConventions, conventionSet : null)
 {
 }
예제 #14
0
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            var exp = new PerformDBOperationExpression()
            {
                Operation = (connection, transaction) =>
                {
                    var helper = new ReferenceListDbHelper(connection, transaction);

                    var refListId = helper.GetReferenceListId(Namespace, Name);
                    if (refListId == null)
                    {
                        throw new Exception($"Reference list '{Namespace}.{Name}' not found");
                    }

                    if (DeleteAll)
                    {
                        // delete all if filter is not specified
                        helper.DeleteReferenceListItems(Namespace, Name);
                    }
                    else
                    if (ItemValue.HasValue)
                    {
                        helper.DeleteReferenceListItem(Namespace, Name, ItemValue.Value);
                    }
                }
            };

            processor.Process(exp);
        }
예제 #15
0
 public MigrationRunner(
     [NotNull] IAssemblyCollection assemblies, [NotNull] IRunnerContext runnerContext,
     [NotNull] IMigrationProcessor processor, IVersionTableMetaData versionTableMetaData = null,
     [CanBeNull] IMigrationRunnerConventions migrationRunnerConventions = null)
     : this(assemblies, runnerContext, processor, versionTableMetaData, migrationRunnerConventions, conventionSet : null, migrationScopeHandler : null)
 {
 }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            // since all the Processors are using String.Format() in their Execute method
            //  we need to escape the brackets with double brackets or else it throws an incorrect format error on the String.Format call
            var sqlText = SqlStatement.Replace("{", "{{").Replace("}", "}}");

            processor.Execute(sqlText);
        }
예제 #17
0
 public MigrationContext(IMigrationConventions conventions, IMigrationProcessor migrationProcessor, Assembly migrationAssembly)
 {
     Conventions = conventions;
     Expressions = new List<IMigrationExpression>();
     QuerySchema = migrationProcessor;
     PreviewOnly = migrationProcessor.Options.PreviewOnly;
     MigrationAssembly = migrationAssembly;
 }
        public override void ExecuteWith( IMigrationProcessor processor )
        {
            string sqlText;
            using (var reader = File.OpenText(SqlScript))
                sqlText = reader.ReadToEnd();

            processor.Execute(sqlText);
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            string sqlText;

            using (var reader = File.OpenText(SqlScript))
                sqlText = reader.ReadToEnd();

            processor.Execute(sqlText);
        }
예제 #20
0
        public ValidatingVersionLoader(
            IProcessorAccessor processorAccessor, IConventionSet conventionSet, IMigrationRunnerConventions conventions,
            IVersionTableMetaData versionTableMetaData, IMigrationRunner runner
            ) : base(processorAccessor, conventionSet, conventions, versionTableMetaData, runner)
        {
            m_processor = processorAccessor.Processor;

            LoadVersionInfo();
        }
예제 #21
0
 public MigrationRunner(IMigrationConventions conventions, IMigrationProcessor processor, IAnnouncer announcer, IStopWatch stopWatch)
 {
     _announcer = announcer;
     SilentlyFail = false;
     CaughtExceptions = null;
     Conventions = conventions;
     Processor = processor;
     _stopWatch = stopWatch;
 }
예제 #22
0
        private static MigrationRunner SetupMigrationRunner(IMigrationProcessor processor)
        {
            Assembly asm           = typeof(MigrationRunnerTests).Assembly;
            var      runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
            {
                Namespace = "FluentMigrator.Tests.Integration.Migrations"
            };

            return(new MigrationRunner(asm, runnerContext, processor));
        }
 public MigrationVersionRunner(IMigrationConventions conventions, IMigrationProcessor processor, IMigrationLoader loader, Assembly assembly, string @namespace)
 {
     _migrationConventions = conventions;
     _migrationProcessor = processor;
     _migrationAssembly = assembly;
     _migrationLoader = loader;
     _namespace = @namespace;
     _migrationRunner = new MigrationRunner(conventions, processor);
        _versionMigration = new VersionMigration();
 }
예제 #24
0
 public TransactionalMigrationScope(IMigrationProcessor migrationProcessor, Action disposalAction)
     : base(disposalAction)
 {
     if (migrationProcessor == null)
     {
         throw new ArgumentNullException("migrationProcessor");
     }
     _migrationProcessor = migrationProcessor;
     _migrationProcessor.BeginTransaction();
 }
        public override void ExecuteWith( IMigrationProcessor processor )
        {
            string sqlText;
            using (var reader = File.OpenText(SqlScript))
                sqlText = reader.ReadToEnd();

            // since all the Processors are using String.Format() in their Execute method
            //  we need to escape the brackets with double brackets or else it throws an incorrect format error on the String.Format call
            sqlText = sqlText.Replace("{", "{{").Replace("}", "}}");
            processor.Execute(sqlText);
        }
예제 #26
0
        private void RunMigration(Action <MigrationRunner> runAction)
        {
            Announcer announcer = CreateAnnouncer();

            using (IMigrationProcessor processor = CreateMigrationProcessor(announcer))
            {
                IRunnerContext migrationContext = new RunnerContext(announcer);
                var            runner           = new MigrationRunner(_migrationAssembly, migrationContext, processor);
                runAction(runner);
            }
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            var exp = new PerformDBOperationExpression()
            {
                Operation = (connection, transaction) => {
                    var helper    = new NotificationDbHelper(connection, transaction);
                    var refListId = helper.InsertNotification(Namespace, Name, Description);
                }
            };

            processor.Process(exp);
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            string sqlText;

            using (var reader = File.OpenText(SqlScript))
                sqlText = reader.ReadToEnd();

            // since all the Processors are using String.Format() in their Execute method
            //  we need to escape the brackets with double brackets or else it throws an incorrect format error on the String.Format call
            sqlText = sqlText.Replace("{", "{{").Replace("}", "}}");
            processor.Execute(sqlText);
        }
 public MigrationVersionRunner(IMigrationConventions conventions, IMigrationProcessor processor, IMigrationLoader loader, Assembly assembly, string @namespace, IAnnouncer announcer)
 {
     _migrationConventions = conventions;
     _migrationProcessor = processor;
     _migrationAssembly = assembly;
     _migrationLoader = loader;
     _namespace = @namespace;
     _announcer = announcer;
     _migrationRunner = new MigrationRunner(conventions, processor, announcer, new StopWatch());
     _versionTableMetaData = loader.GetVersionTableMetaData(assembly);
     _versionMigration = new VersionMigration(_versionTableMetaData);
 }
        private static int CountRowsWith(string countSql, IMigrationProcessor processor, params object[] args)
        {
            var result = processor.Read(countSql, args);

            Assert.That(result.Tables.Count, Is.GreaterThan(0));
            var table = result.Tables[0];

            Assert.That(table.Rows.Count, Is.GreaterThan(0));
            var row = table.Rows[0];

            Assert.IsTrue(table.Columns.Contains("TheCount"));
            return(Convert.ToInt32(row["TheCount"]));
        }
예제 #31
0
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            var exp = new PerformDBOperationExpression()
            {
                Operation = (connection, transaction) =>
                {
                    var helper = new NotificationDbHelper(connection, transaction);

                    var notificationId = helper.GetNotificationId(Namespace, Name);
                    if (notificationId == null)
                    {
                        throw new Exception($"Notification '{Namespace}.{Name}' not found");
                    }

                    if (!Template.Id.IsSet)
                    {
                        Template.Id.Set(Guid.NewGuid());
                    }
                    var templateId = Template.Id.Value;

                    helper.InsertNotificationTemplate(notificationId.Value, Template);

                    if (Template.Name.IsSet)
                    {
                        helper.UpdateTemplateName(templateId, Template.Name.Value);
                    }
                    if (Template.Subject.IsSet)
                    {
                        helper.UpdateTemplateSubject(templateId, Template.Subject.Value);
                    }
                    if (Template.Body.IsSet)
                    {
                        helper.UpdateTemplateBody(templateId, Template.Body.Value);
                    }
                    if (Template.BodyFormat.IsSet)
                    {
                        helper.UpdateTemplateBodyFormat(templateId, Template.BodyFormat.Value);
                    }
                    if (Template.SendType.IsSet)
                    {
                        helper.UpdateTemplateSendType(templateId, Template.SendType.Value);
                    }
                    if (Template.IsEnabled.IsSet)
                    {
                        helper.UpdateTemplateIsEnabled(templateId, Template.IsEnabled.Value);
                    }
                }
            };

            processor.Process(exp);
        }
예제 #32
0
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            var exp = new PerformDBOperationExpression()
            {
                Operation = (connection, transaction) =>
                {
                    var helper = new NotificationDbHelper(connection, transaction);
                    helper.DeleteNotificationTemplates(Namespace, Name);
                    helper.DeleteNotification(Namespace, Name);
                }
            };

            processor.Process(exp);
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            var exp = new PerformDBOperationExpression()
            {
                Operation = (connection, transaction) =>
                {
                    var helper = new ReferenceListDbHelper(connection, transaction);
                    helper.DeleteReferenceListItems(Namespace, Name);
                    helper.DeleteReferenceList(Namespace, Name);
                }
            };

            processor.Process(exp);
        }
예제 #34
0
        private IMigrationProcessor CreateMigrationProcessor(Announcer announcer)
        {
            var options = new ProcessorOptions
            {
                PreviewOnly = false,                 // set to true to see the SQL
                Timeout     = 60,
            };

            EnsureConnectionAvailable(_connectionString);

            var factory = new SqlServer2012ProcessorFactory();
            IMigrationProcessor processor = factory.Create(_connectionString, announcer, options);

            return(processor);
        }
예제 #35
0
        public void Migrate()
        {
            var announcer = new TextWriterAnnouncer(Console.Out)
            {
                ShowElapsedTime = true,
                ShowSql         = true
            };

            IRunnerContext migrationContext = new RunnerContext(announcer);

            var factory = new SQLiteProcessorFactory();
            IMigrationProcessor processor = factory.Create(_connectionString, announcer, new ProcessorOptions());
            var runner = new MigrationRunner(typeof(Migrator).Assembly, migrationContext, processor);

            runner.MigrateUp(true);
        }
예제 #36
0
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            string sqlText;
            string embeddedResourceName = GetQualifiedResourcePath();

            using (var stream = MigrationAssembly.GetManifestResourceStream(embeddedResourceName))
                using (var reader = new StreamReader(stream))
                {
                    sqlText = reader.ReadToEnd();
                }

            // since all the Processors are using String.Format() in their Execute method
            //  we need to escape the brackets with double brackets or else it throws an incorrect format error on the String.Format call
            sqlText = sqlText.Replace("{", "{{").Replace("}", "}}");
            processor.Execute(sqlText);
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            string sqlText;
            string embeddedResourceName = GetQualifiedResourcePath();

            using (var stream = MigrationAssembly.GetManifestResourceStream(embeddedResourceName))
            using (var reader = new StreamReader(stream))
            {
                sqlText = reader.ReadToEnd();
            }

            // since all the Processors are using String.Format() in their Execute method
            //  we need to escape the brackets with double brackets or else it throws an incorrect format error on the String.Format call
            sqlText = sqlText.Replace("{", "{{").Replace("}", "}}");
            processor.Execute(sqlText);
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            string sqlText;
            var    embeddedResourceNameWithAssembly = GetQualifiedResourcePath();

            using (var stream = embeddedResourceNameWithAssembly
                                .Assembly.GetManifestResourceStream(embeddedResourceNameWithAssembly.Name))
                using (var reader = new StreamReader(stream))
                {
                    sqlText = reader.ReadToEnd();
                }

            sqlText = SqlScriptTokenReplacer.ReplaceSqlScriptTokens(sqlText, Parameters);

            processor.Execute(sqlText);
        }
예제 #39
0
        public MigrationRunner(
            [NotNull] IAssemblyCollection assemblies, [NotNull] IRunnerContext runnerContext,
            [NotNull] IMigrationProcessor processor, [CanBeNull] IVersionTableMetaData versionTableMetaData,
            [CanBeNull] IMigrationRunnerConventions migrationRunnerConventions, [CanBeNull] IConventionSet conventionSet,
            [CanBeNull] IMigrationScopeManager migrationScopeHandler = null)
        {
            _migrationAssemblies = assemblies;
            _logger           = new AnnouncerFluentMigratorLogger(runnerContext.Announcer);
            _stopWatch        = runnerContext.StopWatch;
            _processorOptions = new ProcessorOptions(runnerContext);

            Processor     = processor;
            RunnerContext = runnerContext;

            var migrationRunnerConventionsAccessor = new AssemblySourceMigrationRunnerConventionsAccessor(
                serviceProvider: null,
                new AssemblySource(() => assemblies));

            Conventions = migrationRunnerConventions ?? migrationRunnerConventionsAccessor.MigrationRunnerConventions;

            var convSet = conventionSet ?? new DefaultConventionSet(runnerContext);

            _migrationScopeManager = migrationScopeHandler ?? new MigrationScopeHandler(Processor);
            _migrationValidator    = new MigrationValidator(_logger, convSet);
            MigrationLoader        = new DefaultMigrationInformationLoader(Conventions, _migrationAssemblies,
                                                                           runnerContext.Namespace,
                                                                           runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader     = new ProfileLoader(runnerContext, this, Conventions);
            MaintenanceLoader = new MaintenanceLoader(_migrationAssemblies, runnerContext.Tags, Conventions);

            if (runnerContext.NoConnection)
            {
                _versionLoader = new Lazy <IVersionLoader>(
                    () => new ConnectionlessVersionLoader(
                        this,
                        _migrationAssemblies,
                        convSet,
                        Conventions,
                        runnerContext,
                        versionTableMetaData));
            }
            else
            {
                _versionLoader = new Lazy <IVersionLoader>(
                    () => new VersionLoader(this, _migrationAssemblies, convSet, Conventions, runnerContext, versionTableMetaData));
            }
        }
예제 #40
0
        public Migrator(string connectionString, params Assembly[] assemblies)
        {
            var announcer = new TextWriterAnnouncer(Console.Write);

            IAssemblyCollection assemblyCollection = new AssemblyCollection(assemblies);

            var migrationContext = new RunnerContext(announcer);

            var options = new MigrationOptions {
                PreviewOnly = false, Timeout = 60
            };
            PostgresProcessorFactory factory = new PostgresProcessorFactory();

            IMigrationProcessor processor = factory.Create(connectionString, announcer, options);

            runner = new MigrationRunner(assemblyCollection, migrationContext, processor);
        }
예제 #41
0
        public void Update()
        {
            IAnnouncer       announcer        = CreateAnnouncer();
            IRunnerContext   migrationContext = new RunnerContext(announcer);
            ProcessorOptions options          = new ProcessorOptions {
                PreviewOnly = false, Timeout = 200
            };
            IMigrationProcessorFactory factory = new SqlServer2008ProcessorFactory();
            Assembly migrationContainer        = typeof(InitialDeployment).Assembly;

            using (IMigrationProcessor processor = factory.Create(connectionString, announcer, options))
            {
                FluentMigrator.Runner.IMigrationRunner runner = new FluentMigrator.Runner.MigrationRunner(migrationContainer, migrationContext, processor);

                runner.MigrateUp();
            }
        }
예제 #42
0
        public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssembly = assembly;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;

            VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions);
            MigrationLoader = new MigrationLoader(Conventions, _migrationAssembly, runnerContext.Namespace);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
        }
예제 #43
0
        public MigrationRunner(ICollection<MigrationAssemblyInfo> assemblyInfos, IRunnerContext runnerContext, IMigrationProcessor processor, bool loadNestedNamespaces)
        {
            _migrationAssemblies = assemblyInfos;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;
            ApplicationContext = runnerContext.ApplicationContext;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;

            VersionLoader = new VersionLoader(this, assemblyInfos, Conventions);
            MigrationLoader = new MigrationLoader(Conventions, assemblyInfos, loadNestedNamespaces , runnerContext.Tags);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            string sqlText;
            string embeddedResourceName = GetQualifiedResourcePath(SqlScript);

            if (string.IsNullOrEmpty(embeddedResourceName))
            {
                throw new ArgumentNullException(string.Format("Could find resource named {0} in assembly {1}",SqlScript,MigrationAssembly.FullName));
            }

            using (var stream = MigrationAssembly.GetManifestResourceStream(embeddedResourceName))
            {
                using (var reader = new StreamReader(stream))
                {
                    sqlText = reader.ReadToEnd();
                }
            }

            processor.Execute(sqlText);
        }
        public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssembly = assembly;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();

            ProcessWorkingDirectory(runnerContext);

            ProcessAutoReverse(runnerContext);

            VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions);
            MigrationLoader = new MigrationLoader(Conventions, _migrationAssembly, runnerContext.Namespace);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
        }
        public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
        {
            _migrationAssembly = assembly;
            _announcer = runnerContext.Announcer;
            Processor = processor;
            _stopWatch = runnerContext.StopWatch;
            ApplicationContext = runnerContext.ApplicationContext;
            TransactionPerSession = runnerContext.TransactionPerSession;

            SilentlyFail = false;
            CaughtExceptions = null;

            Conventions = new MigrationConventions();
            if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
                Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;

            _migrationScopeHandler = new MigrationScopeHandler(Processor);
            _migrationValidator = new MigrationValidator(_announcer, Conventions);
            VersionLoader = new VersionLoader(this, _migrationAssembly, Conventions);
            MigrationLoader = new DefaultMigrationInformationLoader(Conventions, _migrationAssembly, runnerContext.Namespace, runnerContext.NestedNamespaces, runnerContext.Tags);
            ProfileLoader = new ProfileLoader(runnerContext, this, Conventions);
        }
        public override void ExecuteWith(IMigrationProcessor processor)
        {
            string sqlText;
            using (var reader = File.OpenText(SqlScript))
                sqlText = reader.ReadToEnd();

            // since all the Processors are using String.Format() in their Execute method
            //	1) we need to escape the brackets with double brackets or else it throws an incorrect format error on the String.Format call
            //	2) we need to replace tokens
            //	3) we need to replace escaped tokens
            sqlText = Regex.Replace(
                Regex.Replace(
                    sqlText.Replace("{", "{{").Replace("}", "}}"),
                    @"\$\((?<token>\w+)\)",
                    m => ((Parameters != null) && Parameters.ContainsKey(m.Groups["token"].Value))
                        ? Parameters[m.Groups["token"].Value]
                        : ""),
                @"\${2}\({2}(?<token>\w+)\){2}",
                m => string.Format("$({0})", m.Groups["token"]));

            // adding ability to pass parameters to execute function
            processor.Execute(sqlText);
        }
        private void runMigrationsInNamespace(IMigrationProcessor processor, string @namespace)
        {
            var runner = new MigrationVersionRunner(_conventions, processor, new MigrationLoader(_conventions), typeof(MigrationVersionRunnerTests).Assembly, @namespace);

            runner.MigrateUp();
        }
예제 #49
0
 internal virtual IMigrationRunner GenerateRunner(IRunnerContext context, IMigrationProcessor processor)
 {
     return new MigrationRunner(_assembly, context, processor);
 }
 public MigrationVersionRunner(IMigrationConventions conventions, IMigrationProcessor processor, IMigrationLoader loader, IAnnouncer announcer)
     : this(conventions, processor, loader, Assembly.GetCallingAssembly(), null, announcer)
 {
 }
 protected override ISchemaDumper GetSchemaDumper(IMigrationProcessor processor)
 {
     return new OracleSchemaDumper((OracleProcessor)processor, Announcer);
 }
 public abstract void ExecuteWith(IMigrationProcessor processor);
 public override void ExecuteWith(IMigrationProcessor processor)
 {
     Column.TableName = TableName;
     processor.Process(this);
 }
 public override void ExecuteWith(IMigrationProcessor processor)
 {
     processor.Execute(SqlStatement);
 }
 private void CreateProcessor()
 {
     IMigrationProcessorFactory processorFactory = ProcessorFactory.GetFactory(ProcessorType);
     Processor = processorFactory.Create(Connection);
 }
 public override void ExecuteWith(IMigrationProcessor processor)
 {
     processor.Process(this);
 }
예제 #57
0
 public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
     : this(new[] { assembly }, runnerContext, processor)
 {
 }
예제 #58
0
 private static MigrationRunner BuildMigrationRunner(Assembly migrationAssembly, IRunnerContext runnerContext, IMigrationProcessor processor)
 {
     var migrationRunner = new MigrationRunner(migrationAssembly, runnerContext, processor);
     return migrationRunner;
 }
        private static MigrationRunner SetupMigrationRunner(IMigrationProcessor processor)
        {
            Assembly asm = typeof(MigrationRunnerTests).Assembly;
            var runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
            {
                Namespace = "FluentMigrator.Tests.Integration.Migrations"
            };

            return new MigrationRunner(asm, runnerContext, processor);
        }
 public MigrationVersionRunner(IMigrationConventions conventions, IMigrationProcessor processor, IMigrationLoader loader, Type getAssemblyByType, IAnnouncer announcer)
     : this(conventions, processor, loader, getAssemblyByType.Assembly, null, announcer)
 {
 }