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
17
# File 'lib/online_migrations/index_definition.rb', line 8

def initialize(**options)
  @table = options[:table]&.to_s
  @name = options[:name]&.to_s
  @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

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
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)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/online_migrations/index_definition.rb', line 28

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 opclasses != other.opclasses

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

#intersect?(other) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/online_migrations/index_definition.rb', line 20

def intersect?(other)
  # For ActiveRecord::ConnectionAdapters::IndexDefinition is for expression indexes,
  # `columns` is a string
  table == other.table &&
    ((name && name == other.name) || columns.intersect?(Array(other.columns)))
end