Exemplo n.º 1
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)
 {
 }
Exemplo n.º 2
0
 public MigrationRunner(
     IAssemblyCollection assemblies, IRunnerContext runnerContext,
     IMigrationProcessor processor, IVersionTableMetaData versionTableMetaData = null,
     IMigrationRunnerConventions migrationRunnerConventions = null)
     : this(assemblies, runnerContext, processor, versionTableMetaData, migrationRunnerConventions, conventionSet : null)
 {
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProfileSource"/> class.
 /// </summary>
 /// <param name="source">The assembly source</param>
 /// <param name="conventions">The migration runner conventios</param>
 public ProfileSource(
     [NotNull] IFilteringMigrationSource source,
     [NotNull] IMigrationRunnerConventions conventions)
 {
     _source      = source;
     _conventions = conventions;
 }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
 public MigrationSource(
     [NotNull] IAssemblySource source,
     [NotNull] IMigrationRunnerConventions conventions)
 {
     _source      = source;
     _conventions = conventions;
 }
Exemplo n.º 7
0
        public MigrationManager(
            IFilteringMigrationSource filteringMigrationSource,
            IMigrationRunner migrationRunner,
            IMigrationRunnerConventions migrationRunnerConventions,
            IMigrationContext migrationContext,
            ITypeFinder typeFinder,
            IVersionLoader versionLoader)
        {
            _typeMapping = new Dictionary <Type, Action <ICreateTableColumnAsTypeSyntax> >()
            {
                [typeof(int)]      = c => c.AsInt32(),
                [typeof(string)]   = c => c.AsString(int.MaxValue).Nullable(),
                [typeof(bool)]     = c => c.AsBoolean(),
                [typeof(decimal)]  = c => c.AsDecimal(18, 4),
                [typeof(DateTime)] = c => c.AsDateTime2(),
                [typeof(byte[])]   = c => c.AsBinary(int.MaxValue),
                [typeof(Guid)]     = c => c.AsGuid()
            };

            _filteringMigrationSource   = filteringMigrationSource;
            _migrationRunner            = migrationRunner;
            _migrationRunnerConventions = migrationRunnerConventions;
            _migrationContext           = migrationContext;
            _typeFinder    = typeFinder;
            _versionLoader = versionLoader;
        }
Exemplo n.º 8
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();
        }
Exemplo n.º 9
0
 public ProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, IMigrationRunnerConventions conventions)
 {
     _runner          = runner;
     _conventions     = conventions;
     _serviceProvider = null;
     Profiles         = FindProfilesIn(runner.MigrationAssemblies, runnerContext.Profile).ToList();
 }
 public MigrationSource(
     [NotNull] IAssemblySource source,
     [NotNull] IMigrationRunnerConventions conventions)
 {
     _source      = source;
     _conventions = conventions;
     _sourceItems = Enumerable.Empty <IMigrationSourceItem>();
 }
