Class: Mysql2postgres::Converter
- Inherits:
-
Object
- Object
- Mysql2postgres::Converter
- Defined in:
- lib/mysql2postgres/converter.rb
Instance Attribute Summary collapse
-
#clear_schema ⇒ Object
readonly
Returns the value of attribute clear_schema.
-
#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.
-
#preserve_order ⇒ Object
readonly
Returns the value of attribute preserve_order.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#suppress_data ⇒ Object
readonly
Returns the value of attribute suppress_data.
-
#suppress_ddl ⇒ Object
readonly
Returns the value of attribute suppress_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.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mysql2postgres/converter.rb', line 16 def initialize(reader, writer, ) @reader = reader @writer = writer @exclude_tables = [:exclude_tables] || [] @only_tables = [:tables] @suppress_data = [:suppress_data] || false @suppress_ddl = [:suppress_ddl] || false @force_truncate = [:force_truncate] || false @preserve_order = [:preserve_order] || false @clear_schema = [:clear_schema] || false end |
Instance Attribute Details
#clear_schema ⇒ Object (readonly)
Returns the value of attribute clear_schema.
5 6 7 |
# File 'lib/mysql2postgres/converter.rb', line 5 def clear_schema @clear_schema end |
#exclude_tables ⇒ Object (readonly)
Returns the value of attribute exclude_tables.
5 6 7 |
# File 'lib/mysql2postgres/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/mysql2postgres/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/mysql2postgres/converter.rb', line 5 def only_tables @only_tables end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/mysql2postgres/converter.rb', line 5 def @options end |
#preserve_order ⇒ Object (readonly)
Returns the value of attribute preserve_order.
5 6 7 |
# File 'lib/mysql2postgres/converter.rb', line 5 def preserve_order @preserve_order end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
5 6 7 |
# File 'lib/mysql2postgres/converter.rb', line 5 def reader @reader end |
#suppress_data ⇒ Object (readonly)
Returns the value of attribute suppress_data.
5 6 7 |
# File 'lib/mysql2postgres/converter.rb', line 5 def suppress_data @suppress_data end |
#suppress_ddl ⇒ Object (readonly)
Returns the value of attribute suppress_ddl.
5 6 7 |
# File 'lib/mysql2postgres/converter.rb', line 5 def suppress_ddl @suppress_ddl end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
5 6 7 |
# File 'lib/mysql2postgres/converter.rb', line 5 def writer @writer end |
Instance Method Details
#convert ⇒ Object
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mysql2postgres/converter.rb', line 28 def convert tables = reader.tables tables.reject! { |table| exclude_tables.include? table.name } tables.select! { |table| only_tables ? only_tables.include?(table.name) : true } # preserve order only works, if only_tables are specified if preserve_order && only_tables reordered_tables = [] only_tables.each do |only_table| idx = tables.index { |table| table.name == only_table } if idx.nil? warn "Specified source table '#{only_table}' does not exist, skiped by migration" else reordered_tables << tables[idx] end end tables = reordered_tables end unless suppress_ddl tables.each do |table| puts "Writing DDL for #{table.name}" writer.write_table table end end unless suppress_data if force_truncate && suppress_ddl tables.each do |table| puts "Truncate table #{table.name}" writer.truncate table end end tables.each do |table| puts "Writing data for #{table.name}" writer.write_contents table, reader end end puts 'Writing indices and constraints' unless suppress_ddl tables.each do |table| writer.write_indexes table end end unless suppress_ddl tables.each do |table| writer.write_constraints table end end writer.close writer.clear_schema if clear_schema writer.inload 0 rescue StandardError => e warn "mysql2postgres: Conversion failed: #{e}" warn e warn e.backtrace[0, 3].join("\n") -1 end |