module ActiveGraph::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/active_graph/migrations/helpers/schema.rb 9 def add_constraint(label, property, options = {}) 10 force = options[:force] || false 11 type = options[:type] || :uniqueness 12 label_object = ActiveGraph::Base.label_object(label) 13 if label_object.constraint?(property) 14 if force 15 label_object.drop_constraint(property, type: type) 16 else 17 fail_duplicate_constraint_or_index!(:constraint, label, property) 18 end 19 end 20 label_object.create_constraint(property, type: type) 21 end
add_index(label, property, options = {})
click to toggle source
# File lib/active_graph/migrations/helpers/schema.rb 23 def add_index(label, property, options = {}) 24 force = options[:force] || false 25 label_object = ActiveGraph::Base.label_object(label) 26 if label_object.index?(property) 27 if force 28 label_object.drop_index(property) 29 else 30 fail_duplicate_constraint_or_index!(:index, label, property) 31 end 32 end 33 label_object.create_index(property) 34 end
drop_constraint(label, property, options = {})
click to toggle source
# File lib/active_graph/migrations/helpers/schema.rb 36 def drop_constraint(label, property, options = {}) 37 type = options[:type] || :uniqueness 38 label_object = ActiveGraph::Base.label_object(label) 39 fail_missing_constraint_or_index!(:constraint, label, property) if !options[:force] && !label_object.constraint?(property) 40 label_object.drop_constraint(property, type: type) 41 end
drop_index(label, property, options = {})
click to toggle source
# File lib/active_graph/migrations/helpers/schema.rb 43 def drop_index(label, property, options = {}) 44 label_object = ActiveGraph::Base.label_object(label) 45 fail_missing_constraint_or_index!(:index, label, property) if !options[:force] && !label_object.index?(property) 46 label_object.drop_index(property) 47 end
Protected Instance Methods
fail_duplicate_constraint_or_index!(type, label, property)
click to toggle source
# File lib/active_graph/migrations/helpers/schema.rb 56 def fail_duplicate_constraint_or_index!(type, label, property) 57 fail ActiveGraph::MigrationError, 58 format(DUPLICATE_CONSTRAINT_OR_INDEX, type: type, label: label, property: property) 59 end
fail_missing_constraint_or_index!(type, label, property)
click to toggle source
# File lib/active_graph/migrations/helpers/schema.rb 51 def fail_missing_constraint_or_index!(type, label, property) 52 fail ActiveGraph::MigrationError, 53 format(MISSING_CONSTRAINT_OR_INDEX, type: type, label: label, property: property) 54 end