class OnlineMigrations::IndexDefinition
@private
Attributes
columns[R]
opclasses[R]
table[R]
type[R]
unique[R]
using[R]
where[R]
Public Class Methods
new(**options)
click to toggle source
# File lib/online_migrations/index_definition.rb, line 8 def initialize(**options) @table = options[:table] @columns = Array(options[:columns]).map(&:to_s) @unique = options[:unique] @opclasses = options[:opclass] || {} @where = options[:where] @type = options[:type] @using = options[:using] || :btree end
Public Instance Methods
covered_by?(other)
click to toggle source
@param other [OnlineMigrations::IndexDefinition, ActiveRecord::ConnectionAdapters::IndexDefinition]
# File lib/online_migrations/index_definition.rb, line 27 def covered_by?(other) return false if type != other.type return false if using != other.using return false if where != other.where return false if other.respond_to?(:opclasses) && opclasses != other.opclasses case [unique, other.unique] when [true, true] columns == other.columns when [true, false] false else prefix?(self, other) end end
intersect?(other)
click to toggle source
@param other [OnlineMigrations::IndexDefinition, ActiveRecord::ConnectionAdapters::IndexDefinition]
# File lib/online_migrations/index_definition.rb, line 19 def intersect?(other) # For ActiveRecord::ConnectionAdapters::IndexDefinition is for expression indexes, # `columns` is a string table == other.table && (columns & Array(other.columns)).any? end
Private Instance Methods
prefix?(lhs, rhs)
click to toggle source
# File lib/online_migrations/index_definition.rb, line 44 def prefix?(lhs, rhs) lhs_columns = Array(lhs.columns) rhs_columns = Array(rhs.columns) lhs_columns.count <= rhs_columns.count && rhs_columns[0...lhs_columns.count] == lhs_columns end