module ActiveGraph::Migrations::Schema
Public Class Methods
fetch_schema_data()
click to toggle source
# File lib/active_graph/migrations/schema.rb 5 def fetch_schema_data 6 {constraints: fetch_constraint_descriptions.sort, 7 indexes: fetch_index_descriptions.sort} 8 end
synchronize_schema_data(schema_data, remove_missing)
click to toggle source
# File lib/active_graph/migrations/schema.rb 10 def synchronize_schema_data(schema_data, remove_missing) 11 queries = [] 12 queries += drop_and_create_queries(fetch_constraint_descriptions, schema_data[:constraints], remove_missing) 13 queries += drop_and_create_queries(fetch_index_descriptions, schema_data[:indexes], remove_missing) 14 ActiveGraph::Base.queries do 15 queries.each { |query| append query } 16 end 17 end
Private Class Methods
description(row)
click to toggle source
# File lib/active_graph/migrations/schema.rb 48 def description(row) 49 "INDEX FOR (n:#{row[:labelsOrTypes].first}) ON (#{row[:properties].map { |prop| "n.#{prop}" }.join(', ')})" 50 end
drop_and_create_queries(existing, specified, remove_missing)
click to toggle source
# File lib/active_graph/migrations/schema.rb 52 def drop_and_create_queries(existing, specified, remove_missing) 53 [].tap do |queries| 54 if remove_missing 55 (existing - specified).each { |description| queries << "DROP #{description}" } 56 end 57 58 (specified - existing).each { |description| queries << "CREATE #{description}" } 59 end 60 end
fetch_constraint_descriptions()
click to toggle source
# File lib/active_graph/migrations/schema.rb 21 def fetch_constraint_descriptions 22 ActiveGraph::Base.query('CALL db.constraints() YIELD description').map(&:first) 23 end
fetch_index_descriptions()
click to toggle source
# File lib/active_graph/migrations/schema.rb 25 def fetch_index_descriptions 26 result = ActiveGraph::Base.query('CALL db.indexes()') 27 if result.keys.include?(:description) 28 v3_indexes(result) 29 else 30 v4_indexes(result) 31 end 32 end
v3_indexes(result)
click to toggle source
# File lib/active_graph/migrations/schema.rb 34 def v3_indexes(result) 35 result.reject do |row| 36 # These indexes are created automagically when the corresponding constraints are created 37 row[:type] == 'node_unique_property' 38 end.map { |row| row[:description] } 39 end
v4_indexes(result)
click to toggle source
# File lib/active_graph/migrations/schema.rb 41 def v4_indexes(result) 42 result.reject do |row| 43 # These indexes are created automagically when the corresponding constraints are created 44 row[:uniqueness] == 'UNIQUE' 45 end.map(&method(:description)) 46 end