require 'benchmark' module Neo4j class Migration def migrate fail 'not implemented' end def output(string = '') puts string unless !!ENV['silenced'] end def print_output(string) print string unless !!ENV['silenced'] end def default_path Rails.root if defined? Rails end def joined_path(path) File.join(path.to_s, 'db', 'neo4j-migrate') end class AddIdProperty < Neo4j::Migration attr_reader :models_filename def initialize(path = default_path) @models_filename = File.join(joined_path(path), 'add_id_property.yml') end def migrate models = ActiveSupport::HashWithIndifferentAccess.new(YAML.load_file(models_filename))[:models] output 'This task will add an ID Property every node in the given file.' output 'It may take a significant amount of time, please be patient.' models.each do |model| output output output "Adding IDs to #{model}" add_ids_to model.constantize end end def setup FileUtils.mkdir_p('db/neo4j-migrate') return if File.file?(models_filename) File.open(models_filename, 'w') do |file| message = <