예제 #1
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();
        }
예제 #2
0
 public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
     : this(new List<MigrationAssemblyInfo>() { new MigrationAssemblyInfo() { Assembly = assembly , Namespace = runnerContext.Namespace} }, 
         runnerContext, 
         processor,
         false)
 {
 }
 public ConnectionlessProcessor(IMigrationGenerator generator, IRunnerContext context, IMigrationProcessorOptions options)
 {
     Generator = generator;
     Context = context;
     Announcer = Context.Announcer;
     Options = options;
 }
예제 #4
0
        public TaskExecutor(IRunnerContext runnerContext)
        {
            if (runnerContext == null)
                throw new ArgumentNullException("runnerContext", "RunnerContext cannot be null");

            RunnerContext = runnerContext;
        }
예제 #5
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();
        }
        public AnnouncingHtmlOutputUrlProcessor(
            IValidatorWrapper validator,
            IRunnerContext context,
            IFileNameGenerator fileNameGenerator,
            ResourceCopier resourceCopier,
            IValidatorReportWriterFactory reportWriterFactory,
            IStreamFactory streamFactory,
            IHtmlIndexFileWriter htmlIndexFileWriter)
        {
            if (validator == null)
                throw new ArgumentNullException("validator");
            if (context == null)
                throw new ArgumentNullException("context");
            if (fileNameGenerator == null)
                throw new ArgumentNullException("fileNameGenerator");
            if (resourceCopier == null)
                throw new ArgumentNullException("resourceCopier");
            if (reportWriterFactory == null)
                throw new ArgumentNullException("reportWriterFactory");
            if (streamFactory == null)
                throw new ArgumentNullException("streamFactory");
            if (htmlIndexFileWriter == null)
                throw new ArgumentNullException("htmlIndexFileWriter");

            this.mValidator = validator;
            this.mContext = context;
            this.mFileNameGenerator = fileNameGenerator;
            this.mResourceCopier = resourceCopier;
            this.mReportWriterFactory = reportWriterFactory;
            this.mStreamFactory = streamFactory;
            this.mHtmlIndexFileWriter = htmlIndexFileWriter;
        }
예제 #7
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)
 {
 }
예제 #8
0
 public ConnectionlessProcessor(IMigrationGenerator generator, IRunnerContext context, IMigrationProcessorOptions options)
 {
     Generator = generator;
     Context   = context;
     Announcer = Context.Announcer;
     Options   = options;
 }
예제 #9
0
 public void SetUp()
 {
     _runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
     {
         Namespace = "FluentMigrator.Tests.Integration.Migrations"
     };
 }
예제 #10
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);
            }
        }
예제 #11
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);
            }
        }
예제 #12
0
 public ProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, IMigrationRunnerConventions conventions)
 {
     _runner          = runner;
     _conventions     = conventions;
     _serviceProvider = null;
     Profiles         = FindProfilesIn(runner.MigrationAssemblies, runnerContext.Profile).ToList();
 }
예제 #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 void SetUp()
 {
     _runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                                 {
                                     Namespace = "FluentMigrator.Tests.Integration.Migrations"
                                 };
 }
 public ConnectionlessProcessorFactory(
     [NotNull] IGeneratorAccessor generatorAccessor,
     [NotNull] IRunnerContext runnerContext)
 {
     _generator  = generatorAccessor.Generator;
     _databaseId = runnerContext.Database;
     Name        = _generator.GetName();
 }
예제 #16
0
        public ProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, IMigrationRunnerConventions conventions)
        {
            Runner      = runner;
            Assemblies  = runner.MigrationAssemblies;
            Profile     = runnerContext.Profile;
            Conventions = conventions;

            Initialize();
        }
예제 #17
0
        public TaskExecutor(IRunnerContext runnerContext)
        {
            if (runnerContext == null)
            {
                throw new ArgumentNullException("runnerContext", "RunnerContext cannot be null");
            }

            RunnerContext = runnerContext;
        }
예제 #18
0
        public ProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, IMigrationConventions conventions, bool isBeforeProfile)
        {
            Runner = runner;
            Assembly = runner.MigrationAssembly;
            Profile = isBeforeProfile ? runnerContext.BeforeProfile : runnerContext.Profile;
            Conventions = conventions;

            Initialize();
        }
예제 #19
0
 internal VersionLoader(
     [NotNull] IMigrationRunner runner,
     [NotNull] Assembly assembly,
     [NotNull] IConventionSet conventionSet,
     [NotNull] IMigrationRunnerConventions conventions,
     [NotNull] IRunnerContext runnerContext)
     : this(runner, new SingleAssembly(assembly), conventionSet, conventions, runnerContext)
 {
 }
