Module: ActiveGraph::Migrations::Helpers
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/active_graph/migrations/helpers.rb,
lib/active_graph/migrations/helpers/schema.rb,
lib/active_graph/migrations/helpers/id_property.rb,
lib/active_graph/migrations/helpers/relationships.rb
Defined Under Namespace
Modules: ClassMethods, IdProperty, Relationships, Schema
Constant Summary
collapse
- PROPERTY_ALREADY_DEFINED =
'Property `%{new_property}` is already defined in `%{label}`. '\
'To overwrite, call `remove_property(:%{label}, :%{new_property})` before this method.'.freeze
Instance Method Summary
collapse
-
#add_label(label, new_label) ⇒ Object
-
#add_labels(label, new_labels) ⇒ Object
-
#drop_nodes(label) ⇒ Object
-
#execute(string, params = {}) ⇒ Object
-
#query(*args) ⇒ Object
-
#remove_label(label, label_to_remove) ⇒ Object
-
#remove_labels(label, labels_to_remove) ⇒ Object
-
#remove_property(label, property) ⇒ Object
-
#rename_label(old_label, new_label) ⇒ Object
-
#rename_property(label, old_property, new_property) ⇒ Object
-
#say(message, subitem = false) ⇒ Object
-
#say_with_time(message) ⇒ Object
Instance Method Details
#add_label(label, new_label) ⇒ Object
36
37
38
|
# File 'lib/active_graph/migrations/helpers.rb', line 36
def add_label(label, new_label)
add_labels(label, [new_label])
end
|
#add_labels(label, new_labels) ⇒ Object
32
33
34
|
# File 'lib/active_graph/migrations/helpers.rb', line 32
def add_labels(label, new_labels)
by_label(label).set(n: new_labels).exec
end
|
#drop_nodes(label) ⇒ Object
26
27
28
29
30
|
# File 'lib/active_graph/migrations/helpers.rb', line 26
def drop_nodes(label)
query.match(n: label)
.optional_match('(n)-[r]-()')
.delete(:r, :n).exec
end
|
#execute(string, params = {}) ⇒ Object
52
53
54
|
# File 'lib/active_graph/migrations/helpers.rb', line 52
def execute(string, params = {})
ActiveGraph::Base.query(string, params).to_a
end
|
#query(*args) ⇒ Object
69
70
71
|
# File 'lib/active_graph/migrations/helpers.rb', line 69
def query(*args)
ActiveGraph::Base.new_query(*args)
end
|
#remove_label(label, label_to_remove) ⇒ Object
44
45
46
|
# File 'lib/active_graph/migrations/helpers.rb', line 44
def remove_label(label, label_to_remove)
remove_labels(label, [label_to_remove])
end
|
#remove_labels(label, labels_to_remove) ⇒ Object
40
41
42
|
# File 'lib/active_graph/migrations/helpers.rb', line 40
def remove_labels(label, labels_to_remove)
by_label(label).remove(n: labels_to_remove).exec
end
|
#remove_property(label, property) ⇒ Object
16
17
18
|
# File 'lib/active_graph/migrations/helpers.rb', line 16
def remove_property(label, property)
by_label(label).remove("n.#{property}").exec
end
|
#rename_label(old_label, new_label) ⇒ Object
48
49
50
|
# File 'lib/active_graph/migrations/helpers.rb', line 48
def rename_label(old_label, new_label)
by_label(old_label).set(n: new_label).remove(n: old_label).exec
end
|
#rename_property(label, old_property, new_property) ⇒ Object
20
21
22
23
24
|
# File 'lib/active_graph/migrations/helpers.rb', line 20
def rename_property(label, old_property, new_property)
fail ActiveGraph::MigrationError, format(PROPERTY_ALREADY_DEFINED, new_property: new_property, label: label) if property_exists?(label, new_property)
by_label(label).set("n.#{new_property} = n.#{old_property}")
.remove("n.#{old_property}").exec
end
|
#say(message, subitem = false) ⇒ Object
65
66
67
|
# File 'lib/active_graph/migrations/helpers.rb', line 65
def say(message, subitem = false)
output "#{subitem ? ' ->' : '--'} #{message}"
end
|
#say_with_time(message) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/active_graph/migrations/helpers.rb', line 56
def say_with_time(message)
say(message)
result = nil
time = Benchmark.measure { result = yield }
say format('%.4fs', time.real), :subitem
say("#{result} rows", :subitem) if result.is_a?(Integer)
result
end
|