require 'jcr-db/command'

module JCR
  module DB

    class SequelMigrateCommand
      include JCR::DB::Command

      def initialize(direction, migrations_path, options = {})
        switches = { '-m' => migrations_path }
        if options[:connection_string]
          switches['-t'] = options.delete(:connection_string)
        end
        if direction.to_s == 'down'
          switches['-M'] = options[:version] || 0
        end
        cmd_string = "bundle exec sequel --echo"
        switches_and_values = (switches.map do |(name, value)|
          "#{name} #{value}"
        end).sort.join(" ")
        super("#{cmd_string} #{switches_and_values}")
      end

    end

  end
end
