Module: Neo4j::Migrations::Helpers::Schema

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/neo4j/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

Instance Method Details

#add_constraint(label, property, options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/neo4j/migrations/helpers/schema.rb', line 9

def add_constraint(label, property, options = {})
  force = options[:force] || false
  type = options[:type] || :uniqueness
  label_object = ActiveBase.label_object(label)
  fail_duplicate_constraint_or_index!(:constraint, label, property) if !force && label_object.constraint?(property)
  label_object.create_constraint(property, type: type)
end

#add_index(label, property, options = {}) ⇒ Object



17
18
19
20
21
22
# File 'lib/neo4j/migrations/helpers/schema.rb', line 17

def add_index(label, property, options = {})
  force = options[:force] || false
  label_object = ActiveBase.label_object(label)
  fail_duplicate_constraint_or_index!(:index, label, property) if !force && label_object.index?(property)
  label_object.create_index(property)
end

#drop_constraint(label, property, options = {}) ⇒ Object



24
25
26
27
28
29
# File 'lib/neo4j/migrations/helpers/schema.rb', line 24

def drop_constraint(label, property, options = {})
  type = options[:type] || :uniqueness
  label_object = ActiveBase.label_object(label)
  fail_missing_constraint_or_index!(:constraint, label, property) if !options[:force] && !label_object.constraint?(property)
  label_object.drop_constraint(property, type: type)
end

#drop_index(label, property, options = {}) ⇒ Object



31
32
33
34
35
# File 'lib/neo4j/migrations/helpers/schema.rb', line 31

def drop_index(label, property, options = {})
  label_object = ActiveBase.label_object(label)
  fail_missing_constraint_or_index!(:index, label, property) if !options[:force] && !label_object.index?(property)
  label_object.drop_index(property)
end