Class: Neo4j::Migration::AddIdProperty

Inherits:
Neo4j::Migration show all
Defined in:
lib/neo4j/migration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Neo4j::Migration

#default_path, #joined_path, #output, #print_output

Constructor Details

#initialize(path = default_path) ⇒ AddIdProperty

Returns a new instance of AddIdProperty.



28
29
30
# File 'lib/neo4j/migration.rb', line 28

def initialize(path = default_path)
  @models_filename = File.join(joined_path(path), 'add_id_property.yml')
end

Instance Attribute Details

#models_filenameObject (readonly)

Returns the value of attribute models_filename.



26
27
28
# File 'lib/neo4j/migration.rb', line 26

def models_filename
  @models_filename
end

Instance Method Details

#migrateObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/neo4j/migration.rb', line 32

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

#setupObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/neo4j/migration.rb', line 44

def setup
  FileUtils.mkdir_p('db/neo4j-migrate')

  return if File.file?(models_filename)

  File.open(models_filename, 'w') do |file|
    message = <<MESSAGE
# Provide models to which IDs should be added.
# # It will only modify nodes that do not have IDs. There is no danger of overwriting data.
# # models: [Student,Lesson,Teacher,Exam]\nmodels: []
MESSAGE
    file.write(message)
  end
end