module Rein::Constraint::PrimaryKey

This module contains methods for defining primary key constraints.

Public Instance Methods

add_primary_key(*args) click to toggle source
# File lib/rein/constraint/primary_key.rb, line 5
def add_primary_key(*args)
  reversible do |dir|
    dir.up { _add_primary_key(*args) }
    dir.down { _remove_primary_key(*args) }
  end
end
remove_primary_key(*args) click to toggle source
# File lib/rein/constraint/primary_key.rb, line 12
def remove_primary_key(*args)
  reversible do |dir|
    dir.up { _remove_primary_key(*args) }
    dir.down { _add_primary_key(*args) }
  end
end

Private Instance Methods

_add_primary_key(table, options = {}) click to toggle source
# File lib/rein/constraint/primary_key.rb, line 21
def _add_primary_key(table, options = {})
  table = Util.wrap_identifier(table)
  attribute = (options[:column] || 'id').to_sym
  execute("ALTER TABLE #{table} ADD PRIMARY KEY (#{attribute})")
end
_remove_primary_key(table, options = {}) click to toggle source
# File lib/rein/constraint/primary_key.rb, line 27
def _remove_primary_key(table, options = {})
  table = Util.wrap_identifier(table)
  attribute = (options[:column] || 'id').to_sym
  execute("ALTER TABLE #{table} DROP CONSTRAINT #{attribute}_pkey")
end