Class: Mysql2psql::Converter
- Inherits:
-
Object
- Object
- Mysql2psql::Converter
- Defined in:
- lib/mysql2psql/converter.rb
Instance Attribute Summary collapse
-
#exclude_tables ⇒ Object
readonly
Returns the value of attribute exclude_tables.
-
#force_truncate ⇒ Object
readonly
Returns the value of attribute force_truncate.
-
#only_tables ⇒ Object
readonly
Returns the value of attribute only_tables.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#supress_data ⇒ Object
readonly
Returns the value of attribute supress_data.
-
#supress_ddl ⇒ Object
readonly
Returns the value of attribute supress_ddl.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(reader, writer, options) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(reader, writer, options) ⇒ Converter
Returns a new instance of Converter.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mysql2psql/converter.rb', line 7 def initialize(reader, writer, ) @reader = reader @writer = writer @options = @exclude_tables = .exclude_tables([]) @only_tables = .only_tables(nil) @supress_data = .supress_data(false) @supress_ddl = .supress_ddl(false) @force_truncate = .force_truncate(false) end |
Instance Attribute Details
#exclude_tables ⇒ Object (readonly)
Returns the value of attribute exclude_tables.
5 6 7 |
# File 'lib/mysql2psql/converter.rb', line 5 def exclude_tables @exclude_tables end |
#force_truncate ⇒ Object (readonly)
Returns the value of attribute force_truncate.
5 6 7 |
# File 'lib/mysql2psql/converter.rb', line 5 def force_truncate @force_truncate end |
#only_tables ⇒ Object (readonly)
Returns the value of attribute only_tables.
5 6 7 |
# File 'lib/mysql2psql/converter.rb', line 5 def only_tables @only_tables end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/mysql2psql/converter.rb', line 4 def @options end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
4 5 6 |
# File 'lib/mysql2psql/converter.rb', line 4 def reader @reader end |
#supress_data ⇒ Object (readonly)
Returns the value of attribute supress_data.
5 6 7 |
# File 'lib/mysql2psql/converter.rb', line 5 def supress_data @supress_data end |
#supress_ddl ⇒ Object (readonly)
Returns the value of attribute supress_ddl.
5 6 7 |
# File 'lib/mysql2psql/converter.rb', line 5 def supress_ddl @supress_ddl end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
4 5 6 |
# File 'lib/mysql2psql/converter.rb', line 4 def writer @writer end |
Instance Method Details
#convert ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mysql2psql/converter.rb', line 18 def convert _time1 = Time.now tables = reader.tables. reject {|table| @exclude_tables.include?(table.name)}. select {|table| @only_tables ? @only_tables.include?(table.name) : true} tables.each do |table| writer.write_table(table) end unless @supress_ddl _time2 = Time.now tables.each do |table| writer.truncate(table) if force_truncate && supress_ddl writer.write_contents(table, reader) end unless @supress_data _time3 = Time.now tables.each do |table| writer.write_indexes(table) end unless @supress_ddl tables.each do |table| writer.write_constraints(table) end unless @supress_ddl writer.close _time4 = Time.now puts "Table creation #{((_time2 - _time1) / 60).round} min, loading #{((_time3 - _time2) / 60).round} min, indexing #{((_time4 - _time3) / 60).round} min, total #{((_time4 - _time1) / 60).round} min" return 0 rescue => e $stderr.puts "Mysql2psql: conversion failed: #{e.to_s}" return -1 end |