Class: PgHaMigrations::TableCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pg_ha_migrations/relation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tables, &blk) ⇒ TableCollection

Returns a new instance of TableCollection.



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/pg_ha_migrations/relation.rb', line 196

def initialize(tables, &blk)
  @raw_set = tables.map(&blk).to_set

  if raw_set.empty?
    raise ArgumentError, "Expected a non-empty list of tables"
  end

  if raw_set.uniq(&:mode).size > 1
    raise ArgumentError, "Expected all tables in collection to have the same lock mode"
  end
end

Instance Attribute Details

#raw_setObject (readonly)

Returns the value of attribute raw_set.



187
188
189
# File 'lib/pg_ha_migrations/relation.rb', line 187

def raw_set
  @raw_set
end

Class Method Details

.from_table_names(tables, mode = nil) ⇒ Object



192
193
194
# File 'lib/pg_ha_migrations/relation.rb', line 192

def self.from_table_names(tables, mode=nil)
  new(tables) { |table| Table.from_table_name(table, mode) }
end

Instance Method Details

#subset?(other) ⇒ Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/pg_ha_migrations/relation.rb', line 208

def subset?(other)
  raw_set.subset?(other.raw_set)
end

#to_sqlObject



212
213
214
# File 'lib/pg_ha_migrations/relation.rb', line 212

def to_sql
  map(&:fully_qualified_name).join(", ")
end

#with_partitionsObject



216
217
218
219
220
221
222
# File 'lib/pg_ha_migrations/relation.rb', line 216

def with_partitions
  tables = flat_map do |table|
    table.partitions(include_sub_partitions: true, include_self: true)
  end

  self.class.new(tables)
end