Beispiel #1
0
        /// <summary>
        /// Scan for implementations of the IMigration interface in the provided assembly and order by name
        /// </summary>
        public void ReadAssemblyMigrations(Assembly migrationAssembly)
        {
            //
            foreach (var exportedType in migrationAssembly.ExportedTypes)
            {
                if (exportedType.GetTypeInfo().GetInterfaces().Contains(typeof(IMigration)))
                {
                    var previousMigration = (IMigration)Activator.CreateInstance(exportedType);
                    Migrations.Add(previousMigration);
                }
            }

            Migrations = Migrations.OrderBy(m => m.Name).ToList();
        }
        public async Task <ICollection <IMigration> > GetPendingMigrationsAsync()
        {
            var migrations          = Migrations.OrderBy(m => m.Version).ToList();
            var completedMigrations = await _migrationRepository.GetAllAsync(o => o.PageLimit(1000)).AnyContext();

            int max = 0;

            // if migrations have never run before, mark highest version as completed
            if (completedMigrations.Documents.Count == 0)
            {
                if (migrations.Count > 0)
                {
                    max = migrations.Where(m => m.Version.HasValue).Max(m => m.Version.Value);
                }

                await MarkMigrationCompleteAsync(max);

                return(new List <IMigration>());
            }

            int currentVersion = completedMigrations.Documents.Max(m => m.Version);

            return(migrations.Where(m => (m.Version.HasValue == false && ShouldRunUnversionedMigrations) || (m.Version.HasValue && m.Version > currentVersion)).ToList());
        }