Module: ActiveGraph::Migrations::Helpers
  
  
  
  
  
  
  
      - Extended by:
 
      - 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 
  
  
  
  
    
      
29
30
31 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 29
def add_label(label, new_label)
  add_labels(label, [new_label])
end 
     | 
  
 
    
      
  
  
    #add_labels(label, new_labels)  ⇒ Object 
  
  
  
  
    
      
25
26
27 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 25
def add_labels(label, new_labels)
  by_label(label).set(n: new_labels).exec
end 
     | 
  
 
    
      
  
  
    #drop_nodes(label)  ⇒ Object 
  
  
  
  
    
      
19
20
21
22
23 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 19
def drop_nodes(label)
  query.match(n: label)
       .optional_match('(n)-[r]-()')
       .delete(:r, :n).exec
end
     | 
  
 
    
      
  
  
    #execute(string, params = {})  ⇒ Object 
  
  
  
  
    
      
45
46
47 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 45
def execute(string, params = {})
  ActiveGraph::Base.query(string, params).to_a
end
     | 
  
 
    
      
  
  
    #query(*args)  ⇒ Object 
  
  
  
  
    
      
62
63
64 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 62
def query(*args)
  ActiveGraph::Base.new_query(*args)
end 
     | 
  
 
    
      
  
  
    #remove_label(label, label_to_remove)  ⇒ Object 
  
  
  
  
    
      
37
38
39 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 37
def remove_label(label, label_to_remove)
  remove_labels(label, [label_to_remove])
end 
     | 
  
 
    
      
  
  
    #remove_labels(label, labels_to_remove)  ⇒ Object 
  
  
  
  
    
      
33
34
35 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 33
def remove_labels(label, labels_to_remove)
  by_label(label).remove(n: labels_to_remove).exec
end 
     | 
  
 
    
      
  
  
    #remove_property(label, property)  ⇒ Object 
  
  
  
  
    
      
9
10
11 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 9
def remove_property(label, property)
  by_label(label).remove("n.#{property}").exec
end
     | 
  
 
    
      
  
  
    #rename_label(old_label, new_label)  ⇒ Object 
  
  
  
  
    
      
41
42
43 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 41
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 
  
  
  
  
    
      
13
14
15
16
17 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 13
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 
  
  
  
  
    
      
58
59
60 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 58
def say(message, subitem = false)
  output "#{subitem ? '   ->' : '--'} #{message}"
end
     | 
  
 
    
      
  
  
    #say_with_time(message)  ⇒ Object 
  
  
  
  
    
      
49
50
51
52
53
54
55
56 
     | 
    
      # File 'lib/active_graph/migrations/helpers.rb', line 49
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
     |