private bool Migrate(MongoBackupStrategy backupStrategy, MongoMigrationStrategy migrationStrategy)
        {
            var currentSchema = _database
                                .GetCollection <SchemaDto>(_storageOptions.Prefix + ".schema")
                                .Find(_ => true)
                                .FirstOrDefault();

            if (currentSchema == null)
            {
                // We do not have a schema version yet
                // - assume an empty database and run full migrations
                currentSchema = new SchemaDto
                {
                    Version = MongoSchema.None
                };
            }

            if (RequiredSchemaVersion < currentSchema.Version)
            {
                var assemblyName = GetType().GetTypeInfo().Assembly.GetName();
                throw new InvalidOperationException(
                          $"{Environment.NewLine}{assemblyName.Name} version: {assemblyName.Version}, uses a schema prior to the current database." +
                          $"{Environment.NewLine}Backwards migration is not supported. Please resolve this manually (e.g. by dropping the database)." +
                          $"{Environment.NewLine}Please see https://github.com/sergeyzwezdin/Hangfire.Mongo#migration for further information.");
            }

            if (RequiredSchemaVersion == currentSchema.Version)
            {
                // Nothing to migrate - so let's get outta here.
                return(false);
            }

            if (backupStrategy == null)
            {
                throw new InvalidOperationException(
                          $"{Environment.NewLine}You need to choose a migration strategy by setting the {nameof(MongoStorageOptions)}.{nameof(MongoStorageOptions.MigrationOptions)} property." +
                          $"{Environment.NewLine}Please see https://github.com/sergeyzwezdin/Hangfire.Mongo#migration for further information.");
            }

            backupStrategy
            .Backup(_storageOptions, _database, currentSchema.Version, RequiredSchemaVersion);

            migrationStrategy
            .Execute(_storageOptions, _database, currentSchema.Version, RequiredSchemaVersion);

            return(true);
        }
 /// <summary>
 /// Constructs migration options with specific strategy.
 /// </summary>
 /// <param name="strategy">The migration strategy to use</param>
 public MongoMigrationOptions(MongoMigrationStrategy strategy)
 {
     Strategy       = strategy;
     BackupStrategy = MongoBackupStrategy.Collections;
     BackupPostfix  = "migrationbackup";
 }