public DefaultMigrationRecordStore( IDocumentStore store, MigrationOptions options) { this.store = store; this.options = options; }
public virtual void Setup( IDocumentStore documentStore, MigrationOptions options, ILogger logger) { DocumentStore = documentStore; Database = options.Database; Logger = logger; }
/// <summary> /// Adds a Raven <see cref="MigrationRunner"/> singleton to the dependency injection services using the specified <see cref="IDocumentStore"/>. /// </summary> /// <param name="services">The dependency injection container.</param> /// <returns>A <see cref="MigrationRunner"/> which can be used to run the pending migrations.</returns> public static IServiceCollection AddRavenDbMigrations(this IServiceCollection services, IDocumentStore docStore, Action <MigrationOptions> configuration = null) { var options = new MigrationOptions(); configuration?.Invoke(options); if (options.Assemblies.Count == 0) { options.Assemblies.Add(Assembly.GetCallingAssembly()); } return(services.AddSingleton(provider => new MigrationRunner(docStore, options, provider.GetRequiredService <ILogger <MigrationRunner> >()))); }
private static MigrationRunner CreateMigrationRunnerFromProvider(IServiceProvider provider, Assembly callingAssembly, Action <MigrationOptions> configuration = null, IDocumentStore store = null) { var migrationResolver = new DependencyInjectionMigrationResolver(provider); var options = new MigrationOptions(migrationResolver); configuration?.Invoke(options); if (options.Assemblies.Count == 0) { // No assemblies configured? Use the assembly that called .AddRavenDbMigrations. options.Assemblies.Add(callingAssembly); } var docStore = store ?? provider.GetRequiredService <IDocumentStore>(); var logger = provider.GetRequiredService <ILogger <MigrationRunner> >(); return(new MigrationRunner(docStore, options, logger)); }
/// <summary> /// Returns all migrations found within all assemblies and orders them by the direction /// </summary> /// <param name="options"></param> /// <returns></returns> private static IEnumerable <MigrationWithAttribute> FindAllMigrationsWithOptions(MigrationOptions options) { var migrationsToRun = from assembly in options.Assemblies from t in assembly.GetLoadableTypes() where typeof(Migration).IsAssignableFrom(t) && !t.IsAbstract && t.GetConstructor(Type.EmptyTypes) != null select new MigrationWithAttribute { Migration = () => options.MigrationResolver.Resolve(t), Attribute = t.GetMigrationAttribute() } into migration where IsInCurrentMigrationProfile(migration, options) select migration; // if we are going down, we want to run it in reverse return(options.Direction == Directions.Down ? migrationsToRun.OrderByDescending(x => x.Attribute.Version) : migrationsToRun.OrderBy(x => x.Attribute.Version)); }
public MigrationRunner(IDocumentStore docStore, MigrationOptions options, ILogger <MigrationRunner> logger) { this.docStore = docStore ?? throw new ArgumentNullException(nameof(docStore)); this.options = options ?? throw new ArgumentNullException(nameof(options)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
private static bool IsInCurrentMigrationProfile(MigrationWithAttribute migrationWithAttribute, MigrationOptions options) { if (migrationWithAttribute.Attribute == null) { throw new InvalidOperationException("Subclasses of Migration that can be instantiated must have the MigrationAttribute." + "If this class was intended as a base class for other migrations, make it an abstract class."); } //If no particular profiles have been set, then the migration is //effectively a part of all profiles var profiles = migrationWithAttribute.Attribute.Profiles; if (profiles.Any() == false) { return(true); } //The migration must belong to at least one of the currently //specified profiles return(options.Profiles .Intersect(migrationWithAttribute.Attribute.Profiles, StringComparer.OrdinalIgnoreCase) .Any()); }
/// <summary> /// Returns all migrations found within all assemblies and orders them by the direction /// </summary> /// <param name="options"></param> /// <returns></returns> private static IEnumerable <MigrationWithAttribute> FindAllMigrationsWithOptions(MigrationOptions options) { var zanz = (from assembly in options.Assemblies from t in assembly.GetLoadableTypes() where options.Conventions.TypeIsMigration(t) select t).ToList(); var migrationsToRun = from assembly in options.Assemblies from t in assembly.GetLoadableTypes() where options.Conventions.TypeIsMigration(t) select new MigrationWithAttribute { Migration = () => options.MigrationResolver.Resolve(t), Attribute = t.GetMigrationAttribute() } into migration where IsInCurrentMigrationProfile(migration, options) select migration; // if we are going down, we want to run it in reverse return(options.Direction == Directions.Down ? migrationsToRun.OrderByDescending(x => x.Attribute.Version) : migrationsToRun.OrderBy(x => x.Attribute.Version)); }