Class: Mysql2postgres

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql2postgres.rb,
lib/mysql2postgres/version.rb,
lib/mysql2postgres/converter.rb,
lib/mysql2postgres/connection.rb,
lib/mysql2postgres/mysql_reader.rb,
lib/mysql2postgres/postgres_writer.rb,
lib/mysql2postgres/postgres_db_writer.rb,
lib/mysql2postgres/postgres_file_writer.rb

Defined Under Namespace

Classes: Connection, Converter, MysqlReader, PostgresDbWriter, PostgresFileWriter, PostgresWriter

Constant Summary collapse

VERSION =
'0.4.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml, config_file = nil) ⇒ Mysql2postgres

Returns a new instance of Mysql2postgres.



24
25
26
27
# File 'lib/mysql2postgres.rb', line 24

def initialize(yaml, config_file = nil)
  @config_file = config_file
  @options = build_options yaml
end

Instance Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



22
23
24
# File 'lib/mysql2postgres.rb', line 22

def config_file
  @config_file
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/mysql2postgres.rb', line 22

def options
  @options
end

#readerObject (readonly)

Returns the value of attribute reader.



22
23
24
# File 'lib/mysql2postgres.rb', line 22

def reader
  @reader
end

#writerObject (readonly)

Returns the value of attribute writer.



22
23
24
# File 'lib/mysql2postgres.rb', line 22

def writer
  @writer
end

Instance Method Details

#convertObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mysql2postgres.rb', line 29

def convert
  @reader = MysqlReader.new options

  puts "mysql2postgres #{Mysql2postgres::VERSION}"
  puts "Config file: #{config_file}"
  puts "Dumpfile: #{dump_file}"

  @writer = if to_file?
              puts 'Target: File'
              PostgresFileWriter.new dump_file, options[:destination]
            else
              puts "Target: PostgreSQL DB (#{adapter})"
              PostgresDbWriter.new dump_file, options[:destination]
            end

  Converter.new(reader, writer, options).convert
  File.delete dump_file if options[:remove_dump_file] && File.exist?(dump_file)
end