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);
        }
Exemple #2
0
        private static IEnumerable <IMigrationInfo> FindMigrations(
            [NotNull] IMigrationSource source,
            [NotNull] IMigrationRunnerConventions conventions,
            [CanBeNull] string @namespace,
            bool loadNestedNamespaces,
            [NotNull, ItemNotNull] IReadOnlyCollection <string> tagsToMatch)
        {
            var migrations = source.GetMigrations().ToList();

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

            var migrationInfos =
                (from migration in migrations
                 let type = migration.GetType()
                            where type.IsInNamespace(@namespace, loadNestedNamespaces)
                            where conventions.TypeHasMatchingTags(type, tagsToMatch) || (tagsToMatch.Count == 0 && !conventions.TypeHasTags(type)) || !conventions.TypeHasTags(type)
                            select conventions.GetMigrationInfoForMigration(migration));

            return(migrationInfos.ToList());
        }