#!/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::TableDef::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::TableDef::RedshiftTableDef.from_flydata_tabledef(flydata_tabledef, flydata_ctl_table: create_flydata_ctl_table) create_flydata_ctl_table = false end end