Exemplo n.º 11
0
        public ProfileLoader(IRunnerContext runnerContext, IMigrationRunner runner, IMigrationRunnerConventions conventions)
        {
            Runner      = runner;
            Assemblies  = runner.MigrationAssemblies;
            Profile     = runnerContext.Profile;
            Conventions = conventions;

            Initialize();
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProfileSource"/> class.
 /// </summary>
 /// <param name="source">The assembly source</param>
 /// <param name="conventions">The migration runner conventios</param>
 /// <param name="serviceProvider">The service provider</param>
 public MigrationSource(
     [NotNull] IAssemblySource source,
     [NotNull] IMigrationRunnerConventions conventions,
     [NotNull] IServiceProvider serviceProvider)
 {
     _source          = source;
     _conventions     = conventions;
     _serviceProvider = serviceProvider;
 }
 /// <summary>
 /// Sets the migration runner conventions
 /// </summary>
 /// <param name="builder">The runner builder</param>
 /// <param name="conventions">The migration runner conventions</param>
 /// <returns>The runner builder</returns>
 public static IMigrationRunnerBuilder WithRunnerConventions(
     this IMigrationRunnerBuilder builder,
     IMigrationRunnerConventions conventions)
 {
     builder.Services
     .AddSingleton <IMigrationRunnerConventionsAccessor>(
         new PassThroughMigrationRunnerConventionsAccessor(conventions));
     return(builder);
 }
Exemplo n.º 14
0
        public ValidatingVersionLoader(
            IProcessorAccessor processorAccessor, IConventionSet conventionSet, IMigrationRunnerConventions conventions,
            IVersionTableMetaData versionTableMetaData, IMigrationRunner runner
            ) : base(processorAccessor, conventionSet, conventions, versionTableMetaData, runner)
        {
            m_processor = processorAccessor.Processor;

            LoadVersionInfo();
        }
Exemplo n.º 15
0
 public DefaultMigrationInformationLoader(IMigrationRunnerConventions conventions, IAssemblyCollection assemblies, string @namespace,
                                          bool loadNestedNamespaces, IEnumerable <string> tagsToMatch)
 {
     Conventions          = conventions;
     Assemblies           = assemblies;
     Namespace            = @namespace;
     LoadNestedNamespaces = loadNestedNamespaces;
     TagsToMatch          = tagsToMatch ?? new string[] { };
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MigrationSourceFromItems"/> class.
 /// </summary>
 /// <param name="serviceProvider">The service provider</param>
 /// <param name="conventions">The runner conventions</param>
 /// <param name="sourceItems">The items to get the candidate types from</param>
 public MigrationSourceFromItems(
     [NotNull] IServiceProvider serviceProvider,
     [NotNull] IMigrationRunnerConventions conventions,
     [NotNull, ItemNotNull] IEnumerable <IMigrationSourceItem> sourceItems)
 {
     _serviceProvider = serviceProvider;
     _conventions     = conventions;
     _sourceItems     = sourceItems.ToList();
 }
Exemplo n.º 17
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)
 {
 }
Exemplo n.º 18
0
 internal FxVersionLoader(
     IMigrationRunner runner,
     Assembly assembly,
     IConventionSet conventionSet,
     IMigrationRunnerConventions conventions,
     IRunnerContext runnerContext)
     : this(runner, new SingleAssembly(assembly), conventionSet, conventions, runnerContext)
 {
 }
 public AggregateMigrationInfoLoader(
     IMigrationContext migrationContext,
     IMigrationSource source,
     IOptionsSnapshot <TypeFilterOptions> filterOptions,
     IMigrationRunnerConventions conventions,
     IOptions <RunnerOptions> runnerOptions)
     : base(source, filterOptions, conventions, runnerOptions)
 {
     this.myMigrationContext = migrationContext;
 }
Exemplo n.º 20
0
 public DefaultMigrationInformationLoader(IMigrationRunnerConventions conventions, IAssemblyCollection assemblies, string @namespace,
                                          bool loadNestedNamespaces, IEnumerable <string> tagsToMatch)
 {
     Conventions          = conventions;
     Assemblies           = assemblies;
     Namespace            = @namespace;
     LoadNestedNamespaces = loadNestedNamespaces;
     _tagsToMatch         = tagsToMatch as IReadOnlyCollection <string> ?? tagsToMatch?.ToArray() ?? Array.Empty <string>();
     _source = new MigrationSource(new AssemblySource(() => assemblies), conventions);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProfileSource"/> class.
 /// </summary>
 /// <param name="source">The assembly source</param>
 /// <param name="conventions">The migration runner conventios</param>
 /// <param name="serviceProvider">The service provider</param>
 /// <param name="sourceItems">The additional migration source items</param>
 public MigrationSource(
     [NotNull] IAssemblySource source,
     [NotNull] IMigrationRunnerConventions conventions,
     [NotNull] IServiceProvider serviceProvider,
     [NotNull, ItemNotNull] IEnumerable <IMigrationSourceItem> sourceItems)
 {
     _source          = source;
     _conventions     = conventions;
     _serviceProvider = serviceProvider;
     _sourceItems     = sourceItems;
 }
Exemplo n.º 22
0
        public MigrationManager(
            IFilteringMigrationSource filteringMigrationSource,
            IMigrationRunner migrationRunner,
            IMigrationRunnerConventions migrationRunnerConventions)
        {
            _versionLoader = new Lazy <IVersionLoader>(() => EngineContext.Current.Resolve <IVersionLoader>());

            _filteringMigrationSource   = filteringMigrationSource;
            _migrationRunner            = migrationRunner;
            _migrationRunnerConventions = migrationRunnerConventions;
        }
Exemplo n.º 23
0
        public MigrationManager(
            IFilteringMigrationSource filteringMigrationSource,
            IMigrationRunner migrationRunner,
            IMigrationRunnerConventions migrationRunnerConventions,
            Lazy <IVersionLoader> versionLoader)
        {
            _versionLoader = versionLoader;

            _filteringMigrationSource   = filteringMigrationSource;
            _migrationRunner            = migrationRunner;
            _migrationRunnerConventions = migrationRunnerConventions;
        }
Exemplo n.º 24
0
 public DefaultMigrationInformationLoader(
     [NotNull] IMigrationSource source,
     [NotNull] IOptions <TypeFilterOptions> filterOptions,
     [NotNull] IMigrationRunnerConventions conventions,
     [NotNull] IOptions <RunnerOptions> runnerOptions)
 {
     _source              = source;
     Namespace            = filterOptions.Value.Namespace;
     LoadNestedNamespaces = filterOptions.Value.NestedNamespaces;
     Conventions          = conventions;
     _tagsToMatch         = runnerOptions.Value.Tags ?? Array.Empty <string>();
 }
        private static IEnumerable <IMigrationInfo> FindMigrations(
#pragma warning disable 618
            [NotNull] IMigrationSource source,
#pragma warning restore 618
            [NotNull] IMigrationRunnerConventions conventions,
            [CanBeNull] string @namespace,
            bool loadNestedNamespaces,
            [NotNull, ItemNotNull] IReadOnlyCollection <string> tagsToMatch)
        {
            bool IsMatchingMigration(Type type)
            {
                if (!type.IsInNamespace(@namespace, loadNestedNamespaces))
                {
                    return(false);
                }
                if (!conventions.TypeIsMigration(type))
                {
                    return(false);
                }
                return(conventions.TypeHasMatchingTags(type, tagsToMatch) ||
                       (tagsToMatch.Count == 0 && !conventions.TypeHasTags(type)) ||
                       !conventions.TypeHasTags(type));
            }

            IReadOnlyCollection <IMigration> migrations;

            if (source is IFilteringMigrationSource filteringSource)
            {
                migrations = filteringSource.GetMigrations(IsMatchingMigration).ToList();
            }
            else
            {
                migrations =
                    (from migration in source.GetMigrations()
                     where IsMatchingMigration(migration.GetType())
                     select migration).ToList();
            }

            if (migrations.Count == 0)
            {
                throw new MissingMigrationsException("No migrations found");
            }

            var migrationInfos = migrations
                                 .Select(conventions.GetMigrationInfoForMigration)
                                 .ToList();

            return(migrationInfos);
        }
Exemplo n.º 26
0
        public DefaultMigrationInformationLoader(
#pragma warning disable 618
            [NotNull] IMigrationSource source,
#pragma warning restore 618
            [NotNull] IOptionsSnapshot <TypeFilterOptions> filterOptions,
            [NotNull] IMigrationRunnerConventions conventions,
            [NotNull] IOptions <RunnerOptions> runnerOptions)
        {
            _source                    = source;
            Namespace                  = filterOptions.Value.Namespace;
            LoadNestedNamespaces       = filterOptions.Value.NestedNamespaces;
            Conventions                = conventions;
            _tagsToMatch               = runnerOptions.Value.Tags ?? Array.Empty <string>();
            _includeUntaggedMigrations = runnerOptions.Value.IncludeUntaggedMigrations;
        }
Exemplo n.º 27
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));
            }
        }
