Module: ActiveGraph::Migrations::Helpers::Relationships

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/active_graph/migrations/helpers/relationships.rb

Constant Summary collapse

DEFAULT_MAX_PER_BATCH =
1000

Instance Method Summary collapse

Instance Method Details

#change_relations_style(relationships, old_style, new_style, params = {}) ⇒ Object



9
10
11
12
13
# File 'lib/active_graph/migrations/helpers/relationships.rb', line 9

def change_relations_style(relationships, old_style, new_style, params = {})
  relationships.each do |rel|
    relabel_relation(relationship_style(rel, old_style), relationship_style(rel, new_style), params)
  end
end

#relabel_relation(old_name, new_name, params = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_graph/migrations/helpers/relationships.rb', line 15

def relabel_relation(old_name, new_name, params = {})
  relation_query = match_relation(old_name, params)

  max_per_batch = (ENV['MAX_PER_BATCH'] || DEFAULT_MAX_PER_BATCH).to_i

  count = count_relations(relation_query)
  output "Indexing #{count} #{old_name}s into #{new_name}..."
  while count > 0
    relation_query.create("(a)-[r2:`#{new_name}`]->(b)").set('r2 = r').with(:r).limit(max_per_batch).delete(:r).exec
    count = count_relations(relation_query)
    output "... #{count} #{old_name}'s left to go.." if count > 0
  end
end