Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed upgrade_v2 rake script

  • Loading branch information...
commit 69e5488892e0cbb5702da34a126de1d1cd196e01 1 parent 799cdf9
Andreas Ronge andreasronge authored
4 bin/neo4j-upgrade
View
@@ -7,7 +7,7 @@ if ARGV.length == 0
puts <<TEXT
A tool for upgrading the neo4j database to #{Neo4j::VERSION}.
Make sure you shutdown the database cleanly before running this script.
-More info: http://neo4j.rubyforge.org/guides/configuration.html#upgrade-to-a-new-neo4j-version
+More info: https://github.com/andreasronge/neo4j/wiki
Usage : neo4j-upgrade <location of database>
Example : neo4j-upgrade db/neo4j-development
@@ -69,4 +69,4 @@ else
puts("No lucene index for relationship found at location #{nodes_path}")
end
-puts "Upgraded database done at '#{root}'"
+puts "Upgraded database done at '#{root}'"
2  lib/neo4j/tasks/neo4j.rb
View
@@ -0,0 +1,2 @@
+Dir["#{File.dirname(__FILE__)}/*/*.rake"].each { |f| load f }
+#require File.join(File.dirname(__FILE__), "upgrade_v2", "upgrade_v2")
62 lib/tasks/upgrade_v2/lib/upgrade_v2.rb → lib/neo4j/tasks/upgrade_v2/lib/upgrade_v2.rb
View
@@ -1,43 +1,35 @@
-# A script for renaming relationship
-# In Ne4j.rb version 2.0.0 the relationship declared with has_n(something).to(otherclass)
-# has changed. In order to change the relationship of an already existing database you can run this script.
-# Use the migrate_all! to automatically update all Neo4j::Rails::Model classes
-# For Neo4j::NodeMixin nodes you need to migrate each node using the migrate method (since there are no automatic way of finding all instances of an Neo4j::NodeMixin)
-
-$NEO4J_CLASSES = []
-$DOMAIN_CLASSES = []
-
-module Neo4j
- module Rails
- class Model
- class << self
- alias_method :_old_inherited, :inherited
-
- def inherited(c)
- _old_inherited(c)
- unless c == Neo4j::Rails::Model
- $NEO4J_CLASSES << c
- $DOMAIN_CLASSES << c if c.respond_to?(:ref_node_for_class)
- end
- end
- end
- end
- end
-end
-
module Neo4j
- module UpgradeV2 #:nodoc:
+ # A script for renaming relationship
+ # In Neo4j.rb version 2.0.0 the relationship declared with has_n(something).to(otherclass)
+ # has changed. In order to change the relationship of an already existing database you can run this script.
+ # Uses the @NEO4J_CLASSES@ and @NEO4J_MULTI_TENANCY_CLASSES@ environment variables.
+ # Usage see the github wiki pages upgrade
+ module UpgradeV2
class << self
# The domain classes declared as global ref_nodes
def default_domains_nodes
domain_nodes = [Neo4j.default_ref_node]
- $DOMAIN_CLASSES.each{|clazz| domain_nodes += clazz._all.to_a}
+ multi_tenancy_classes.each{|clazz| domain_nodes += clazz._all.to_a}
domain_nodes
end
+ def neo4j_classes
+ abort("Please set the environment variable 'NEO4J_CLASSES' or ruby constant ($NEO4J_CLASSES) before running this task") unless ENV['NEO4J_CLASSES']
+ ENV['NEO4J_CLASSES'].split(',').map(&:strip).map{|c| Neo4j::Wrapper.to_class(c)}
+ end
+
+ def multi_tenancy_classes
+ (ENV['NEO4J_MULTI_TENANCY_CLASSES'] && ENV['NEO4J_MULTI_TENANCY_CLASSES'].split(',').map(&:strip).map{|c| Neo4j::Wrapper.to_class(c)}) || []
+ end
+
def migrate_all!(domains = default_domains_nodes)
+ $NEO4J_CLASSES ||= neo4j_classes
+
+ puts "Upgrading #{$NEO4J_CLASSES.join(', ')}"
+ puts "Number of domains (multitenancy) #{domains.size}"
+
domains.each do |domain|
puts "domain #{domain.props.inspect} (multitenancy) " if domain != Neo4j.default_ref_node
::Neo4j.threadlocal_ref_node = domain
@@ -46,9 +38,19 @@ def migrate_all!(domains = default_domains_nodes)
end
def migrate(clazz, nodes = clazz._all)
- puts "migrate #{clazz} ..."
+ puts "migrate 2.0 #{clazz} ..."
source_class = clazz
+ rule_node = Neo4j::Wrapper::Rule::Rule.rule_node_for(clazz).rule_node
+
+ if rule_node.property?(:_count__all__classname)
+ puts "Rename size property on #{clazz}, #{rule_node[:_count__all__classname]}"
+ Neo4j::Transaction.run do
+ rule_node[:_size__all__classname] = rule_node[:_count__all__classname]
+ rule_node[:_count__all__classname] = nil
+ end
+ end
+
clazz._decl_rels.keys.each do |rel_accessor|
target_class = clazz._decl_rels[rel_accessor].target_class
next unless target_class
2  lib/tasks/upgrade_v2/upgrade_v2.rake → lib/neo4j/tasks/upgrade_v2/upgrade_v2.rake
View
@@ -1,3 +1,5 @@
+puts "LOADING UPGRADE SCRIPT Neo4j"
+
require File.join(File.dirname(__FILE__), "lib", "upgrade_v2")
namespace(:neo4j) do
Please sign in to comment.
Something went wrong with that request. Please try again.