예제 #20
0
        public TaskExecutor(IRunnerContext runnerContext, AssemblyLoaderFactory assemblyLoaderFactory, MigrationProcessorFactoryProvider processorFactoryProvider)
        {
            if (runnerContext == null) throw new ArgumentNullException("runnerContext");
            if (assemblyLoaderFactory == null) throw new ArgumentNullException("assemblyLoaderFactory");

            RunnerContext = runnerContext;
            AssemblyLoaderFactory = assemblyLoaderFactory;
            ProcessorFactoryProvider = processorFactoryProvider;
        }
예제 #21
0
        public ProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, IEnumerable<Assembly> assemblies, IMigrationConventions conventions)
        {
            Runner = runner;
            Assemblies = assemblies.ToList();
            Profile = runnerContext.Profile;
            Conventions = conventions;

            Initialize();
        }
예제 #22
0
        public ProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, IMigrationConventions conventions)
        {
            Runner = runner;
            Assembly = runner.MigrationAssembly;
            Profile = runnerContext.Profile;
            Conventions = conventions;

            Initialize();
        }
예제 #23
0
 internal FxVersionLoader(
     IMigrationRunner runner,
     Assembly assembly,
     IConventionSet conventionSet,
     IMigrationRunnerConventions conventions,
     IRunnerContext runnerContext)
     : this(runner, new SingleAssembly(assembly), conventionSet, conventions, runnerContext)
 {
 }
예제 #24
0
 public void SetValuesFrom(IRunnerContext runnerContext)
 {
     PreviewOnly = runnerContext.PreviewOnly;
     Timeout     = runnerContext.Timeout == null
         ? null
         : (TimeSpan?)TimeSpan.FromSeconds(runnerContext.Timeout.Value);
     ProviderSwitches = runnerContext.ProviderSwitches;
     ConnectionString = runnerContext.Connection;
 }
예제 #25
0
 public void SetUp()
 {
     _runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
     {
         Database   = "sqlserver",
         Target     = GetType().Assembly.Location,
         Connection = IntegrationTestOptions.SqlServer.ConnectionString,
         Namespace  = "FluentMigrator.Tests.Integration.Migrations"
     };
 }
예제 #26
0
 public TaskExecutor(
     [NotNull] IRunnerContext runnerContext,
     [CanBeNull] IConnectionStringProvider connectionStringProvider,
     [NotNull] AssemblyLoaderFactory assemblyLoaderFactory,
     // ReSharper disable once UnusedParameter.Local
     MigrationProcessorFactoryProvider factoryProvider)
     : this(
         runnerContext,
         assemblyLoaderFactory,
         connectionStringProvider)
 {
 }
예제 #27
0
 public ConnectionlessProcessor(
     IMigrationGenerator generator,
     IRunnerContext context,
     IMigrationProcessorOptions options)
 {
     _logger        = new AnnouncerFluentMigratorLogger(context.Announcer);
     _legacyOptions = options;
     DatabaseType   = context.Database;
     Generator      = generator;
     Announcer      = context.Announcer;
     Options        = options.GetProcessorOptions(connectionString: null);
 }
예제 #28
0
        private IMigrationRunnerConventions GetMigrationRunnerConventions(IRunnerContext runnerContext)
        {
            var matchedType = _migrationAssemblies
                              .GetExportedTypes()
                              .FirstOrDefault(t => typeof(IMigrationRunnerConventions).IsAssignableFrom(t));

            if (matchedType != null)
            {
                return((IMigrationRunnerConventions)Activator.CreateInstance(matchedType));
            }

            return(new MigrationRunnerConventions());
        }
예제 #29
0
 public void SetValuesFrom(IRunnerContext runnerContext)
 {
     Task                  = runnerContext.Task;
     Version               = runnerContext.Version;
     StartVersion          = runnerContext.StartVersion;
     Steps                 = runnerContext.Steps;
     Profile               = runnerContext.Profile;
     Tags                  = runnerContext.Tags?.ToArray();
     AllowBreakingChange   = runnerContext.AllowBreakingChange;
     TransactionPerSession = runnerContext.TransactionPerSession;
     ApplicationContext    = runnerContext.ApplicationContext;
     NoConnection          = runnerContext.NoConnection;
 }
