/// <summary> /// Attempts to load a migrations assembly from the specified path and populate this object /// </summary> public async Task InitializeMigrationsAsync(string pathToMigrations) { Requires.NotNull(pathToMigrations, "pathToMigrations"); // Find files based on the specified glob var file = await _filesRepository.GetMostRecentMatchingFile(pathToMigrations); if (file == null) { throw new ProjectException("Path to migrations dll does not exist", null, this); } // Load migrations assembly MigrationsAssembly = await _assemblyRepository.LoadFromFile(file.FullName); if (MigrationsAssembly == null) { throw new ProjectException("Could not load any migrations from the specified file", null, this); } // Load referenced Fluent Migrator assembly FluentMigratorAssemblyName = await _assemblyRepository.GetReferenceByName(MigrationsAssembly, "FluentMigrator"); if (FluentMigratorAssemblyName == null) { throw new ProjectException("Could not find a reference to the FluentMigrator assembly", null, this); } // Find migration classes var migrationTypes = await _migrationsRepository.GetMigrationTypes(MigrationsAssembly); Migrations = migrationTypes.Select(m => new MigrationInfo(_migrationsRepository, _log, this, m)).ToList(); // Find profile classes var profileTypes = await _migrationsRepository.GetProfileTypes(MigrationsAssembly); Profiles = profileTypes.Select(p => new ProfileInfo(_migrationsRepository, _log, this, p)).ToList(); await Task.WhenAll(Migrations.Select(m => m.InitializeAsync())); await Task.WhenAll(Profiles.Select(p => p.InitializeAsync())); PathToMigrationsDll = pathToMigrations; _log.Info("Loaded {0} migrations and {1} profiles for project '{2}' from assembly {3}, which uses FluentMigrator {4}", Migrations.Count, Profiles.Count, Name, MigrationsAssembly.GetName().Name, FluentMigratorAssemblyName.Version.ToString()); }
/// <summary> /// Checks whether the specified connection parameters work /// </summary> public async Task InitializeDatabase(DatabaseType databaseType, string connectionString) { Requires.NotNull(connectionString, "connectionString"); var canConnectToDatabase = await _migrationsRepository.CanConnectToDatabase(databaseType, connectionString); if (!canConnectToDatabase) { throw new ProjectException("Could not connect to database", null, this); } await Task.WhenAll(Migrations.Select(m => m.InitializeAsync())); await Task.WhenAll(Profiles.Select(p => p.InitializeAsync())); DatabaseType = databaseType; ConnectionString = connectionString; IsDatabaseInitialized = true; _log.Info("Initialized {0} database connection for project '{1}'", databaseType.ToString(), Name); }