Method: ActiveRecord::ConnectionAdapters::SchemaStatements#check_constraint_exists?

Defined in:
activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

#check_constraint_exists?(table_name, **options) ⇒ Boolean

Checks to see if a check constraint exists on a table for a given check constraint definition.

check_constraint_exists?(:products, name: "price_check")

Returns:

  • (Boolean)


1341
1342
1343
1344
1345
1346
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb', line 1341

def check_constraint_exists?(table_name, **options)
  if !options.key?(:name) && !options.key?(:expression)
    raise ArgumentError, "At least one of :name or :expression must be supplied"
  end
  check_constraint_for(table_name, **options).present?
end