Sha256: ab522bdad87fbac5d293538c5bfa5c6926f1f0bbaec55e509d0d1e8028b02353

Contents?: true

Size: 1.32 KB

Versions: 69

Compression:

Stored size: 1.32 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
      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
  end
end

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
backlog-0.36.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
advertnet-1.0.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
advertnet-1.0.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.4 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.3 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.5 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.7 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.6 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.11.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.12.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.10.8 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.12.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.12.2 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.12.4 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.12.3 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.14.0 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb
backlog-0.13.1 vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb