Class: ActiveRecord::ConnectionAdapters::Elasticsearch::UpdateTableDefinition
- Inherits:
-
TableDefinition
- Object
- TableDefinition
- ActiveRecord::ConnectionAdapters::Elasticsearch::UpdateTableDefinition
- Defined in:
- lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb
Constant Summary collapse
- COMPOSITE_DEFINITIONS =
defines which definitions can be executed composite
[ AddMappingDefinition, ChangeMappingDefinition, ChangeMetaDefinition, AddSettingDefinition, ChangeSettingDefinition, RemoveSettingDefinition, RemoveAliasDefinition ].freeze
Instance Method Summary collapse
- #add_alias(name, if_not_exists: false, **options, &block) ⇒ Object
- #add_mapping(name, type, if_not_exists: false, **options, &block) ⇒ Object (also: #add_column, #mapping, #column)
- #add_setting(name, value, if_not_exists: false, **options, &block) ⇒ Object
- #change_alias(name, if_exists: false, **options, &block) ⇒ Object
- #change_mapping(name, type, **options, &block) ⇒ Object (also: #change_column, #change)
- #change_mapping_attributes(name, if_exists: false, **options, &block) ⇒ Object
- #change_mapping_meta(name, **options) ⇒ Object
- #change_meta(name, value, **options) ⇒ Object
- #change_setting(name, value, if_exists: false, **options, &block) ⇒ Object
-
#definitions ⇒ Object
returns the definitions hash.
- #remove_alias(name, if_exists: false, &block) ⇒ Object
- #remove_mapping(name) ⇒ Object (also: #remove_column)
- #remove_meta(name, **options) ⇒ Object
- #remove_setting(name, if_exists: false, **options, &block) ⇒ Object
-
#timestamps(**options) ⇒ Object
Appends :datetime columns :created_at and :updated_at to the table.
Constructor Details
This class inherits a constructor from ActiveRecord::ConnectionAdapters::Elasticsearch::TableDefinition
Instance Method Details
#add_alias(name, if_not_exists: false, **options, &block) ⇒ Object
102 103 104 105 106 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 102 def add_alias(name, if_not_exists: false, **, &block) return if if_not_exists && alias_exists?(self.name, name) define! AddAliasDefinition, new_alias_definition(name, **, &block) end |
#add_mapping(name, type, if_not_exists: false, **options, &block) ⇒ Object Also known as: add_column, mapping, column
22 23 24 25 26 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 22 def add_mapping(name, type, if_not_exists: false, **, &block) return if if_not_exists && mapping_exists?(self.name, name, type) define! AddMappingDefinition, new_mapping_definition(name, type, **, &block) end |
#add_setting(name, value, if_not_exists: false, **options, &block) ⇒ Object
84 85 86 87 88 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 84 def add_setting(name, value, if_not_exists: false, **, &block) return if if_not_exists && setting_exists?(self.name, name) define! AddSettingDefinition, new_setting_definition(name, value, **, &block) end |
#change_alias(name, if_exists: false, **options, &block) ⇒ Object
108 109 110 111 112 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 108 def change_alias(name, if_exists: false, **, &block) return if if_exists && !alias_exists?(self.name, name) define! ChangeAliasDefinition, new_alias_definition(name, **, &block) end |
#change_mapping(name, type, **options, &block) ⇒ Object Also known as: change_column, change
44 45 46 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 44 def change_mapping(name, type, **, &block) raise ArgumentError, "you cannot change the mapping '#{name}' without the 'recreate: true' flag in the '#change_table' call" end |
#change_mapping_attributes(name, if_exists: false, **options, &block) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 61 def change_mapping_attributes(name, if_exists: false, **, &block) return if if_exists && !mapping_exists?(self.name, name) # receive current mapping current_mapping = table_mappings(self.name).dig('properties', name.to_s) raise ArgumentError, "you cannot change an unknown mapping '#{name}'" if current_mapping.blank? # build new mapping mapping = new_mapping_definition(name, current_mapping[:type], **, &block) define! ChangeMappingDefinition, mapping # check if the mapping is assigned as new primary_key if mapping.primary_key? :primary_key, mapping.name (:auto_increment, mapping.auto_increment) if mapping.auto_increment? end end |
#change_mapping_meta(name, **options) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 51 def (name, **) mapping = table_mappings(self.name).dig('properties', name.to_s) raise ArgumentError, "you cannot change the 'meta' parameter for an unknown mapping '#{name}'" if mapping.blank? # resolve existing meta & merge with new = (mapping['meta'] || {}).merge() define! ChangeMappingDefinition, new_mapping_definition(name, mapping['type'], meta: ) end |
#change_meta(name, value, **options) ⇒ Object
32 33 34 35 36 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 32 def (name, value, **) define! ChangeMetaDefinition, (name, value, **) end |
#change_setting(name, value, if_exists: false, **options, &block) ⇒ Object
90 91 92 93 94 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 90 def change_setting(name, value, if_exists: false, **, &block) return if if_exists && !setting_exists?(self.name, name) define! ChangeSettingDefinition, new_setting_definition(name, value, **, &block) end |
#definitions ⇒ Object
returns the definitions hash
130 131 132 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 130 def definitions @definitions ||= {} end |
#remove_alias(name, if_exists: false, &block) ⇒ Object
114 115 116 117 118 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 114 def remove_alias(name, if_exists: false, **, &block) return if if_exists && !alias_exists?(self.name, name) define! RemoveAliasDefinition, new_alias_definition(name, &block) end |
#remove_mapping(name) ⇒ Object Also known as: remove_column
79 80 81 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 79 def remove_mapping(name) raise ArgumentError, "you cannot remove the mapping '#{name}' without the 'recreate: true' flag in the '#change_table' call" end |
#remove_meta(name, **options) ⇒ Object
38 39 40 41 42 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 38 def (name, **) define! ChangeMetaDefinition, (name, nil, **) end |
#remove_setting(name, if_exists: false, **options, &block) ⇒ Object
96 97 98 99 100 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 96 def remove_setting(name, if_exists: false, **, &block) return if if_exists && !setting_exists?(self.name, name) define! RemoveSettingDefinition, new_setting_definition(name, nil, **, &block) end |
#timestamps(**options) ⇒ Object
Appends :datetime columns :created_at and :updated_at to the table. See ActiveRecord::ConnectionAdapters::Elasticsearch::UpdateTableDefinition.connectionconnection.add_timestamps[rdoc-ref:SchemaStatements#add_timestamps]
t.timestamps
124 125 126 127 |
# File 'lib/active_record/connection_adapters/elasticsearch/schema_definitions/update_table_definition.rb', line 124 def (**) add_mapping(:created_at, :datetime, if_not_exists: true, **) add_mapping(:updated_at, :datetime, if_not_exists: true, **) end |