예제 #30
0
        public TaskExecutor(IRunnerContext runnerContext, AssemblyLoaderFactory assemblyLoaderFactory, MigrationProcessorFactoryProvider processorFactoryProvider)
        {
            if (runnerContext == null)
            {
                throw new ArgumentNullException("runnerContext");
            }
            if (assemblyLoaderFactory == null)
            {
                throw new ArgumentNullException("assemblyLoaderFactory");
            }

            RunnerContext            = runnerContext;
            AssemblyLoaderFactory    = assemblyLoaderFactory;
            ProcessorFactoryProvider = processorFactoryProvider;
        }
예제 #31
0
        private IMigrationConventions GetMigrationConventions(IRunnerContext runnerContext)
        {
            Type matchedType = this._migrationAssemblies.GetExportedTypes().FirstOrDefault(t => typeof(IMigrationConventions).IsAssignableFrom(t));

            if (matchedType == null)
            {
                if (!string.IsNullOrEmpty(runnerContext.SchemaName))
                {
                    return(new MigrationConventionsWithDefaultSchema(runnerContext.SchemaName));
                }

                return(new MigrationConventions());
            }

            return((IMigrationConventions)Activator.CreateInstance(matchedType));
        }
예제 #32
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));
            }
        }
예제 #33
0
        public TaskExecutor([NotNull] IRunnerContext runnerContext)
        {
            var runnerCtxt = runnerContext ?? throw new ArgumentNullException(nameof(runnerContext));

            _logger        = new AnnouncerFluentMigratorLogger(runnerCtxt.Announcer);
            _runnerOptions = new RunnerOptions(runnerCtxt);
            var asmLoaderFactory = new AssemblyLoaderFactory();

            _assemblySource          = new AssemblySource(() => new AssemblyCollection(asmLoaderFactory.GetTargetAssemblies(runnerCtxt.Targets)));
            ConnectionStringProvider = new DefaultConnectionStringProvider();
            _lazyServiceProvider     = new Lazy <IServiceProvider>(
                () => runnerContext
                .CreateServices(
                    ConnectionStringProvider,
                    asmLoaderFactory)
                .BuildServiceProvider(validateScopes: true));
        }
예제 #34
0
        /// <summary>
        /// Loads the connection string using the connection string provider for the given assembly
        /// </summary>
        /// <param name="assemblies">The assembly to load the connection string from</param>
        /// <param name="connectionStringProvider">The connection string provider</param>
        /// <param name="runnerContext">The runner context</param>
        /// <returns>The found connection string</returns>
        public static string LoadConnectionString(
            this IReadOnlyCollection <Assembly> assemblies,
            IConnectionStringProvider connectionStringProvider,
            IRunnerContext runnerContext)
        {
            var singleAssembly         = assemblies.Count == 1 ? assemblies.Single() : null;
            var singleAssemblyLocation = singleAssembly != null ? singleAssembly.Location : string.Empty;

            var connectionString = connectionStringProvider.GetConnectionString(
                runnerContext.Announcer,
                runnerContext.Connection,
                runnerContext.ConnectionStringConfigPath,
                singleAssemblyLocation,
                runnerContext.Database);

            return(connectionString);
        }
예제 #35
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);
        }
예제 #36
0
        internal static IServiceCollection CreateServices(
            [NotNull] this IRunnerContext runnerContext,
            [CanBeNull] IConnectionStringProvider connectionStringProvider,
            [CanBeNull] AssemblyLoaderFactory defaultAssemblyLoaderFactory = null)
        {
            var services = new ServiceCollection();
            var assemblyLoaderFactory = defaultAssemblyLoaderFactory ?? new AssemblyLoaderFactory();

            if (!runnerContext.NoConnection && connectionStringProvider == null)
            {
                runnerContext.NoConnection = true;
            }

            // Configure the migration runner
            services
            .AddLogging(lb => lb.AddProvider(new LegacyFluentMigratorLoggerProvider(runnerContext.Announcer)))
            .AddFluentMigratorCore()
            .AddAllDatabases()
            .Configure <SelectingProcessorAccessorOptions>(opt => opt.ProcessorId = runnerContext.Database)
            .AddSingleton(assemblyLoaderFactory)
            .Configure <TypeFilterOptions>(
                opt =>
            {
                opt.Namespace        = runnerContext.Namespace;
                opt.NestedNamespaces = runnerContext.NestedNamespaces;
            })
            .Configure <AssemblySourceOptions>(opt => opt.AssemblyNames = runnerContext.Targets)
            .Configure <RunnerOptions>(
                opt => { opt.SetValuesFrom(runnerContext); })
            .Configure <ProcessorOptions>(opt => { opt.SetValuesFrom(runnerContext); })
            .Configure <AppConfigConnectionStringAccessorOptions>(
                opt => opt.ConnectionStringConfigPath = runnerContext.ConnectionStringConfigPath);

            // Configure the processor
            if (runnerContext.NoConnection)
            {
                // Always return the connectionless processor
                services
                .AddScoped <IProcessorAccessor, ConnectionlessProcessorAccessor>();
            }

            return(services);
        }
