Class: FuryDumper::Dumper
- Inherits:
-
Object
- Object
- FuryDumper::Dumper
- Defined in:
- lib/fury_dumper/dumper.rb
Instance Attribute Summary collapse
-
#dump_state ⇒ Object
readonly
Returns the value of attribute dump_state.
Instance Method Summary collapse
- #equal_schemas? ⇒ Boolean
-
#initialize(password:, host:, port:, user:, database:, model:, debug_mode:) ⇒ Dumper
constructor
A new instance of Dumper.
- #sync_models ⇒ Object
Constructor Details
#initialize(password:, host:, port:, user:, database:, model:, debug_mode:) ⇒ Dumper
Returns a new instance of Dumper.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fury_dumper/dumper.rb', line 7 def initialize(password:, host:, port:, user:, database:, model:, debug_mode:) @password = password @host = host @user = user @database = database @port = port @model = model @debug_mode = debug_mode @dump_state = Dumpers::DumpState.new(root_source_model: @model_name) @undump_models = [] end |
Instance Attribute Details
#dump_state ⇒ Object (readonly)
Returns the value of attribute dump_state.
5 6 7 |
# File 'lib/fury_dumper/dumper.rb', line 5 def dump_state @dump_state end |
Instance Method Details
#equal_schemas? ⇒ Boolean
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fury_dumper/dumper.rb', line 38 def equal_schemas? tables_list = cur_connection.tables.map { |e| "'#{e}'" }.join(', ') sql = 'SELECT column_name, data_type, table_name FROM INFORMATION_SCHEMA.COLUMNS ' \ "WHERE table_name IN (#{tables_list});" cur_schema = cur_connection.exec_query(sql).to_a remote_schema = remote_connection.exec_query(sql).to_a difference = difference(remote_schema, cur_schema) if difference.present? difference.group_by { |e| e['table_name'] }.each do |table_name, diff| p "💣 Found difference for table #{table_name}" diff.sort_by { |e| e['column_name'] }.each do |dif| if cur_schema.include?(dif) p "Current DB have column: #{dif['column_name']} <#{dif['data_type']}>" else p "Remote DB have column: #{dif['column_name']} <#{dif['data_type']}>" end end end false else true end end |
#sync_models ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fury_dumper/dumper.rb', line 26 def sync_models p '--- Dump models ---' if FuryDumper::Config.mode == :wide sync_model_in_wight(@model) else sync_model_in_depth(@model) end @dump_state.stop print_undump_models end |