Module: ActiveGraph::Migrations::Helpers::Schema
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/active_graph/migrations/helpers/schema.rb
Constant Summary collapse
- MISSING_CONSTRAINT_OR_INDEX =
'No such %{type} for %{label}#%{property}'.freeze
- DUPLICATE_CONSTRAINT_OR_INDEX =
'Duplicate %{type} for %{label}#%{property}'.freeze
Instance Method Summary collapse
- #add_constraint(name, property, relationship: false, type: :key, force: false) ⇒ Object
- #add_index(label, property, options = {}) ⇒ Object
- #drop_constraint(name, property, type: :key, relationship: false, force: false) ⇒ Object
- #drop_index(label, property, options = {}) ⇒ Object
Instance Method Details
#add_constraint(name, property, relationship: false, type: :key, force: false) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/active_graph/migrations/helpers/schema.rb', line 9 def add_constraint(name, property, relationship: false, type: :key, force: false) element = ActiveGraph::Base.element(name, relationship:) if element.constraint?(property) if force element.drop_constraint(property, type:) else fail_duplicate_constraint_or_index!(:constraint, name, property) end end element.create_constraint(property, type:) end |
#add_index(label, property, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_graph/migrations/helpers/schema.rb', line 21 def add_index(label, property, = {}) force = [:force] || false label_object = ActiveGraph::Base.label_object(label) if label_object.index?(property) if force label_object.drop_index(property) else fail_duplicate_constraint_or_index!(:index, label, property) end end label_object.create_index(property) end |
#drop_constraint(name, property, type: :key, relationship: false, force: false) ⇒ Object
34 35 36 37 38 |
# File 'lib/active_graph/migrations/helpers/schema.rb', line 34 def drop_constraint(name, property, type: :key, relationship: false, force: false) element = ActiveGraph::Base.element(name, relationship:) fail_missing_constraint_or_index!(:constraint, name, property) unless force || element.constraint?(property) element.drop_constraint(property, type:) end |
#drop_index(label, property, options = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/active_graph/migrations/helpers/schema.rb', line 40 def drop_index(label, property, = {}) label_object = ActiveGraph::Base.label_object(label) fail_missing_constraint_or_index!(:index, label, property) if ![:force] && !label_object.index?(property) label_object.drop_index(property) end |