class PGTrunk::Operations::MaterializedViews::Base

@abstract @private Base class for operations with views

Constants

RESET

A special constant to distinct cluster resetting from nil

Public Instance Methods

column(name, **opts) click to toggle source
# File lib/pg_trunk/operations/materialized_views/base.rb, line 17
def column(name, **opts)
  columns << Column.new(name: name, **opts.except(:new_name))
end

Private Instance Methods

validate_definition!(name: nil, **opts) click to toggle source
# File lib/pg_trunk/operations/materialized_views/base.rb, line 63
def validate_definition!(name: nil, **opts)
  return if opts.none? { |_, value| value == UNDEFINED }

  errors.add :base, "Definition of column #{name} can't be reverted"
end
validate_naming!(name: nil, **) click to toggle source
# File lib/pg_trunk/operations/materialized_views/base.rb, line 59
def validate_naming!(name: nil, **)
  errors.add :columns, "has undefined names" if name.blank?
end
validate_statistics!(name: nil, **opts) click to toggle source
# File lib/pg_trunk/operations/materialized_views/base.rb, line 69
def validate_statistics!(name: nil, **opts)
  opts.values_at(*STATISTICS).each do |value|
    next if value.nil? || value == UNDEFINED
    next if value.is_a?(Numeric) && value >= 0

    errors.add :base, "Column #{name} has invalid statistics #{value}"
    break
  end
end