Module: RareMap::SchemaReader
- Included in:
- Mapper
- Defined in:
- lib/rare_map/schema_reader.rb
Overview
RareMap::SchemaReader dumps database schema by using ActiveRecord::SchemaDumper.
Instance Method Summary collapse
-
#read_schema(db_profile) ⇒ String
Returns the content of schema.rb which is created by ActiveRecord::SchemaDumper.
Instance Method Details
#read_schema(db_profile) ⇒ String
Returns the content of schema.rb which is created by ActiveRecord::SchemaDumper.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rare_map/schema_reader.rb', line 11 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 |