Module: ActiveRecord::ConnectionAdapters::Elasticsearch::TableStatements

Extended by:
ActiveSupport::Concern
Included in:
ActiveRecord::ConnectionAdapters::ElasticsearchAdapter
Defined in:
lib/active_record/connection_adapters/elasticsearch/table_statements.rb

Overview

extend adapter with table-related statements

Table name decoration

Every statement below resolves its provided table name(s) through #_env_table_name, which recaps them with the table_name_prefix & table_name_suffix of the connection config. This happens by default - so a migration only ever has to name the base table (index):

create_table 'settings'   # => creates 'settings-dev' on a '-dev' suffixed connection

Provide decorate: false to address an index by its literal name instead. This is required for names that are already resolved and for base names that happen to start with the prefix (or end with the suffix), which #_env_table_name cannot tell apart:

drop_table 'settings-pro', decorate: false

The default of a NOT explicitly provided decorate: argument is resolved from ElasticsearchRecord.decorate_table_names - setting it to false restores the former, opt-in behaviour, where the decoration had to be applied by hand through #_env_table_name. A single statement can still opt in or out on its own.

PLEASE NOTE: the decoration only applies to table (index) names - alias, mapping, setting & meta names are never touched.

Internal tables

schema_migrations & ar_internal_metadata carry the migration state of the connection. Only #truncate_table guards them - it raises instead of wiping the state of a whole environment, which in Elasticsearch means a drop & create of the index.

Every other statement passes them through on purpose. #drop_table especially MUST stay open: ActiveRecord resets both tables through it (+ActiveRecord::SchemaMigration#drop_table+ & ActiveRecord::InternalMetadata#drop_table both call connection.drop_table(table_name, if_exists: true)), so a guard there would break that API without an escape hatch.