Sha256: 46b56e15cdcb88bb9a74b59df4ccf1010849555b45968af6b027cb5d6e10b0b0
Contents?: true
Size: 1.64 KB
Versions: 11
Compression:
Stored size: 1.64 KB
Contents
module RedHillConsulting::Core::ActiveRecord module SchemaDumper def self.included(base) base.class_eval do private alias_method_chain :tables, :redhillonrails_core alias_method_chain :indexes, :redhillonrails_core end end private def tables_with_redhillonrails_core(stream) @foreign_keys = StringIO.new begin tables_without_redhillonrails_core(stream) @foreign_keys.rewind stream.print @foreign_keys.read views(stream) ensure @foreign_keys = nil end end def indexes_with_redhillonrails_core(table, stream) indexes = @connection.indexes(table) indexes.each do |index| stream.print " add_index #{index.table.inspect}, #{index.columns.inspect}, :name => #{index.name.inspect}" stream.print ", :unique => true" if index.unique stream.print ", :case_sensitive => false" unless index.case_sensitive? stream.puts end stream.puts unless indexes.empty? foreign_keys(table, @foreign_keys) end def foreign_keys(table, stream) foreign_keys = @connection.foreign_keys(table) foreign_keys.each do |foreign_key| stream.print " " stream.print foreign_key.to_dump stream.puts end stream.puts unless foreign_keys.empty? end def views(stream) views = @connection.views views.each do |view_name| definition = @connection.view_definition(view_name) stream.print " create_view #{view_name.inspect}, #{definition.inspect}" stream.puts end stream.puts unless views.empty? end end end
Version data entries
11 entries across 11 versions & 3 rubygems