Class: OnlineMigrations::IndexDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/online_migrations/index_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ IndexDefinition

Returns a new instance of IndexDefinition.



8
9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



6
7
8
# File 'lib/online_migrations/index_definition.rb', line 6

def columns
  @columns
end

#opclassesObject (readonly)

Returns the value of attribute opclasses.



6
7
8
# File 'lib/online_migrations/index_definition.rb', line 6

def opclasses
  @opclasses
end

#tableObject (readonly)

Returns the value of attribute table.



6
7
8
# File 'lib/online_migrations/index_definition.rb', line 6

def table
  @table
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/online_migrations/index_definition.rb', line 6

def type
  @type
end

#uniqueObject (readonly)

Returns the value of attribute unique.



6
7
8
# File 'lib/online_migrations/index_definition.rb', line 6

def unique
  @unique
end

#usingObject (readonly)

Returns the value of attribute using.



6
7
8
# File 'lib/online_migrations/index_definition.rb', line 6

def using
  @using
end

#whereObject (readonly)

Returns the value of attribute where.



6
7
8
# File 'lib/online_migrations/index_definition.rb', line 6

def where
  @where
end

Instance Method Details

#covered_by?(other) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
# 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

  if unique && !other.unique
    false
  else
    prefix?(self, other)
  end
end

#intersect?(other) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


19
20
21
22
23
24
# 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