Exemplo n.º 28
0
        public VersionLoader(IMigrationRunner runner, IAssemblyCollection assemblies,
                             IConventionSet conventionSet,
                             IMigrationRunnerConventions conventions,
                             IVersionTableMetaData versionTableMetaData = null)
        {
            _conventionSet = conventionSet;
            Runner         = runner;
            Processor      = runner.Processor;
            Assemblies     = assemblies;

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

            LoadVersionInfo();
        }
Exemplo n.º 29
0
        /// <summary>
        /// Returns a value indicating whether the type matches the given tag list.
        /// </summary>
        /// <param name="conventions">The conventions to use.</param>
        /// <param name="type">The type to validate.</param>
        /// <param name="tagsList">The list of tags to check against.</param>
        /// <param name="includeUntagged">Allow untagged entries.</param>
        /// <returns><see langword="true"/> when the requested tags match the tags attached to the type.</returns>
        public static bool HasRequestedTags(
            this IMigrationRunnerConventions conventions,
            Type type,
            string[] tagsList,
            bool includeUntagged)
        {
            if (tagsList.Length > 0)
            {
                if (includeUntagged)
                {
                    return(conventions.TypeHasMatchingTags(type, tagsList) ||
                           !conventions.TypeHasTags(type));
                }

                return(conventions.TypeHasMatchingTags(type, tagsList));
            }

            return(!conventions.TypeHasTags(type));
        }
Exemplo n.º 30
0
        public VersionLoader(
            [NotNull] IProcessorAccessor processorAccessor,
            [NotNull] IConventionSet conventionSet,
            [NotNull] IMigrationRunnerConventions conventions,
            [NotNull] IVersionTableMetaData versionTableMetaData,
            [NotNull] IMigrationRunner runner)
        {
            _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);

            LoadVersionInfo();
        }