Module: RareMap::SchemaReader

Included in:
Mapper
Defined in:
lib/rare_map/schema_reader.rb

Instance Method Summary collapse

Instance Method Details

#detect_errors(schema) ⇒ Object



24
25
26
27
28
29
# File 'lib/rare_map/schema_reader.rb', line 24

def detect_errors(schema)
  if $? != 0
    puts schema
    schema = ''
  end
end

#read_schema(db_profile) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rare_map/schema_reader.rb', line 6

def read_schema(db_profile)
  conn = db_profile.connection.map { |k, v| v.kind_of?(Integer) ? "'#{k}'=>#{v}" : "'#{k}'=>'#{v}'" }.join(', ')
  schema = if RUBY_PLATFORM == 'java'
    %x[jruby -e "require 'active_record'; require 'activerecord-jdbc-adapter'; ActiveRecord::Base.establish_connection(#{conn}); ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection);" 2>&1]
  else
    %x[ruby -e "require 'active_record'; ActiveRecord::Base.establish_connection(#{conn}); ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection);" 2>&1]
  end
  detect_errors schema
  schema
=begin
  schema = StringIO.new
  ActiveRecord::Base.establish_connection db_profile.connection
  ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, schema)
  schema.close
  schema.string
=end

end