module Rein::Constraint::Check

This module contains methods for defining check constraints.

Public Instance Methods

add_check_constraint(*args) click to toggle source
# File lib/rein/constraint/check.rb, line 8
def add_check_constraint(*args)
  reversible do |dir|
    dir.up { _add_check_constraint(*args) }
    dir.down { _remove_check_constraint(*args) }
  end
end
remove_check_constraint(*args) click to toggle source
# File lib/rein/constraint/check.rb, line 15
def remove_check_constraint(*args)
  reversible do |dir|
    dir.up { _remove_check_constraint(*args) }
    dir.down { _add_check_constraint(*args) }
  end
end

Private Instance Methods

_add_check_constraint(table_name, predicate, options = {}) click to toggle source
# File lib/rein/constraint/check.rb, line 24
def _add_check_constraint(table_name, predicate, options = {})
  raise 'Generic CHECK constraints must have a name' unless options[:name].present?
  name = Util.wrap_identifier(options[:name])
  sql = "ALTER TABLE #{Util.wrap_identifier(table_name)}"
  sql << " ADD CONSTRAINT #{name}"
  sql << " CHECK (#{predicate})"
  execute(Util.add_not_valid_suffix_if_required(sql, options))
end
_remove_check_constraint(table_name, _predicate, options = {}) click to toggle source
# File lib/rein/constraint/check.rb, line 33
def _remove_check_constraint(table_name, _predicate, options = {})
  raise 'Generic CHECK constraints must have a name' unless options[:name].present?
  name = Util.wrap_identifier(options[:name])
  execute("ALTER TABLE #{Util.wrap_identifier(table_name)} DROP CONSTRAINT #{name}")
end