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.
-
#suppress_data ⇒ Object
readonly
Returns the value of attribute suppress_data.
-
#suppress_ddl ⇒ Object
readonly
Returns the value of attribute suppress_ddl.
-
#suppress_indexes ⇒ Object
readonly
Returns the value of attribute suppress_indexes.
-
#supress_sequence_update ⇒ Object
readonly
Returns the value of attribute supress_sequence_update.
-
#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 17 18 19 |
# 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) @suppress_data = .suppress_data(false) @suppress_ddl = .suppress_ddl(false) @supress_sequence_update = .supress_sequence_update(false) @suppress_indexes = .suppress_indexes(false) @force_truncate = .force_truncate(false) @use_timezones = .use_timezones(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 |
#suppress_data ⇒ Object (readonly)
Returns the value of attribute suppress_data.
5 6 7 |
# File 'lib/mysql2psql/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/mysql2psql/converter.rb', line 5 def suppress_ddl @suppress_ddl end |
#suppress_indexes ⇒ Object (readonly)
Returns the value of attribute suppress_indexes.
5 6 7 |
# File 'lib/mysql2psql/converter.rb', line 5 def suppress_indexes @suppress_indexes end |
#supress_sequence_update ⇒ Object (readonly)
Returns the value of attribute supress_sequence_update.
5 6 7 |
# File 'lib/mysql2psql/converter.rb', line 5 def supress_sequence_update @supress_sequence_update 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
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 53 54 55 56 57 58 59 |
# File 'lib/mysql2psql/converter.rb', line 21 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_sequence_update(table, ) end if !(@suppress_sequence_update && @suppress_ddl) tables.each do |table| writer.write_table(table, {:use_timezones => @use_timezones}) end unless @suppress_ddl _time2 = Time.now tables.each do |table| writer.truncate(table) if force_truncate && !suppress_ddl writer.write_contents(table, reader) end unless @suppress_data _time3 = Time.now tables.each do |table| writer.write_indexes(table) unless @suppress_indexes end unless @suppress_ddl tables.each do |table| writer.write_constraints(table) end unless @suppress_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}" $stderr.puts e.backtrace return -1 end |