module ActiveGraph::Migrations::Helpers

Constants

PROPERTY_ALREADY_DEFINED

Public Instance Methods

add_label(label, new_label) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
36 def add_label(label, new_label)
37   add_labels(label, [new_label])
38 end
add_labels(label, new_labels) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
32 def add_labels(label, new_labels)
33   by_label(label).set(n: new_labels).exec
34 end
drop_nodes(label) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
26 def drop_nodes(label)
27   query.match(n: label)
28        .optional_match('(n)-[r]-()')
29        .delete(:r, :n).exec
30 end
execute(string, params = {}) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
52 def execute(string, params = {})
53   ActiveGraph::Base.query(string, params).to_a
54 end
query(*args) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
69 def query(*args)
70   ActiveGraph::Base.new_query(*args)
71 end
remove_label(label, label_to_remove) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
44 def remove_label(label, label_to_remove)
45   remove_labels(label, [label_to_remove])
46 end
remove_labels(label, labels_to_remove) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
40 def remove_labels(label, labels_to_remove)
41   by_label(label).remove(n: labels_to_remove).exec
42 end
remove_property(label, property) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
16 def remove_property(label, property)
17   by_label(label).remove("n.#{property}").exec
18 end
rename_label(old_label, new_label) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
48 def rename_label(old_label, new_label)
49   by_label(old_label).set(n: new_label).remove(n: old_label).exec
50 end
rename_property(label, old_property, new_property) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
20 def rename_property(label, old_property, new_property)
21   fail ActiveGraph::MigrationError, format(PROPERTY_ALREADY_DEFINED, new_property: new_property, label: label) if property_exists?(label, new_property)
22   by_label(label).set("n.#{new_property} = n.#{old_property}")
23                  .remove("n.#{old_property}").exec
24 end
say(message, subitem = false) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
65 def say(message, subitem = false)
66   output "#{subitem ? '   ->' : '--'} #{message}"
67 end
say_with_time(message) { || ... } click to toggle source
   # File lib/active_graph/migrations/helpers.rb
56 def say_with_time(message)
57   say(message)
58   result = nil
59   time = Benchmark.measure { result = yield }
60   say format('%.4fs', time.real), :subitem
61   say("#{result} rows", :subitem) if result.is_a?(Integer)
62   result
63 end

Protected Instance Methods

output(*string_format) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
75 def output(*string_format)
76   puts format(*string_format) unless @silenced
77 end
transactions?() click to toggle source
   # File lib/active_graph/migrations/helpers.rb
79 def transactions?
80   self.class.transaction?
81 end

Private Instance Methods

by_label(label, options = {}) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
89 def by_label(label, options = {})
90   symbol = options[:symbol] || :n
91   query.match(symbol => label)
92 end
property_exists?(label, property) click to toggle source
   # File lib/active_graph/migrations/helpers.rb
85 def property_exists?(label, property)
86   by_label(label).where("EXISTS(n.#{property})").return(:n).any?
87 end