예제 #37
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);
        }
예제 #38
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);
        }
        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 DefaultConventionSet(IRunnerContext runnerContext)
        {
            var schemaConvention =
                new DefaultSchemaConvention(new DefaultSchemaNameConvention(runnerContext?.DefaultSchemaName));

            ColumnsConventions = new List <IColumnsConvention>()
            {
                new DefaultPrimaryKeyNameConvention(),
            };

            ConstraintConventions = new List <IConstraintConvention>()
            {
                new DefaultConstraintNameConvention(),
                schemaConvention,
            };

            ForeignKeyConventions = new List <IForeignKeyConvention>()
            {
                new DefaultForeignKeyNameConvention(),
                schemaConvention,
            };

            IndexConventions = new List <IIndexConvention>()
            {
                new DefaultIndexNameConvention(),
                schemaConvention,
            };

            SequenceConventions = new List <ISequenceConvention>()
            {
                schemaConvention,
            };

            AutoNameConventions = new List <IAutoNameConvention>()
            {
                new DefaultAutoNameConvention(),
            };

            SchemaConvention   = schemaConvention;
            RootPathConvention = new DefaultRootPathConvention(runnerContext?.WorkingDirectory);
        }
        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);
        }
예제 #42
0
        /// <summary>
        /// Find the version table meta data in the given assembly collection
        /// </summary>
        /// <param name="assemblies">The assembly collection</param>
        /// <param name="runnerConventions">The runner conventions used to identify a version table metadata type</param>
        /// <param name="runnerContext">The runner context defining the search boundaries for the custom version table metadata type</param>
        /// <returns>A custom or the default version table metadata instance</returns>
        public static Type GetVersionTableMetaDataType(
            [CanBeNull] this IEnumerable <Assembly> assemblies,
            [NotNull] IMigrationRunnerConventions runnerConventions,
            [NotNull] IRunnerContext runnerContext)
        {
            if (assemblies == null)
            {
                return(typeof(DefaultVersionTableMetaData));
            }

            var exportedTypes = assemblies.GetExportedTypes();

            var matchedType = exportedTypes
                              .FilterByNamespace(runnerContext.Namespace, runnerContext.NestedNamespaces)
                              .FirstOrDefault(t => runnerConventions.TypeIsVersionTableMetaData(t));

            if (matchedType == null)
            {
                return(typeof(DefaultVersionTableMetaData));
            }

            return(matchedType);
        }
예제 #43
0
        internal VersionLoader(IMigrationRunner runner, IAssemblyCollection assemblies,
                               [NotNull] IConventionSet conventionSet,
                               [NotNull] IMigrationRunnerConventions conventions,
                               [NotNull] IRunnerContext runnerContext,
                               [CanBeNull] IVersionTableMetaData versionTableMetaData = null)
        {
            _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);

            VersionTableMetaData.ApplicationContext = runnerContext.ApplicationContext;

            LoadVersionInfo();
        }
예제 #44
0
        public MigrationRunner(
            IAssemblyCollection assemblies, IRunnerContext runnerContext,
            IMigrationProcessor processor, IVersionTableMetaData versionTableMetaData,
            IMigrationRunnerConventions migrationRunnerConventions, IConventionSet conventionSet)
        {
            _migrationAssemblies = assemblies;
            _announcer           = runnerContext.Announcer;
            Processor            = processor;
            _stopWatch           = runnerContext.StopWatch;
            RunnerContext        = runnerContext;

            SilentlyFail     = false;
            CaughtExceptions = null;

            Conventions = migrationRunnerConventions ?? GetMigrationRunnerConventions(runnerContext);

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

            _migrationScopeHandler = new MigrationScopeHandler(Processor);
            _migrationValidator    = new MigrationValidator(_announcer, 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 ConnectionlessVersionLoader(
                    this, _migrationAssemblies, convSet, Conventions,
                    runnerContext.StartVersion, runnerContext.Version, versionTableMetaData);
            }
            else
            {
                VersionLoader = new VersionLoader(this, _migrationAssemblies, convSet, Conventions, versionTableMetaData);
            }
        }
