module Neo4j::Migrations::Helpers::Relationships
Constants
- DEFAULT_MAX_PER_BATCH
Public Instance Methods
change_relations_style(relationships, old_style, new_style, params = {})
click to toggle source
# File lib/neo4j/migrations/helpers/relationships.rb 9 def change_relations_style(relationships, old_style, new_style, params = {}) 10 relationships.each do |rel| 11 relabel_relation(relationship_style(rel, old_style), relationship_style(rel, new_style), params) 12 end 13 end
relabel_relation(old_name, new_name, params = {})
click to toggle source
# File lib/neo4j/migrations/helpers/relationships.rb 15 def relabel_relation(old_name, new_name, params = {}) 16 relation_query = match_relation(old_name, params) 17 18 max_per_batch = (ENV['MAX_PER_BATCH'] || DEFAULT_MAX_PER_BATCH).to_i 19 20 count = count_relations(relation_query) 21 output "Indexing #{count} #{old_name}s into #{new_name}..." 22 while count > 0 23 relation_query.create("(a)-[r2:`#{new_name}`]->(b)").set('r2 = r').with(:r).limit(max_per_batch).delete(:r).exec 24 count = count_relations(relation_query) 25 output "... #{count} #{old_name}'s left to go.." if count > 0 26 end 27 end
Private Instance Methods
arrow_cypher(label, direction)
click to toggle source
# File lib/neo4j/migrations/helpers/relationships.rb 39 def arrow_cypher(label, direction) 40 case direction 41 when :in 42 "<-[r:`#{label}`]-" 43 when :both 44 "<-[r:`#{label}`]->" 45 else 46 "-[r:`#{label}`]->" 47 end 48 end
count_relations(query)
click to toggle source
# File lib/neo4j/migrations/helpers/relationships.rb 50 def count_relations(query) 51 query.pluck('COUNT(r)').first 52 end
match_relation(label, params = {})
click to toggle source
# File lib/neo4j/migrations/helpers/relationships.rb 31 def match_relation(label, params = {}) 32 from = params[:from] ? "(a:`#{params[:from]}`)" : '(a)' 33 to = params[:to] ? "(b:`#{params[:to]}`)" : '(b)' 34 relation = arrow_cypher(label, params[:direction]) 35 36 query.match("#{from}#{relation}#{to}") 37 end
relationship_style(relationship, format)
click to toggle source
# File lib/neo4j/migrations/helpers/relationships.rb 54 def relationship_style(relationship, format) 55 case format.to_s 56 when 'lower_hashtag' then "##{relationship.downcase}" 57 when 'lower' then relationship.downcase 58 when 'upper' then relationship.upcase 59 else 60 fail("Invalid relationship type style `#{format}`.") 61 end 62 end