module Neo4j::Migrations::Helpers::Schema

Constants

DUPLICATE_CONSTRAINT_OR_INDEX
MISSING_CONSTRAINT_OR_INDEX

Public Instance Methods

add_constraint(label, property, options = {}) click to toggle source
   # File lib/neo4j/migrations/helpers/schema.rb
 9 def add_constraint(label, property, options = {})
10   force = options[:force] || false
11   type = options[:type] || :uniqueness
12   label_object = ActiveBase.label_object(label)
13   fail_duplicate_constraint_or_index!(:constraint, label, property) if !force && label_object.constraint?(property)
14   label_object.create_constraint(property, type: type)
15 end
add_index(label, property, options = {}) click to toggle source
   # File lib/neo4j/migrations/helpers/schema.rb
17 def add_index(label, property, options = {})
18   force = options[:force] || false
19   label_object = ActiveBase.label_object(label)
20   fail_duplicate_constraint_or_index!(:index, label, property) if !force && label_object.index?(property)
21   label_object.create_index(property)
22 end
drop_constraint(label, property, options = {}) click to toggle source
   # File lib/neo4j/migrations/helpers/schema.rb
24 def drop_constraint(label, property, options = {})
25   type = options[:type] || :uniqueness
26   label_object = ActiveBase.label_object(label)
27   fail_missing_constraint_or_index!(:constraint, label, property) if !options[:force] && !label_object.constraint?(property)
28   label_object.drop_constraint(property, type: type)
29 end
drop_index(label, property, options = {}) click to toggle source
   # File lib/neo4j/migrations/helpers/schema.rb
31 def drop_index(label, property, options = {})
32   label_object = ActiveBase.label_object(label)
33   fail_missing_constraint_or_index!(:index, label, property) if !options[:force] && !label_object.index?(property)
34   label_object.drop_index(property)
35 end

Protected Instance Methods

fail_duplicate_constraint_or_index!(type, label, property) click to toggle source
   # File lib/neo4j/migrations/helpers/schema.rb
44 def fail_duplicate_constraint_or_index!(type, label, property)
45   fail Neo4j::MigrationError,
46        format(DUPLICATE_CONSTRAINT_OR_INDEX, type: type, label: label, property: property)
47 end
fail_missing_constraint_or_index!(type, label, property) click to toggle source
   # File lib/neo4j/migrations/helpers/schema.rb
39 def fail_missing_constraint_or_index!(type, label, property)
40   fail Neo4j::MigrationError,
41        format(MISSING_CONSTRAINT_OR_INDEX, type: type, label: label, property: property)
42 end