method
index_name_exists?
v5.1.7 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements
index_name_exists?(table_name, index_name, default = nil)public
Verifies existence of an index with a given name.
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 67
def index_name_exists?(table_name, index_name, default = nil)
unless default.nil?
ActiveSupport::Deprecation.warn( Passing default to #index_name_exists? is deprecated without replacement..squish)
end
table = quoted_scope(table_name)
index = quoted_scope(index_name)
query_value( SELECT COUNT(*) FROM pg_class t INNER JOIN pg_index d ON t.oid = d.indrelid INNER JOIN pg_class i ON d.indexrelid = i.oid LEFT JOIN pg_namespace n ON n.oid = i.relnamespace WHERE i.relkind = 'i' AND i.relname = #{index[:name]} AND t.relname = #{table[:name]} AND n.nspname = #{index[:schema]}, "SCHEMA").to_i > 0
end Related methods
- Instance methods
- add_column
- add_index
- change_column
- change_column_comment
- change_column_default
- change_column_null
- change_table_comment
- client_min_messages
- client_min_messages=
- collation
- columns_for_distinct
- create_database
- create_schema
- ctype
- current_database
- current_schema
- default_sequence_name
- drop_database
- drop_schema
- drop_table
- encoding
- extract_foreign_key_action
- fetch_type_metadata
- foreign_keys
- index_name_exists?
- indexes
- new_column_from_field
- pk_and_sequence_for
- primary_keys
- recreate_database
- remove_index
- rename_column
- rename_index
- rename_table
- reset_pk_sequence!
- schema_exists?
- schema_names
- schema_search_path
- schema_search_path=
- serial_sequence
- set_pk_sequence!
- table_comment
- table_options
- type_to_sql
- Private methods
-
data_source_sql -
extract_schema_qualified_name -
quoted_scope