예제 #45
0
        public void Execute(IRunnerContext runnerContext)
        {
            if (runnerContext == null)
                throw new ArgumentNullException("runnerContext", "RunnerContext cannot be null");

            RunnerContext = runnerContext;

            Initialize();

            switch (RunnerContext.Task)
            {
                case null:
                case "":
                case "migrate":
                case "migrate:up":
                    if (RunnerContext.Version != 0)
                        Runner.MigrateUp(RunnerContext.Version);
                    else
                        Runner.MigrateUp();
                    break;
                case "rollback":
                    if (RunnerContext.Steps == 0)
                        RunnerContext.Steps = 1;
                    Runner.Rollback(RunnerContext.Steps);
                    break;
                case "rollback:toversion":
                    Runner.RollbackToVersion(RunnerContext.Version);
                    break;
                case "rollback:all":
                    Runner.RollbackToVersion(0);
                    break;
                case "migrate:down":
                    Runner.MigrateDown(RunnerContext.Version);
                    break;
            }
        }
예제 #46
0
 internal virtual IMigrationRunner GenerateRunner(IRunnerContext context, IMigrationProcessor processor)
 {
     return new MigrationRunner(_assembly, context, processor);
 }
 /// <summary>Get a profile loader.</summary>
 /// <param name="runnerContext">The runner metadata.</param>
 /// <param name="runner">The runner which executes migrations.</param>
 /// <param name="conventions">The default rules for migration mappings.</param>
 public virtual IProfileLoader GetProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, IMigrationConventions conventions)
 {
     return new ProfileLoader(runnerContext, runner, conventions);
 }
예제 #48
0
 public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
     : this(new[] { assembly }, runnerContext, processor)
 {
 }
 private void ProcessAutoReverse(IRunnerContext runnerContext)
 {
     Conventions.GetAutoReverse = () => System.Convert.ToBoolean(runnerContext.AutoReverse);
 }
예제 #50
0
 public FakeTaskExecutor(IRunnerContext runnerContext, IMigrationRunner runner)
     : base(runnerContext)
 {
     this.runner = runner;
 }
 private void ProcessWorkingDirectory(IRunnerContext runnerContext)
 {
     if (!string.IsNullOrEmpty(runnerContext.WorkingDirectory))
         Conventions.GetWorkingDirectory = () => runnerContext.WorkingDirectory;
 }
예제 #52
0
 public ProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, Assembly assembly, IMigrationConventions conventions)
     : this(runnerContext, runner, new[] { assembly }, conventions)
 {
 }
 public void SetUp()
 {
     _runnerContext = new RunnerContext(new TextWriterAnnouncer(System.Console.Out))
                                 {
                                     Database = "sqlserver",
                                     Target = GetType().Assembly.Location,
                                     Connection = IntegrationTestOptions.SqlServer.ConnectionString,
                                     Namespace = "FluentMigrator.Tests.Integration.Migrations"
                                 };
 }
 public MockHtmlOutputUrlProcessor(
     IRunnerContext context,
     IValidatorWrapper validator,
     IValidatorReportWriterFactory reportWriterFactory,
     IFileNameGenerator fileNameGenerator,
     ResourceCopier resourceCopier,
     IStreamFactory streamFactory,
     IHtmlIndexFileWriter htmlIndexFileWriter)
 {
     this.mContext = context;
     this.mValidator = validator;
     this.mReportWriterFactory = reportWriterFactory;
     this.mFileNameGenerator = fileNameGenerator;
     this.mResourceCopier = resourceCopier;
     this.mStreamFactory = streamFactory;
     this.mHtmlIndexFileWriter = htmlIndexFileWriter;
 }
예제 #55
0
 public MigrationRunner(Assembly assembly, IRunnerContext runnerContext, IMigrationProcessor processor)
     : this(new SingleAssembly(assembly), runnerContext, processor)
 {
 }
예제 #56
0
 public TaskExecutor(IRunnerContext runnerContext)
     : this(runnerContext, new AssemblyLoaderFactory(), new MigrationProcessorFactoryProvider())
 {
 }
예제 #57
0
 private static MigrationRunner BuildMigrationRunner(Assembly migrationAssembly, IRunnerContext runnerContext, IMigrationProcessor processor)
 {
     var migrationRunner = new MigrationRunner(migrationAssembly, runnerContext, processor);
     return migrationRunner;
 }