-fibrous = require 'fibrous'   # TODO remove me
 path = require 'path'
 fse = require 'fs-extra'
 redis = require 'redis'

      (next) =>
        @redisClient.smembers @setKey(), next
      (migrationsAlreadyRun, next) =>
        # TODO remove fibrous
        fibrous.run =>
          if migrationsAlreadyRun?.length
            lastMigrationName = migrationsAlreadyRun.sort()[migrationsAlreadyRun.length - 1]
          if not lastMigrationName
            throw new Error("No migrations found!")
          migration = @get(lastMigrationName)
          @log "Reversing migration `#{migration.name}`"
          migration.sync.down()
          return lastMigrationName
        , next

      (lastMigrationName, next) =>
        @redisClient.srem @setKey(), lastMigrationName, next



  # Generate a stub migration file
  generate: (name, done) ->
    name = "#{slugify name, '_'}"
    timestamp = (new Date()).toISOString().replace /\D/g, ''
    filename = "#{@opts.path}/#{timestamp}_#{name}.#{@opts.ext}"
    async.series [
      ((innerDone) => fse.mkdirp @opts.path, innerDone)
      ((innerDone) => fse.writeFile filename, @opts.template, innerDone)
    ], (err) =>
      return done(err) if err
      done(null, filename)
