Sha256: 4a3dc303b2ebecb64edb8092b52033e24f750158c1f88cedba861c72baf906e4
Contents?: true
Size: 965 Bytes
Versions: 4
Compression:
Stored size: 965 Bytes
Contents
module ActiveRecordSchema module SchemaDiff extend ActiveSupport::Concern def diff(*args) diff_method = "_diff_" << args.join('_') self.respond_to?(diff_method) ? self.send(diff_method) : [] end def _diff_fields_add model.schema.fields.values.delete_if {|field| _column_names.include?(field.name.to_s) } end def _diff_indexes_add model.schema.indexes.values.delete_if {|index| _index_names.include?(index.name.to_s) } end def _diff_joins_add model.schema.joins.values.delete_if {|join| _table_names.include?(join.table.to_s) } end def _connection ActiveRecord::Base.connection end def _table model.table_name end def _column_names _connection.columns(_table).map(&:name) end def _index_names _connection.indexes(_table).map(&:name) end def _table_names _connection.tables end end end
Version data entries
4 entries across 4 versions & 1 rubygems