module AR::Check::Adapter
Public Instance Methods
add_check(table, constraint_name, expression)
click to toggle source
# File lib/ar/check/adapter.rb, line 24 def add_check(table, constraint_name, expression) sql = <<-SQL ALTER TABLE #{table} ADD CONSTRAINT #{quote_column_name("#{constraint_name}_on_#{table}")} CHECK (#{expression}) SQL execute(sql) end
check_constraints(table)
click to toggle source
# File lib/ar/check/adapter.rb, line 6 def check_constraints(table) result = select_all <<~SQL SELECT c.conname AS name, pg_get_constraintdef(c.oid) AS expression, t1.relname AS table FROM pg_constraint c JOIN pg_class t1 ON c.conrelid = t1.oid JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid JOIN pg_namespace t2 ON c.connamespace = t2.oid WHERE c.contype = 'c' AND c.convalidated = TRUE AND t1.relname = '#{table}' AND t2.nspname = ANY (current_schemas(false)) SQL result.to_a end
remove_check(table, constraint_name)
click to toggle source
# File lib/ar/check/adapter.rb, line 33 def remove_check(table, constraint_name) sql = <<-SQL ALTER TABLE #{table} DROP CONSTRAINT #{quote_column_name("#{constraint_name}_on_#{table}")} SQL execute(sql) end