Sha256: 968835b00b2d6145bb7f57c3e70b584f7e1292d57791c9aac8ac9e4499800f46

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

#!/usr/bin/env ruby

#require 'optparse'

lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'flydata/table_def'

if `which mysqldump`.empty?
  abort "mysqldump is not installed."
end

# TODO Implement options instead of passing all to mysqldump.
=begin
opts = {}

op = OptionParser.new do |o|
  o.on('-h', '--host NAME', 'Connect to host.') do |v|
    opts[:host] = v
  end
  o.on('-P', '--port NUMBER', 'Port number to use for connection.') do |v|
    opts[:port] = v
  end
  o.on('-u', '--user NAME', 'User for login if not current user.') do |v|
    opts[:user] = v
  end
  o.on('-p', '--password [TEXT]', "Password to use when connecting to server.  If password is not given it's solicited on the tty.") do |v|
    opts[:password] = v
  end
end

op.parse!

=end
command = "mysqldump -d"

=begin
command += " -u#{opts[:user]}" if opts[:user]
command += " -h#{opts[:host]}" if opts[:host]
command += " -P#{opts[:port]}" if opts[:port]
command += " -p#{opts[:password]}" if opts[:password]
=end
command += " " + ARGV.join(' ')

IO.popen(command, 'r') do |io|
  create_flydata_ctl_table = true
  while !io.eof?
    mysql_tabledef = Flydata::Sync::MysqlTableDef.create(io)
    if mysql_tabledef.nil?
      # stream had no more create table definition
      break
    end
    flydata_tabledef = mysql_tabledef.to_flydata_tabledef
    puts Flydata::Sync::RedshiftTableDef.from_flydata_tabledef(flydata_tabledef, flydata_ctl_table: create_flydata_ctl_table)
    create_flydata_ctl_table = false
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flydata-0.1.0 bin/fdmysqldump